mirror of
https://github.com/vlang/v.git
synced 2025-09-10 07:47:20 -04:00
vdoc: improve html tag escape (#19266)
This commit is contained in:
parent
0e154bbbfd
commit
dac6f0b0c9
@ -13,13 +13,16 @@ import v.pref
|
||||
import v.util { tabs }
|
||||
|
||||
const (
|
||||
css_js_assets = ['doc.css', 'normalize.css', 'doc.js', 'dark-mode.js']
|
||||
default_theme = os.resource_abs_path('theme')
|
||||
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>'
|
||||
css_js_assets = ['doc.css', 'normalize.css', 'doc.js', 'dark-mode.js']
|
||||
default_theme = os.resource_abs_path('theme')
|
||||
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>'
|
||||
|
||||
single_quote = "'"
|
||||
double_quote = '"'
|
||||
no_quotes_replacement = [single_quote, '', double_quote, '']
|
||||
single_quote = "'"
|
||||
double_quote = '"'
|
||||
no_quotes_replacement = [single_quote, '', double_quote, '']
|
||||
|
||||
html_tag_escape_replacement = ['<', '<', '>', '>']
|
||||
html_tag_escape_re = regex.regex_opt(r'`.+[(<)(>)].+`') or { panic(err) }
|
||||
)
|
||||
|
||||
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 {
|
||||
escaped_string := str.replace_each(['<', '<', '>', '>'])
|
||||
mut re := regex.regex_opt(r'`.+[(<)(>)].+`') or { regex.RE{} }
|
||||
escaped_string := str.replace_each(html_tag_escape_replacement)
|
||||
mut re := html_tag_escape_re
|
||||
if re.find_all_str(escaped_string).len > 0 {
|
||||
return str
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user