diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index c27027084c..59dbd14a02 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -516,7 +516,8 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool, table: tb } } - md_content := markdown.render(dn.merge_comments_without_examples(), mut renderer) or { '' } + only_comments_text := dn.merge_comments_without_examples() + md_content := markdown.render(only_comments_text, mut renderer) or { '' } highlighted_code := html_highlight(dn.content, tb) node_class := if dn.kind == .const_group { ' const' } else { '' } sym_name := get_sym_name(dn) @@ -615,7 +616,16 @@ fn (f &MdHtmlCodeHighlighter) transform_attribute(p markdown.ParentType, name st fn (f &MdHtmlCodeHighlighter) transform_content(parent markdown.ParentType, text string) string { if parent is markdown.MD_BLOCKTYPE && parent == .md_block_code { - return html_highlight(text, f.table) + if f.language == '' { + return text + } + output := html_highlight(text, f.table) + // Reset the language, so that it will not persist between blocks, + // and will not be accidentally re-used for the next block, that may be lacking ```language : + unsafe { + f.language = '' + } + return output } return text } diff --git a/cmd/tools/vdoc/testdata/output_formats/README.md b/cmd/tools/vdoc/testdata/output_formats/README.md index b709d705e3..87514fdd6e 100644 --- a/cmd/tools/vdoc/testdata/output_formats/README.md +++ b/cmd/tools/vdoc/testdata/output_formats/README.md @@ -138,3 +138,16 @@ const html = ' 1. Numbered markdown list point 1 2. List point 2 3. List point 3 + +A code block without a specific language should be rendered verbatim: +``` +. +├── static/ +│ ├── css/ +│ │ └── main.css +│ └── js/ +│ └── main.js +└── main.v +``` + +The End. diff --git a/cmd/tools/vdoc/testdata/output_formats/main.ansi b/cmd/tools/vdoc/testdata/output_formats/main.ansi index 8fce2eb5ef..73895c9014 100644 --- a/cmd/tools/vdoc/testdata/output_formats/main.ansi +++ b/cmd/tools/vdoc/testdata/output_formats/main.ansi @@ -118,6 +118,17 @@ List point 3 Numbered markdown list point 1 List point 2 List point 3 + +A code block without a specific language should be rendered verbatim: +. +├── static/ +│ ├── css/ +│ │ └── main.css +│ └── js/ +│ └── main.js +└── main.v + +The End. [94mmodule[39m [32mmain[39m ## Description @@ -259,6 +270,18 @@ List point 3 2. List point 2 3. List point 3 + A code block without a specific language should be rendered verbatim: + ``` + . + ├── static/ + │ ├── css/ + │ │ └── main.css + │ └── js/ + │ └── main.js + └── main.v + ``` + + The End. [94mconst[39m omega = [94m3[39m [90m// should be first[39m [94mconst[39m alpha = [94m5[39m [90m// should be in the middle[39m diff --git a/cmd/tools/vdoc/testdata/output_formats/main.html b/cmd/tools/vdoc/testdata/output_formats/main.html index 8074ee3e92..fb3cc00d51 100644 --- a/cmd/tools/vdoc/testdata/output_formats/main.html +++ b/cmd/tools/vdoc/testdata/output_formats/main.html @@ -90,7 +90,14 @@ doc2 := toml console.log(res); } </script> -</html>'
A code block without a specific language should be rendered verbatim:
.
+├── static/
+│ ├── css/
+│ │ └── main.css
+│ └── js/
+│ └── main.js
+└── main.v
+
The End.
diff --git a/cmd/tools/vdoc/testdata/output_formats/main.text b/cmd/tools/vdoc/testdata/output_formats/main.text index 7a3927c365..28741ac532 100644 --- a/cmd/tools/vdoc/testdata/output_formats/main.text +++ b/cmd/tools/vdoc/testdata/output_formats/main.text @@ -139,6 +139,18 @@ module main 2. List point 2 3. List point 3 + A code block without a specific language should be rendered verbatim: + ``` + . + ├── static/ + │ ├── css/ + │ │ └── main.css + │ └── js/ + │ └── main.js + └── main.v + ``` + + The End. const omega = 3 // should be first const alpha = 5 // should be in the middle