@@ -13,16 +13,17 @@ import v.pref
13
13
import v.util { tabs }
14
14
15
15
const (
16
- css_js_assets = ['doc.css' , 'normalize.css' , 'doc.js' , 'dark-mode.js' ]
17
- default_theme = os.resource_abs_path ('theme' )
18
- 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>'
16
+ css_js_assets = ['doc.css' , 'normalize.css' , 'doc.js' , 'dark-mode.js' ]
17
+ default_theme = os.resource_abs_path ('theme' )
18
+ 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>'
19
19
20
- single_quote = "'"
21
- double_quote = '"'
22
- no_quotes_replacement = [single_quote, '' , double_quote, '' ]
20
+ single_quote = "'"
21
+ double_quote = '"'
22
+ no_quotes_replacement = [single_quote, '' , double_quote, '' ]
23
23
24
- html_tag_escape_replacement = ['<' , '<' , '>' , '>' ]
25
- html_tag_escape_re = regex.regex_opt (r '`.+[(<)(>)].+`' ) or { panic (err) }
24
+ html_tag_escape_re = regex.regex_opt (r '`.+[(<)(>)].+`' ) or { panic (err) }
25
+ html_tag_escape_seq = ['<' , '<' , '>' , '>' ]
26
+ md_script_escape_seq = ['<script>' , '`' , '</script>' , '`' ]
26
27
)
27
28
28
29
enum HighlightTokenTyp {
@@ -213,14 +214,13 @@ fn (vd VDoc) gen_html(d doc.Doc) string {
213
214
}
214
215
// write nav1
215
216
if cfg.is_multi || vd.docs.len > 1 {
216
- mut used_submod_prefix := []string {}
217
- for i, dc in vd.docs {
218
- names := dc.head.name.split ('.' )
219
- submod_prefix := if names.len > 1 { names[0 ] } else { dc.head.name }
220
- if i - 1 > = 0 && submod_prefix in used_submod_prefix {
217
+ mut used_submod_prefixes := map [string ]bool {}
218
+ for dc in vd.docs {
219
+ submod_prefix := dc.head.name.all_before ('.' )
220
+ if used_submod_prefixes[submod_prefix] {
221
221
continue
222
222
}
223
- used_submod_prefix << submod_prefix
223
+ used_submod_prefixes[submod_prefix] = true
224
224
mut href_name := './${dc.head.name} .html'
225
225
if (cfg.is_vlib && dc.head.name == 'builtin' && ! cfg.include_readme)
226
226
|| dc.head.name == 'README' {
@@ -424,8 +424,7 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
424
424
// Allow README.md to go through unescaped except for script tags
425
425
escaped_html := if head && is_module_readme (dn) {
426
426
// Strip markdown [TOC] directives, since we generate our own.
427
- stripped := comments.replace ('[TOC]' , '' )
428
- markdown_escape_script_tags (stripped)
427
+ comments.replace ('[TOC]' , '' ).replace_each (md_script_escape_seq)
429
428
} else {
430
429
html_tag_escape (comments)
431
430
}
@@ -494,7 +493,7 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
494
493
}
495
494
496
495
fn html_tag_escape (str string ) string {
497
- escaped_string := str.replace_each (html_tag_escape_replacement )
496
+ escaped_string := str.replace_each (html_tag_escape_seq )
498
497
mut re := html_tag_escape_re
499
498
if re.find_all_str (escaped_string).len > 0 {
500
499
return str
0 commit comments