Skip to content

Commit 3f269ca

Browse files
committed
fix
1 parent 5e8af91 commit 3f269ca

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/html/comrak_adapters.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl HighlightAdapter {
5050
));
5151
}
5252

53-
highlighter(&mut lines, &html_escape::encode_text(line))?;
53+
highlighter(&mut lines, line)?;
5454

5555
if self.show_line_numbers {
5656
lines.push_str("</span>");
@@ -112,8 +112,10 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
112112
let theme = &self.theme_set.themes["InspiredGitHub"];
113113
let mut highlighter = syntect::easy::HighlightLines::new(syntax, theme);
114114

115+
let code = html_escape::encode_text(code);
116+
115117
match self.highlight_html(
116-
syntect::util::LinesWithEndings::from(code),
118+
syntect::util::LinesWithEndings::from(&code),
117119
|lines, line| {
118120
let regions = highlighter.highlight_line(line, &self.syntax_set)?;
119121
syntect::html::append_highlighted_html_for_styled_line(
@@ -129,7 +131,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
129131
Err(_) => output.write_all(code.as_bytes())?,
130132
}
131133

132-
self.write_button(output, code)
134+
self.write_button(output, &code)
133135
}
134136

135137
#[cfg(all(feature = "tree-sitter", not(feature = "syntect")))]
@@ -141,6 +143,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
141143
) -> std::io::Result<()> {
142144
let lang = lang.unwrap_or_default();
143145
let config = (self.language_cb)(lang);
146+
let code = html_escape::encode_text(code);
144147
let source = code.as_bytes();
145148
if let Some(config) = config {
146149
let mut highlighter = tree_sitter_highlight::Highlighter::new();
@@ -160,7 +163,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
160163
.unwrap();
161164

162165
output.write_all(html.as_bytes())?;
163-
return self.write_button(output, code);
166+
return self.write_button(output, &code);
164167
}
165168
Err(err) => {
166169
eprintln!("Error rendering code: {}", err);
@@ -173,7 +176,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
173176
}
174177
}
175178
comrak::html::escape(output, source)?;
176-
self.write_button(output, code)
179+
self.write_button(output, &code)
177180
}
178181

179182
#[cfg(all(not(feature = "syntect"), not(feature = "tree-sitter")))]
@@ -183,6 +186,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
183186
_lang: Option<&str>,
184187
code: &str,
185188
) -> std::io::Result<()> {
189+
let code = html_escape::encode_text(code);
186190
let html = self
187191
.highlight_html(code.lines(), |lines, line| {
188192
lines.push_str(&format!("{line}\n"));
@@ -192,7 +196,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
192196
.unwrap();
193197

194198
output.write_all(html.as_bytes())?;
195-
self.write_button(output, code)
199+
self.write_button(output, &code)
196200
}
197201

198202
fn write_pre_tag(

src/html/jsdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn markdown_to_html(
295295

296296
let mut html = {
297297
let arena = Arena::new();
298-
let root = comrak::parse_document(&arena, &md, &options);
298+
let root = comrak::parse_document(&arena, md, &options);
299299

300300
walk_node(&arena, root, &options, &plugins);
301301

0 commit comments

Comments
 (0)