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 11use std:: collections:: BTreeMap ;
2+ use std:: io;
23use std:: path:: Path ;
34
45use crate :: utils;
@@ -102,7 +103,7 @@ impl HelperDef for RenderToc {
102103 // Part title
103104 if let Some ( title) = item. get ( "part" ) {
104105 out. write ( "<li class=\" part-title\" >" ) ?;
105- out . write ( title) ?;
106+ write_escaped ( out , title) ?;
106107 out. write ( "</li>" ) ?;
107108 continue ;
108109 }
@@ -160,7 +161,7 @@ impl HelperDef for RenderToc {
160161 html:: push_html ( & mut markdown_parsed_name, parser) ;
161162
162163 // write to the handlebars template
163- out . write ( & markdown_parsed_name) ?;
164+ write_escaped ( out , & markdown_parsed_name) ?;
164165 }
165166
166167 if path_exists {
@@ -204,3 +205,18 @@ fn write_li_open_tag(
204205 li. push_str ( "\" >" ) ;
205206 out. write ( & li)
206207}
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