fix parsing examples after multi-line example

pull/13894/head
Nick Treleaven 2022-04-02 11:21:43 +01:00
parent 804cb91d64
commit 6eb9f91f83
2 changed files with 9 additions and 10 deletions

View File

@ -33,4 +33,3 @@ pub fn (dc DocComment) is_multi_line_example() bool {
pub fn (dc DocComment) has_triple_backtick() bool { pub fn (dc DocComment) has_triple_backtick() bool {
return dc.text.starts_with('\x01 ```') return dc.text.starts_with('\x01 ```')
} }

View File

@ -84,26 +84,26 @@ pub fn (dc DocNode) merge_comments_without_examples() string {
// examples returns a `[]string` containing examples parsed from `DocNode.comments`. // examples returns a `[]string` containing examples parsed from `DocNode.comments`.
pub fn (dn DocNode) examples() []string { pub fn (dn DocNode) examples() []string {
mut output := []string{} mut output := []string{}
for i, comment in dn.comments { for i := 0; i < dn.comments.len; i++ {
comment := dn.comments[i]
if comment.is_example() { if comment.is_example() {
output << comment.example() output << comment.example()
} else if comment.is_multi_line_example() { } else if comment.is_multi_line_example() {
mut j := i + 1 i++
mut ml_ex := '' if i + 2 < dn.comments.len && dn.comments[i].has_triple_backtick() {
if j + 2 < dn.comments.len && dn.comments[j].has_triple_backtick() { i++
j++ mut ml_ex := ''
for j < dn.comments.len && !dn.comments[j].has_triple_backtick() { for i < dn.comments.len && !dn.comments[i].has_triple_backtick() {
if ml_ex.len > 0 { if ml_ex.len > 0 {
ml_ex += '\n' ml_ex += '\n'
} }
s := dn.comments[j].text s := dn.comments[i].text
if s.len > 2 { if s.len > 2 {
ml_ex += s[2..] ml_ex += s[2..]
} }
j++ i++
} }
output << ml_ex output << ml_ex
break
} }
} }
} }