Skip to content

Commit

Permalink
Fix code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Dec 23, 2024
1 parent 2a82308 commit 833405e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions crates/header-translator/src/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ impl Documentation {
write!(&mut s, "{}", format_child(child))?;
}

let s = s
let s = fix_code_blocks(&s)
.trim()
.replace("\n", "\n/// ")
.replace("/// \n", "///\n")
.replace("\n\n```\n", "\n\n```objc\n")
.replace("\t", " ");

if !s.is_empty() {
Expand Down Expand Up @@ -103,6 +102,24 @@ impl Documentation {
}
}

fn fix_code_blocks(s: &str) -> String {
let mut ret = String::with_capacity(s.len());
let mut last_end = 0;
for (i, (start, part)) in s.match_indices("```").enumerate() {
if i % 2 == 1 {
continue;
}
if &s[start..start + 4] != "```\n" {
continue;
}
ret.push_str(&s[last_end..start]);
ret.push_str("```text");
last_end = start + part.len();
}
ret.push_str(&s[last_end..s.len()]);
ret
}

fn format_child(child: &CommentChild) -> impl fmt::Display + '_ {
FormatterFn(move |f| {
match child {
Expand Down

0 comments on commit 833405e

Please sign in to comment.