@@ -50,7 +50,7 @@ impl HighlightAdapter {
50
50
) ) ;
51
51
}
52
52
53
- highlighter ( & mut lines, & html_escape :: encode_text ( line) ) ?;
53
+ highlighter ( & mut lines, line) ?;
54
54
55
55
if self . show_line_numbers {
56
56
lines. push_str ( "</span>" ) ;
@@ -112,8 +112,10 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
112
112
let theme = & self . theme_set . themes [ "InspiredGitHub" ] ;
113
113
let mut highlighter = syntect:: easy:: HighlightLines :: new ( syntax, theme) ;
114
114
115
+ let code = html_escape:: encode_text ( code) ;
116
+
115
117
match self . highlight_html (
116
- syntect:: util:: LinesWithEndings :: from ( code) ,
118
+ syntect:: util:: LinesWithEndings :: from ( & code) ,
117
119
|lines, line| {
118
120
let regions = highlighter. highlight_line ( line, & self . syntax_set ) ?;
119
121
syntect:: html:: append_highlighted_html_for_styled_line (
@@ -129,7 +131,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
129
131
Err ( _) => output. write_all ( code. as_bytes ( ) ) ?,
130
132
}
131
133
132
- self . write_button ( output, code)
134
+ self . write_button ( output, & code)
133
135
}
134
136
135
137
#[ cfg( all( feature = "tree-sitter" , not( feature = "syntect" ) ) ) ]
@@ -141,6 +143,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
141
143
) -> std:: io:: Result < ( ) > {
142
144
let lang = lang. unwrap_or_default ( ) ;
143
145
let config = ( self . language_cb ) ( lang) ;
146
+ let code = html_escape:: encode_text ( code) ;
144
147
let source = code. as_bytes ( ) ;
145
148
if let Some ( config) = config {
146
149
let mut highlighter = tree_sitter_highlight:: Highlighter :: new ( ) ;
@@ -160,7 +163,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
160
163
. unwrap ( ) ;
161
164
162
165
output. write_all ( html. as_bytes ( ) ) ?;
163
- return self . write_button ( output, code) ;
166
+ return self . write_button ( output, & code) ;
164
167
}
165
168
Err ( err) => {
166
169
eprintln ! ( "Error rendering code: {}" , err) ;
@@ -173,7 +176,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
173
176
}
174
177
}
175
178
comrak:: html:: escape ( output, source) ?;
176
- self . write_button ( output, code)
179
+ self . write_button ( output, & code)
177
180
}
178
181
179
182
#[ cfg( all( not( feature = "syntect" ) , not( feature = "tree-sitter" ) ) ) ]
@@ -183,6 +186,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
183
186
_lang : Option < & str > ,
184
187
code : & str ,
185
188
) -> std:: io:: Result < ( ) > {
189
+ let code = html_escape:: encode_text ( code) ;
186
190
let html = self
187
191
. highlight_html ( code. lines ( ) , |lines, line| {
188
192
lines. push_str ( & format ! ( "{line}\n " ) ) ;
@@ -192,7 +196,7 @@ impl SyntaxHighlighterAdapter for HighlightAdapter {
192
196
. unwrap ( ) ;
193
197
194
198
output. write_all ( html. as_bytes ( ) ) ?;
195
- self . write_button ( output, code)
199
+ self . write_button ( output, & code)
196
200
}
197
201
198
202
fn write_pre_tag (
0 commit comments