mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +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' }
|
head_tag := if head { 'h1' } else { 'h2' }
|
||||||
// Allow README.md to go through unescaped except for script tags
|
// Allow README.md to go through unescaped except for script tags
|
||||||
escaped_html := if head && is_module_readme(dn) {
|
escaped_html := if head && is_module_readme(dn) {
|
||||||
// Strip markdown [TOC] directives, since we generate our own.
|
readme_lines := dn.comments[0].text.split_into_lines()
|
||||||
dn.comments[0].text
|
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 {
|
} else {
|
||||||
dn.merge_comments()
|
dn.merge_comments()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue