Skip to content

Commit 9f87a17

Browse files
committed
fix build
1 parent 273796f commit 9f87a17

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/plugins/extra/syntect.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Syntax highlighting for code blocks
22
use syntect::highlighting::ThemeSet;
3-
use syntect::html::{highlighted_html_for_string, ClassedHtmlGenerator};
43
pub use syntect::html::ClassStyle;
4+
use syntect::html::{highlighted_html_for_string, ClassedHTMLGenerator};
55
use syntect::parsing::SyntaxSet;
66
use syntect::util::LinesWithEndings;
77

@@ -25,7 +25,7 @@ impl NodeValue for SyntectSnippet {
2525
#[derive(Debug, Clone, Copy)]
2626
enum SyntectMode {
2727
InlineStyles { theme: &'static str },
28-
CssClasses { class_style: ClassStyle }
28+
CssClasses { class_style: ClassStyle },
2929
}
3030

3131
#[derive(Debug, Clone, Copy)]
@@ -34,7 +34,9 @@ impl MarkdownItExt for SyntectSettings {}
3434

3535
impl Default for SyntectSettings {
3636
fn default() -> Self {
37-
Self(SyntectMode::InlineStyles { theme: "InspiredGitHub" })
37+
Self(SyntectMode::InlineStyles {
38+
theme: "InspiredGitHub",
39+
})
3840
}
3941
}
4042

@@ -44,26 +46,29 @@ pub fn add(md: &mut MarkdownIt) {
4446

4547
/// Use inline styles with the given theme
4648
pub fn set_theme(md: &mut MarkdownIt, theme: &'static str) {
47-
md.ext.insert(SyntectSettings(
48-
SyntectMode::InlineStyles { theme }
49-
));
49+
md.ext
50+
.insert(SyntectSettings(SyntectMode::InlineStyles { theme }));
5051
}
5152

5253
/// Generate spans with css classes applied
53-
///
54+
///
5455
/// This is an alternative to using a theme. You are responsible for including a style sheet.
5556
pub fn use_css_classes(md: &mut MarkdownIt, class_style: ClassStyle) {
56-
md.ext_insert(SyntectSettings(
57-
SyntectMode::CssClasses { class_style }
58-
));
57+
md.ext
58+
.insert(SyntectSettings(SyntectMode::CssClasses { class_style }));
5959
}
6060

6161
pub struct SyntectRule;
6262
impl CoreRule for SyntectRule {
6363
fn run(root: &mut Node, md: &MarkdownIt) {
6464
let ss = SyntaxSet::load_defaults_newlines();
6565
let ts = ThemeSet::load_defaults();
66-
let mode = match md.ext.get::<SyntectSettings>().copied().unwrap_or_default().0;
66+
let mode = md
67+
.ext
68+
.get::<SyntectSettings>()
69+
.copied()
70+
.unwrap_or_default()
71+
.0;
6772

6873
root.walk_mut(|node, _| {
6974
let mut content = None;
@@ -84,11 +89,18 @@ impl CoreRule for SyntectRule {
8489
let syntax = syntax.unwrap_or_else(|| ss.find_syntax_plain_text());
8590

8691
let html = match mode {
87-
SyntectMode::InlineStyles { theme } => highlighted_html_for_string(content, &ss, syntax, &ts.themes[theme]),
92+
SyntectMode::InlineStyles { theme } => {
93+
highlighted_html_for_string(content, &ss, syntax, &ts.themes[theme])
94+
}
8895
SyntectMode::CssClasses { class_style } => {
89-
let mut html_generator = ClassedHTMLGenerator::new_with_class_style(syntax, &ss, class_style);
96+
let mut html_generator =
97+
ClassedHTMLGenerator::new_with_class_style(syntax, &ss, class_style);
9098
for line in LinesWithEndings::from(content) {
91-
html_generator.parse_html_for_line_which_includes_newline(line);
99+
if let Err(_) =
100+
html_generator.parse_html_for_line_which_includes_newline(line)
101+
{
102+
return;
103+
};
92104
}
93105
Ok(html_generator.finalize())
94106
}

0 commit comments

Comments
 (0)