vdoc: fix wrong escaping in HTML docs (#10638)

pull/11002/head
Hunam 2021-07-30 11:00:03 +02:00 committed by GitHub
parent 6674d65397
commit 0f09228adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import os
import net.urllib
import strings
import markdown
import regex
import v.scanner
import v.ast
import v.token
@ -493,7 +494,12 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
}
fn html_tag_escape(str string) string {
return str.replace_each(['<', '&lt;', '>', '&gt;'])
excaped_string := str.replace_each(['<', '&lt;', '>', '&gt;'])
mut re := regex.regex_opt(r'`.+[(&lt;)(&gt;)].+`') or { regex.RE{} }
if re.find_all_str(excaped_string).len > 0 {
return str
}
return excaped_string
}
/*

View File

@ -0,0 +1,6 @@
module main
fn test_html_tag_escape() {
assert html_tag_escape('<abc>') == '&lt;abc&gt;'
assert html_tag_escape('`<abc>`') == '`<abc>`'
}