Skip to content

Commit

Permalink
Allow multi line comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Gall committed Dec 10, 2019
1 parent d9da3e5 commit b7ab20e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,18 @@ Footer blocks are added after the attributes

### Unclassified text

any other lines starting ```#=``` outside of a block are added after all the footers
any other lines starting ```#=``` outside of a block are added after all the footers

## Multiline doc strings

start line with ```/*=``` rest of line is ignored all lines upto but not including a line containing ```*/``` are added acording to the same rules as above. You can include section directives within the multiline comments

```
/*=
#=OUTLINE= title
this text
is all included
in the markdown
but not this */
```
26 changes: 24 additions & 2 deletions docgen
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ for file in args.source:
if os.path.isdir(file):
continue
if args.verbose: print(f'>>> {file}')
multiline_comment = False
with open(file) as f:
for line in f.readlines():
line = line.strip()
Expand All @@ -109,12 +110,31 @@ for file in args.source:

if words[0] == '#=OUTLINE=':
docs.outline(words[1])
continue

if words[0] == '#=SECTION=':
docs.section(words[1])
continue

if words[0] == '#=FOOTER=':
docs.footer(words[1])
continue

if words[0] == '#==':
docs.end_block()
continue

if words[0] == '/*=':
multiline_comment = True
continue

if multiline_comment and '*/' in line:
multiline_comment = False
continue

if multiline_comment:
docs.add_text(line)
continue

if words[0] == 'variable':
name = re.search('"(.*)"', words[1])
Expand All @@ -135,8 +155,10 @@ for file in args.source:
name = re.search('"(.*)"', words[1])
docs.output(name.group(1))

if words[0] == '#==':
docs.end_block()
elif multiline_comment:
docs.add_text(line)



if args.out:
file = open(args.out[0],'w+')
Expand Down
13 changes: 13 additions & 0 deletions examples/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ output "urls" {

#= ### Unclassified text
#= stuff not in a block

output "not_in_order" {
value = 1
}

/*=
#=SECTION= Multiline MD
- test markdown
- within
- multiline comment
``` bit of code ```
*/

0 comments on commit b7ab20e

Please sign in to comment.