From 6eb9f91f83662fc1d5665db88360271aff40ce21 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 2 Apr 2022 11:21:43 +0100 Subject: [PATCH] fix parsing examples after multi-line example --- vlib/v/doc/comment.v | 1 - vlib/v/doc/node.v | 18 +++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/vlib/v/doc/comment.v b/vlib/v/doc/comment.v index d88d610a8f..679149cd76 100644 --- a/vlib/v/doc/comment.v +++ b/vlib/v/doc/comment.v @@ -33,4 +33,3 @@ pub fn (dc DocComment) is_multi_line_example() bool { pub fn (dc DocComment) has_triple_backtick() bool { return dc.text.starts_with('\x01 ```') } - diff --git a/vlib/v/doc/node.v b/vlib/v/doc/node.v index 9d2da7a42b..98a40b3e2f 100644 --- a/vlib/v/doc/node.v +++ b/vlib/v/doc/node.v @@ -84,26 +84,26 @@ pub fn (dc DocNode) merge_comments_without_examples() string { // examples returns a `[]string` containing examples parsed from `DocNode.comments`. pub fn (dn DocNode) examples() []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() { output << comment.example() } else if comment.is_multi_line_example() { - mut j := i + 1 - mut ml_ex := '' - if j + 2 < dn.comments.len && dn.comments[j].has_triple_backtick() { - j++ - for j < dn.comments.len && !dn.comments[j].has_triple_backtick() { + i++ + if i + 2 < dn.comments.len && dn.comments[i].has_triple_backtick() { + i++ + mut ml_ex := '' + for i < dn.comments.len && !dn.comments[i].has_triple_backtick() { if ml_ex.len > 0 { ml_ex += '\n' } - s := dn.comments[j].text + s := dn.comments[i].text if s.len > 2 { ml_ex += s[2..] } - j++ + i++ } output << ml_ex - break } } }