summaryrefslogtreecommitdiff
path: root/man
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-29 19:15:13 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-29 19:15:13 -0800
commitc1d5685baa7d53d8a41160b487681498c3c79993 (patch)
tree0065aa09a673de8456ad2dd8927acf63b2975f87 /man
parentb004ef0330ece7767bd9b57aa16bfe36e8fcc350 (diff)
make_man_page.py improved.
Diffstat (limited to 'man')
-rw-r--r--man/make_man_page.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/man/make_man_page.py b/man/make_man_page.py
index 526a717..ed52381 100644
--- a/man/make_man_page.py
+++ b/man/make_man_page.py
@@ -1,18 +1,25 @@
#!/usr/bin/env python
# Creates a man page from a C file.
+
# Lines beginning with /// are treated as Markdown.
+
# Non-blank lines immediately following a /// line are treated
-# as function signatures or examples and included verbatim.
+# as function signatures or examples and included verbatim. The
+# immediately preceding markdown chunk is printed after the example
+# as a comment on it.
+
# That's about it!
import sys
import re
-special_comment_re = re.compile('\/\/\/');
+special_comment_re = re.compile('^\/\/\/ ?');
blank_re = re.compile('^\s*$');
mdlines = []
+chunk = []
+sig = []
with open('../src/cmark.h', 'r') as cmarkh:
state = 'default'
@@ -27,11 +34,26 @@ with open('../src/cmark.h', 'r') as cmarkh:
state = 'signature'
# handle line
- if oldstate != state and len(mdlines) > 0 and mdlines[-1] != '\n':
- mdlines.append('\n')
+ #if oldstate != state and len(mdlines) > 0 and mdlines[-1] != '\n':
+ # mdlines.append('\n')
if state == 'markdown':
- mdlines.append(line[4:])
+ chunk.append(re.sub(special_comment_re, '', line))
elif state == 'signature':
- mdlines.append(' ' + line)
+ sig.append(' ' + line)
+ elif oldstate == 'signature' and state != 'signature':
+ if len(mdlines) > 0 and mdlines[-1] != '\n':
+ mdlines.append('\n')
+ mdlines += sig # add sig, then prepended markdown comment
+ if len(mdlines) > 0 and mdlines[-1] != '\n':
+ mdlines.append('\n')
+ mdlines += chunk
+ chunk = []
+ sig = []
+ elif oldstate == 'markdown' and state != 'signature':
+ if len(mdlines) > 0 and mdlines[-1] != '\n':
+ mdlines.append('\n')
+ mdlines += chunk # add markdown chunk
+ chunk = []
+ mdlines.append('\n')
sys.stdout.write(''.join(mdlines))