pull/13894/head
Nick Treleaven 2022-04-01 17:20:50 +01:00
parent ea5bf34621
commit 5aae733775
1 changed files with 9 additions and 6 deletions

View File

@ -54,13 +54,15 @@ pub fn (dc DocNode) merge_comments() string {
// merge_comments_without_examples returns a `string` with the // merge_comments_without_examples returns a `string` with the
// combined contents of `DocNode.comments` - excluding any examples. // combined contents of `DocNode.comments` - excluding any examples.
pub fn (dc DocNode) merge_comments_without_examples() string { pub fn (dc DocNode) merge_comments_without_examples() string {
mut sans_examples := []DocComment{cap:dc.comments.len} mut sans_examples := []DocComment{cap: dc.comments.len}
for i := 0; i < dc.comments.len; i++ { for i := 0; i < dc.comments.len; i++ {
if dc.comments[i].is_example() { continue } if dc.comments[i].is_example() {
continue
}
if dc.comments[i].is_multi_line_example() { if dc.comments[i].is_multi_line_example() {
i++ i++
if i == dc.comments.len || !dc.comments[i].has_triple_backtick() { if i == dc.comments.len || !dc.comments[i].has_triple_backtick() {
eprintln('${dc.file_path}: Expected code block after empty example line:') eprintln('$dc.file_path: Expected code block after empty example line:')
eprintln('// ```') eprintln('// ```')
if i < dc.comments.len { if i < dc.comments.len {
eprintln('Found:') eprintln('Found:')
@ -88,15 +90,16 @@ pub fn (dn DocNode) examples() []string {
} else if comment.is_multi_line_example() { } else if comment.is_multi_line_example() {
mut j := i + 1 mut j := i + 1
mut ml_ex := '' mut ml_ex := ''
if j + 2 < dn.comments.len && dn.comments[j].has_triple_backtick() if j + 2 < dn.comments.len && dn.comments[j].has_triple_backtick() {
{
j++ j++
for j < dn.comments.len && !dn.comments[j].has_triple_backtick() { for j < dn.comments.len && !dn.comments[j].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[j].text
if s.len > 2 { ml_ex += s[2..] } if s.len > 2 {
ml_ex += s[2..]
}
j++ j++
} }
output << ml_ex output << ml_ex