forked from wenhsinjen/ptxconf
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapi2md.py
More file actions
executable file
·40 lines (28 loc) · 923 Bytes
/
api2md.py
File metadata and controls
executable file
·40 lines (28 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /usr/bin/python
import pdoc
import sys
import os
modpath = os.path.dirname( os.path.abspath(sys.argv[1]) )
modname = os.path.basename(sys.argv[1]).split(".py")[0]
sys.path.append( modpath )
pdoc.import_path.append( modpath )
md = []
for line in pdoc.text( modname ).split('\n'):
md.append(line)
md.append("")
for i, line in enumerate(md):
if i>len(md)-2: break
# first level headings
if "----" == md[i+1][0:4]:
print "#"+line
# first level definitions class names / functions
elif line != "" and " " != line[0:4] and "----" != line[0:4] and "----" != md[i+1][0:4]:
print "##"+line
elif " " == line[0:4] and "----" in md[i+1][4:8]:
print "###"+line[4:]
# methods
elif "(self" in line:
print "####"+line[4:]
# plain text/members
elif line != "" and " " == line[0:4] and "----" not in line:
print line[4:].strip()