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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue