Skip to content

Commit

Permalink
vdoc: fix markdown lists in html (#21287)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Apr 15, 2024
1 parent e676245 commit e387fcb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
16 changes: 12 additions & 4 deletions cmd/tools/vdoc/html.v
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,21 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
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++ {
for i := 0; i < readme_lines.len; i++ {
l := readme_lines[i]
nl := readme_lines[i + 1]
if l.trim_left('\x01').trim_space().starts_with('```') {
nl := readme_lines[i + 1] or {
merged_lines << l
break
}
l_trimmed := l.trim_left('\x01').trim_space()
if l_trimmed.starts_with('```') {
is_codeblock = !is_codeblock
}
if !is_codeblock && l != '' && nl != ''
// -> if l_trimmed.len > 1 && (is_ul || is_ol)
is_list := l_trimmed.len > 1 && ((l_trimmed[1] == ` ` && l_trimmed[0] in [`*`, `-`])
|| (l_trimmed.len > 2 && l_trimmed[2] == ` ` && l_trimmed[1] == `.`
&& l_trimmed[0].is_digit()))
if !is_codeblock && l != '' && nl != '' && !is_list
&& !nl.trim_left('\x01').trim_space().starts_with('```') {
merged_lines << '${l} ${nl}'
i++
Expand Down
8 changes: 8 additions & 0 deletions cmd/tools/vdoc/tests/testdata/output_formats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,11 @@ const html = '<!DOCTYPE html>
</script>
</html>'
```

- Regular markdown list point 1
- List point 2
- List point 3

1. Numbered markdown list point 1
2. List point 2
3. List point 3
13 changes: 13 additions & 0 deletions cmd/tools/vdoc/tests/testdata/output_formats/main.ansi
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ const html = '<!DOCTYPE html>
}
</script>
</html>'

Regular markdown list point 1
List point 2
List point 3

Numbered markdown list point 1
List point 2
List point 3
module main
## Description

Expand Down Expand Up @@ -243,6 +251,11 @@ const html = '<!DOCTYPE html>
</html>'
```

- Regular markdown list point 1
- List point 2
- List point 3

1. Numbered markdown list point 1 2. List point 2 3. List point 3

const omega = 3 // should be first
const alpha = 5 // should be in the middle
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/vdoc/tests/testdata/output_formats/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h2>Description</h2><p>This is an example of a an .md file, used for adding more
console.log(res);
}
&lt;/script&gt;
&lt;/html&gt;'</span></code></pre>
&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>

</section>

Expand Down
5 changes: 5 additions & 0 deletions cmd/tools/vdoc/tests/testdata/output_formats/main.text
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ module main
</html>'
```

- Regular markdown list point 1
- List point 2
- List point 3

1. Numbered markdown list point 1 2. List point 2 3. List point 3

const omega = 3 // should be first
const alpha = 5 // should be in the middle
Expand Down

0 comments on commit e387fcb

Please sign in to comment.