diff --git a/hacking/module_formatter.py b/hacking/module_formatter.py
index 5451d5abbf..1722d507f5 100755
--- a/hacking/module_formatter.py
+++ b/hacking/module_formatter.py
@@ -88,6 +88,16 @@ def html_ify(text):
t = _CONST.sub("" + r"\1" + "
", t)
return t
+def json_ify(text):
+
+ t = _ITALIC.sub("" + r"\1" + "", text)
+ t = _BOLD.sub("" + r"\1" + "", t)
+ t = _MODULE.sub("" + r"\1" + "", t)
+ t = _URL.sub("" + r"\1" + "", t)
+ t = _CONST.sub("" + r"\1" + "
", t)
+
+ return t
+
def man_ify(text):
t = _ITALIC.sub(r'\\fI' + r"\1" + r"\\fR", text)
@@ -164,7 +174,7 @@ def main():
p.add_argument("-t", "--type",
action='store',
dest='type',
- choices=['html', 'latex', 'man', 'rst'],
+ choices=['html', 'latex', 'man', 'rst', 'json'],
default='latex',
help="Output type")
p.add_argument("-m", "--module",
@@ -234,6 +244,9 @@ def main():
env.filters['xline'] = rst_xline
template = env.get_template('rst.j2')
outputname = "%s.rst"
+ if args.type == 'json':
+ env.filters['jpfunc'] = json_ify
+ outputname = "%s.json"
for module in os.listdir(args.module_dir):
if len(args.module_list):
@@ -267,7 +280,12 @@ def main():
f.close()
doc['extradata'] = extradata
- text = template.render(doc)
+ if args.type == 'json':
+ doc = { doc['module'] : doc }
+ text = json.dumps(doc, indent=2)
+ else:
+ text = template.render(doc)
+
if args.output_dir is not None:
f = open(os.path.join(args.output_dir, outputname % module), 'w')
f.write(text)