Skip to content

Commit

Permalink
vdoc: improve html tag escape (#19266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Sep 6, 2023
1 parent 0e154bb commit dac6f0b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cmd/tools/vdoc/html.v
Expand Up @@ -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 = ['<', '&lt;', '>', '&gt;']
html_tag_escape_re = regex.regex_opt(r'`.+[(&lt;)(&gt;)].+`') or { panic(err) }
)

enum HighlightTokenTyp {
Expand Down Expand Up @@ -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(['<', '&lt;', '>', '&gt;'])
mut re := regex.regex_opt(r'`.+[(&lt;)(&gt;)].+`') 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
}
Expand Down

0 comments on commit dac6f0b

Please sign in to comment.