vdoc: improve html tag escape (#19266)

This commit is contained in:
Turiiya 2023-09-06 08:42:18 +02:00 committed by GitHub
parent 0e154bbbfd
commit dac6f0b0c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,9 @@ const (
single_quote = "'" single_quote = "'"
double_quote = '"' double_quote = '"'
no_quotes_replacement = [single_quote, '', double_quote, ''] no_quotes_replacement = [single_quote, '', double_quote, '']
html_tag_escape_replacement = ['<', '&lt;', '>', '&gt;']
html_tag_escape_re = regex.regex_opt(r'`.+[(&lt;)(&gt;)].+`') or { panic(err) }
) )
enum HighlightTokenTyp { enum HighlightTokenTyp {
@ -450,8 +453,8 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
} }
fn html_tag_escape(str string) string { fn html_tag_escape(str string) string {
escaped_string := str.replace_each(['<', '&lt;', '>', '&gt;']) escaped_string := str.replace_each(html_tag_escape_replacement)
mut re := regex.regex_opt(r'`.+[(&lt;)(&gt;)].+`') or { regex.RE{} } mut re := html_tag_escape_re
if re.find_all_str(escaped_string).len > 0 { if re.find_all_str(escaped_string).len > 0 {
return str return str
} }