Skip to content

Commit 2cb50de

Browse files
db48xrdmsr
authored andcommittedNov 29, 2024·
only report a failure from pygmentize as a warning, not an error
It shouldn’t fail to generate the documentation just because pygmentize doesn’t recognize the language used in the code block. Instead it should just output an unhilighted code block containing the text.
1 parent 69d8676 commit 2cb50de

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed
 

‎src/render.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::config::Config;
22
use crate::doctest;
33
use crate::parser;
4+
use crate::report::report_warning;
45

56
use serde::Serialize;
67
use std::collections::HashMap;
@@ -95,12 +96,15 @@ pub fn process_markdown(
9596
}
9697

9798
// Pygmentize was chosen over syntect because it has way more themes and is customizable through a CSS stylesheet
98-
let html =
99-
pygmentize::highlight(&code, Some(&code_lang), &HtmlFormatter::new()).unwrap();
100-
99+
let ret = match pygmentize::highlight(&code, Some(&code_lang), &HtmlFormatter::new()) {
100+
Ok(html) => Some(Event::Html(html.into())),
101+
Err(_) => {
102+
report_warning(&format!("Unable to create syntax highlighting for “{code_lang}” code block"));
103+
Some(Event::Code(code.clone().into()))
104+
},
105+
};
101106
code.clear();
102-
103-
Some(Event::Html(html.into()))
107+
ret
104108
}
105109
}
106110

0 commit comments

Comments
 (0)
Please sign in to comment.