diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index 0c3f4798a6..5671916f81 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -14,6 +14,7 @@ const ( css_js_assets = ['doc.css', 'normalize.css', 'doc.js', 'dark-mode.js'] res_path = os.resource_abs_path('resources') favicons_path = os.join_path(res_path, 'favicons') + link_svg = '' html_content = ' @@ -421,10 +422,17 @@ fn html_highlight(code string, tb &table.Table) string { fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool, tb &table.Table) string { mut dnw := strings.new_builder(200) - link_svg := '' head_tag := if head { 'h1' } else { 'h2' } comments := dn.merge_comments_without_examples() - md_content := markdown.to_html(html_tag_escape(comments)) + // Allow README.md to go through unescaped except for script tags + escaped_html := if head && is_module_readme(dn) { + // Strip markdown [TOC] directives, since we generate our own. + stripped := comments.replace('[TOC]', '') + markdown_escape_script_tags(stripped) + } else { + html_tag_escape(comments) + } + md_content := markdown.to_html(escaped_html) hlighted_code := html_highlight(dn.content, tb) node_class := if dn.kind == .const_group { ' const' } else { '' } sym_name := get_sym_name(dn) diff --git a/cmd/tools/vdoc/markdown.v b/cmd/tools/vdoc/markdown.v index 01000a86e1..5aa5ec46a9 100644 --- a/cmd/tools/vdoc/markdown.v +++ b/cmd/tools/vdoc/markdown.v @@ -3,6 +3,10 @@ module main import strings import v.doc +fn markdown_escape_script_tags(str string) string { + return str.replace_each(['', '`']) +} + fn (vd VDoc) gen_markdown(d doc.Doc, with_toc bool) string { mut hw := strings.new_builder(200) mut cw := strings.new_builder(200)