Skip to content

Commit 7cba38b

Browse files
committed
Address review comment
1 parent 26d9632 commit 7cba38b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/render.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ impl<'a> MarkdownRenderer<'a> {
8787
// Tweak annotations of code blocks.
8888
iter_nodes(root, &|node| {
8989
if let NodeValue::CodeBlock(ref mut ncb) = node.data.borrow_mut().value {
90-
let mut orig_annot = String::from_utf8(ncb.info.to_vec()).unwrap();
91-
92-
// Ignore characters after a comma for syntax highlighting to work correctly.
93-
if let Some(offset) = orig_annot.find(',') {
94-
let _ = orig_annot.drain(offset..orig_annot.len());
95-
ncb.info = orig_annot.as_bytes().to_vec();
90+
// If annot includes invalid UTF-8 char, do nothing.
91+
if let Ok(mut orig_annot) = String::from_utf8(ncb.info.to_vec()) {
92+
// Ignore characters after a comma for syntax highlighting to work correctly.
93+
if let Some(offset) = orig_annot.find(',') {
94+
let _ = orig_annot.drain(offset..orig_annot.len());
95+
ncb.info = orig_annot.as_bytes().to_vec();
96+
}
9697
}
9798
}
9899
});

0 commit comments

Comments
 (0)