ParseDescriptions splits a documentation string into multiple multi-line description sections, using blank lines as delimiters.
(doc string)
| 92 | // ParseDescriptions splits a documentation string into multiple multi-line description |
| 93 | // sections, using blank lines as delimiters. |
| 94 | func ParseDescriptions(doc string) []string { |
| 95 | var examples []string |
| 96 | if len(doc) != 0 { |
| 97 | lines := strings.Split(doc, "\n") |
| 98 | lineStart := 0 |
| 99 | for i, l := range lines { |
| 100 | // Trim trailing whitespace to identify effectively blank lines. |
| 101 | l = strings.TrimRightFunc(l, unicode.IsSpace) |
| 102 | // If a line is blank, it marks the end of the current section. |
| 103 | if len(l) == 0 { |
| 104 | // Start the next section after the blank line. |
| 105 | ex := lines[lineStart:i] |
| 106 | if len(ex) != 0 { |
| 107 | examples = append(examples, MultilineDescription(ex...)) |
| 108 | } |
| 109 | lineStart = i + 1 |
| 110 | } |
| 111 | } |
| 112 | // Append the last section if it wasn't terminated by a blank line. |
| 113 | if lineStart < len(lines) { |
| 114 | examples = append(examples, MultilineDescription(lines[lineStart:]...)) |
| 115 | } |
| 116 | } |
| 117 | return examples |
| 118 | } |
| 119 | |
| 120 | // NewVariableDoc creates a new Doc struct specifically for documenting a variable. |
| 121 | func NewVariableDoc(name, celType, description string) *Doc { |