mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
vdoc: improve line merging for readme contents (#21224)
This commit is contained in:
parent
4e8d00d368
commit
427b6dbcbb
2 changed files with 20 additions and 3 deletions
|
@ -501,8 +501,25 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
|
|||
head_tag := if head { 'h1' } else { 'h2' }
|
||||
// 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.
|
||||
dn.comments[0].text
|
||||
readme_lines := dn.comments[0].text.split_into_lines()
|
||||
mut merged_lines := []string{}
|
||||
mut is_codeblock := false
|
||||
for i := 0; i < readme_lines.len - 1; i++ {
|
||||
l := readme_lines[i]
|
||||
nl := readme_lines[i + 1]
|
||||
is_codeblock_divider := l.trim_left('\x01').trim_space().starts_with('```')
|
||||
if is_codeblock_divider {
|
||||
is_codeblock = !is_codeblock
|
||||
}
|
||||
if !is_codeblock && !is_codeblock_divider && l != '' && nl != ''
|
||||
&& !nl.trim_left('\x01').trim_space().starts_with('```') {
|
||||
merged_lines << '${l} ${nl}'
|
||||
i++
|
||||
continue
|
||||
}
|
||||
merged_lines << l
|
||||
}
|
||||
merged_lines.join_lines()
|
||||
} else {
|
||||
dn.merge_comments()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<section id="readme_main" class="doc-node">
|
||||
<div class="title"><h1> main <a href="#readme_main">#</a></h1></div>
|
||||
<h2>Description</h2><p>This is an example of a an .md file, used for adding more rich textdocumentation in a project or module.</p><p>This is a <a href="https://vlang.io/">link</a> to the main V site.</p><p>This is a <b>bold text</b>.</p><p>This is a script <code><script>console.log('hi from README.md');</script></code> .</p><h2>Examples</h2><h3>Processing command line args</h3><pre><code class="language-v"><span class="token keyword">import</span> os
|
||||
<h2>Description</h2><p>This is an example of a an .md file, used for adding more rich text documentation in a project or module.</p><p>This is a <a href="https://vlang.io/">link</a> to the main V site.</p><p>This is a <b>bold text</b>.</p><p>This is a script <code><script>console.log('hi from README.md');</script></code> .</p><h2>Examples</h2><h3>Processing command line args</h3><pre><code class="language-v"><span class="token keyword">import</span> os
|
||||
|
||||
<span class="token keyword">fn</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">dump</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span>args<span class="token punctuation">)</span>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue