Skip to content

Commit 833405e

Browse files
committed
Fix code blocks
1 parent 2a82308 commit 833405e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

crates/header-translator/src/documentation.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ impl Documentation {
6666
write!(&mut s, "{}", format_child(child))?;
6767
}
6868

69-
let s = s
69+
let s = fix_code_blocks(&s)
7070
.trim()
7171
.replace("\n", "\n/// ")
7272
.replace("/// \n", "///\n")
73-
.replace("\n\n```\n", "\n\n```objc\n")
7473
.replace("\t", " ");
7574

7675
if !s.is_empty() {
@@ -103,6 +102,24 @@ impl Documentation {
103102
}
104103
}
105104

105+
fn fix_code_blocks(s: &str) -> String {
106+
let mut ret = String::with_capacity(s.len());
107+
let mut last_end = 0;
108+
for (i, (start, part)) in s.match_indices("```").enumerate() {
109+
if i % 2 == 1 {
110+
continue;
111+
}
112+
if &s[start..start + 4] != "```\n" {
113+
continue;
114+
}
115+
ret.push_str(&s[last_end..start]);
116+
ret.push_str("```text");
117+
last_end = start + part.len();
118+
}
119+
ret.push_str(&s[last_end..s.len()]);
120+
ret
121+
}
122+
106123
fn format_child(child: &CommentChild) -> impl fmt::Display + '_ {
107124
FormatterFn(move |f| {
108125
match child {

0 commit comments

Comments
 (0)