diff options
Diffstat (limited to 'doc/tools')
-rw-r--r-- | doc/tools/makemd.py | 21 | ||||
-rw-r--r-- | doc/tools/makerst.py | 30 |
2 files changed, 39 insertions, 12 deletions
diff --git a/doc/tools/makemd.py b/doc/tools/makemd.py index b2444eb47b..a73a4337d0 100644 --- a/doc/tools/makemd.py +++ b/doc/tools/makemd.py @@ -2,12 +2,19 @@ # -*- coding: utf-8 -*- import sys +import os.path as path +import os import xml.etree.ElementTree as ET input_list = [] for arg in sys.argv[1:]: - input_list.append(arg) + if not path.exists(arg): + exit("path {} doesn't exist".format(arg)) + elif path.isdir(arg): + input_list += filter(path.isfile, [path.join(arg, f) for f in os.listdir(arg)]) + else: # assuming is a file + input_list.append(arg) if len(input_list) < 1: print 'usage: makemd.py <classes.xml>' @@ -29,7 +36,6 @@ def make_class_list(class_list, columns): f = open('class_list.md', 'wb') prev = 0 col_max = len(class_list) / columns + 1 - print ('col max is ', col_max) col_count = 0 row_count = 0 last_initial = '' @@ -335,12 +341,11 @@ for file in input_list: sys.exit(255) version = doc.attrib['version'] - - for c in list(doc): - if c.attrib['name'] in class_names: - continue - class_names.append(c.attrib['name']) - classes[c.attrib['name']] = c + class_name = doc.attrib['name'] + if class_name in class_names: + continue + class_names.append(class_name) + classes[class_name] = doc class_names.sort() diff --git a/doc/tools/makerst.py b/doc/tools/makerst.py index 492f3b6d54..9e767bf3d6 100644 --- a/doc/tools/makerst.py +++ b/doc/tools/makerst.py @@ -155,8 +155,9 @@ def rstize_text(text, cclass): # Escape * character to avoid interpreting it as emphasis pos = 0 + next_brac_pos = text.find('['); while True: - pos = text.find('*', pos) + pos = text.find('*', pos, next_brac_pos) if pos == -1: break text = text[:pos] + "\*" + text[pos + 1:] @@ -165,7 +166,7 @@ def rstize_text(text, cclass): # Escape _ character at the end of a word to avoid interpreting it as an inline hyperlink pos = 0 while True: - pos = text.find('_', pos) + pos = text.find('_', pos, next_brac_pos) if pos == -1: break if not text[pos + 1].isalnum(): # don't escape within a snake_case word @@ -264,6 +265,27 @@ def rstize_text(text, cclass): if escape_post and post_text and post_text[0].isalnum(): # not punctuation, escape post_text = '\ ' + post_text + next_brac_pos = post_text.find('[',0) + iter_pos = 0 + while not inside_code: + iter_pos = post_text.find('*', iter_pos, next_brac_pos) + if iter_pos == -1: + break + post_text = post_text[:iter_pos] + "\*" + post_text[iter_pos + 1:] + iter_pos += 2 + + iter_pos = 0 + while not inside_code: + iter_pos = post_text.find('_', iter_pos, next_brac_pos) + if iter_pos == -1: + break + if not post_text[iter_pos + 1].isalnum(): # don't escape within a snake_case word + post_text = post_text[:iter_pos] + "\_" + post_text[iter_pos + 1:] + iter_pos += 2 + else: + iter_pos += 1 + + text = pre_text + tag_text + post_text pos = len(pre_text) + len(tag_text) @@ -500,7 +522,7 @@ def make_rst_class(node): enums.append(c) else: consts.append(c) - + if len(consts) > 0: f.write(make_heading('Numeric Constants', '-')) for c in list(consts): @@ -512,7 +534,7 @@ def make_rst_class(node): s += ' --- ' + rstize_text(c.text.strip(), name) f.write(s + '\n') f.write('\n') - + if len(enum_names) > 0: f.write(make_heading('Enums', '-')) for e in enum_names: |