v / cmd / tools / vdoc / document / comment.v
35 lines · 28 sloc · 1.07 KB · 46447f1262986910fe68dbb4a47b743b3656910f
Raw
1module document
2
3import v.token
4
5const example_pattern = '\x01 Example: '
6
7pub struct DocComment {
8pub 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>'
18pub 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
23pub 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
28pub 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
33pub fn (dc DocComment) has_triple_backtick() bool {
34 return dc.text.starts_with('\x01 ```')
35}
36