vdoc: escape `<` and `>` before creating md (#7895)

pull/7902/head
hazohelet 2021-01-06 03:16:56 +09:00 committed by GitHub
parent 5a70eba8e1
commit a02de42450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -399,7 +399,7 @@ fn doc_node_html(dd doc.DocNode, link string, head bool, tb &table.Table) string
mut dnw := strings.new_builder(200) mut dnw := strings.new_builder(200)
link_svg := '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>' link_svg := '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>'
head_tag := if head { 'h1' } else { 'h2' } head_tag := if head { 'h1' } else { 'h2' }
md_content := markdown.to_html(dd.comment) md_content := markdown.to_html(html_tag_escape(dd.comment))
hlighted_code := html_highlight(dd.content, tb) hlighted_code := html_highlight(dd.content, tb)
node_class := if dd.kind == .const_group { ' const' } else { '' } node_class := if dd.kind == .const_group { ' const' } else { '' }
sym_name := get_sym_name(dd) sym_name := get_sym_name(dd)
@ -433,6 +433,10 @@ fn doc_node_html(dd doc.DocNode, link string, head bool, tb &table.Table) string
return dnw_str return dnw_str
} }
fn html_tag_escape(str string) string {
return str.replace_each(['<', '&lt;', '>', '&gt;'])
}
fn get_sym_name(dn doc.DocNode) string { fn get_sym_name(dn doc.DocNode) string {
sym_name := if dn.parent_name.len > 0 && dn.parent_name != 'void' { sym_name := if dn.parent_name.len > 0 && dn.parent_name != 'void' {
'($dn.parent_name) $dn.name' '($dn.parent_name) $dn.name'