| 1 | module document |
| 2 | |
| 3 | import v.token |
| 4 | |
| 5 | const example_pattern = '\x01 Example: ' |
| 6 | |
| 7 | pub struct DocComment { |
| 8 | pub mut: |
| 9 | text string // Raw text content of the comment, excluding the comment token chars ('//, /*, */') |
| 10 | is_multi bool // Is a block / multi-line comment |
| 11 | pos token.Pos |
| 12 | is_readme bool |
| 13 | frontmatter map[string]string |
| 14 | } |
| 15 | |
| 16 | // is_example returns true if the contents of this comment is an inline doc example. |
| 17 | // The current convention is '// Example: <content>' |
| 18 | pub fn (dc DocComment) is_example() bool { |
| 19 | return dc.text.trim_space().starts_with(example_pattern) |
| 20 | } |
| 21 | |
| 22 | // example returns the content of the inline example body |
| 23 | pub fn (dc DocComment) example() string { |
| 24 | return dc.text.all_after(example_pattern) |
| 25 | } |
| 26 | |
| 27 | // is_multi_line_example returns true if an example line has no inline code |
| 28 | pub fn (dc DocComment) is_multi_line_example() bool { |
| 29 | return dc.text.trim_space() == '\x01 Example:' |
| 30 | } |
| 31 | |
| 32 | // has_triple_backtick returns true if the comment starts or ends a markdown code block |
| 33 | pub fn (dc DocComment) has_triple_backtick() bool { |
| 34 | return dc.text.starts_with('\x01 ```') |
| 35 | } |
| 36 | |