Skip to content

Commit b445c5b

Browse files
committed
fix whitespace around embeds
1 parent a8ab8a8 commit b445c5b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tools/od_ref_bot/src/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,24 @@ fn format_body(body: &str, data: &Data) -> String {
310310

311311
new_body = tag_cleaner_regex.replace_all(&new_body, "").to_string();
312312
new_body = new_body.replace("```dm", "```js");
313-
new_body.replace("\n\n\n", "\n")
313+
314+
let mut whitespaced_body = new_body.clone();
315+
316+
let whitespace_cleaner = Regex::new(r"(\n{3,}```)|(```\n{2,})").unwrap();
317+
for capture in whitespace_cleaner.captures_iter(&new_body) {
318+
let original = capture.get(0).unwrap().as_str();
319+
320+
if let Some(_) = capture.get(1) {
321+
whitespaced_body = whitespaced_body.replace(original, "\n\n```");
322+
break;
323+
}
324+
325+
if let Some(_) = capture.get(2) {
326+
whitespaced_body = whitespaced_body.replace(original, "```\n")
327+
}
328+
}
329+
330+
whitespaced_body
314331
}
315332

316333
/// Converts the internal Zola page structure into something we can link to.

0 commit comments

Comments
 (0)