File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
src/renderer/html_handlebars/helpers Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
1
use std:: collections:: BTreeMap ;
2
+ use std:: io;
2
3
use std:: path:: Path ;
3
4
4
5
use crate :: utils;
@@ -102,7 +103,7 @@ impl HelperDef for RenderToc {
102
103
// Part title
103
104
if let Some ( title) = item. get ( "part" ) {
104
105
out. write ( "<li class=\" part-title\" >" ) ?;
105
- out . write ( title) ?;
106
+ write_escaped ( out , title) ?;
106
107
out. write ( "</li>" ) ?;
107
108
continue ;
108
109
}
@@ -160,7 +161,7 @@ impl HelperDef for RenderToc {
160
161
html:: push_html ( & mut markdown_parsed_name, parser) ;
161
162
162
163
// write to the handlebars template
163
- out . write ( & markdown_parsed_name) ?;
164
+ write_escaped ( out , & markdown_parsed_name) ?;
164
165
}
165
166
166
167
if path_exists {
@@ -204,3 +205,18 @@ fn write_li_open_tag(
204
205
li. push_str ( "\" >" ) ;
205
206
out. write ( & li)
206
207
}
208
+
209
+ fn write_escaped ( out : & mut dyn Output , mut title : & str ) -> io:: Result < ( ) > {
210
+ let needs_escape: & [ char ] = & [ '<' , '>' ] ;
211
+ while let Some ( next) = title. find ( needs_escape) {
212
+ out. write ( & title[ ..next] ) ?;
213
+ match title. as_bytes ( ) [ next] {
214
+ b'<' => out. write ( "<" ) ?,
215
+ b'>' => out. write ( ">" ) ?,
216
+ _ => unreachable ! ( ) ,
217
+ }
218
+ title = & title[ next + 1 ..] ;
219
+ }
220
+ out. write ( title) ?;
221
+ Ok ( ( ) )
222
+ }
You can’t perform that action at this time.
0 commit comments