tools: fix v doc truncating code blocks, that lack a specific language (fix #22017)

This commit is contained in:
Delyan Angelov 2024-09-05 16:41:13 +03:00
parent 633d5f27be
commit 9238dd6b31
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
5 changed files with 68 additions and 3 deletions

View File

@ -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
}

View File

@ -138,3 +138,16 @@ const html = '<!DOCTYPE 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.

View File

@ -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.
module main
## 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.
const omega = 3 // should be first
const alpha = 5 // should be in the middle

View File

@ -90,7 +90,14 @@ doc2 <span class="token operator">:=</span> toml<span class="token punctuation">
console.log(res);
}
&lt;/script&gt;
&lt;/html&gt;'</span></code></pre><ul><li>Regular markdown list point 1</li><li>List point 2</li><li>List point 3</li></ul><ol><li>Numbered markdown list point 1</li><li>List point 2</li><li>List point 3</li></ol>
&lt;/html&gt;'</span></code></pre><ul><li>Regular markdown list point 1</li><li>List point 2</li><li>List point 3</li></ul><ol><li>Numbered markdown list point 1</li><li>List point 2</li><li>List point 3</li></ol><p>A code block without a specific language should be rendered verbatim:</p><pre><code>.
├── static/
│ ├── css/
│ │ └── main.css
│ └── js/
│ └── main.js
└── main.v
</code></pre><p>The End.</p>
</section>

View File

@ -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