diff options
Diffstat (limited to 'doc/tools/makerst.py')
-rw-r--r-- | doc/tools/makerst.py | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/doc/tools/makerst.py b/doc/tools/makerst.py index 1e2d276fb3..2ba291680d 100644 --- a/doc/tools/makerst.py +++ b/doc/tools/makerst.py @@ -100,7 +100,7 @@ def make_class_list(class_list, columns): def rstize_text(text,cclass): - # Linebreak + tabs in the XML should become two line breaks + # Linebreak + tabs in the XML should become two line breaks unless in a "codeblock" pos = 0 while True: pos = text.find('\n', pos) @@ -112,8 +112,40 @@ def rstize_text(text,cclass): pos += 1 post_text = text[pos+1:] - text = pre_text + "\n\n" + post_text - pos += 2 + # Handle codeblocks + if post_text.startswith("[codeblock]"): + end_pos = post_text.find("[/codeblock]") + if end_pos == -1: + sys.exit("ERROR! [codeblock] without a closing tag!") + + code_text = post_text[len("[codeblock]"):end_pos] + post_text = post_text[end_pos:] + + # Remove extraneous tabs + code_pos = 0 + while True: + code_pos = code_text.find('\n', code_pos) + if code_pos == -1: + break + + to_skip = 0 + while code_pos+to_skip+1 < len(code_text) and code_text[code_pos+to_skip+1] == '\t': + to_skip += 1 + + if len(code_text[code_pos+to_skip+1:])==0: + code_text = code_text[:code_pos] + "\n" + code_pos += 1 + else: + code_text = code_text[:code_pos] + "\n " + code_text[code_pos+to_skip+1:] + code_pos += 5 - to_skip + + text = pre_text + "\n[codeblock]" + code_text + post_text + pos += len("\n[codeblock]" + code_text) + + # Handle normal text + else: + text = pre_text + "\n\n" + post_text + pos += 2 # Escape * character to avoid interpreting it as emphasis pos = 0 @@ -179,6 +211,13 @@ def rstize_text(text,cclass): tag_text = '' elif cmd == '/center': tag_text = '' + elif cmd == 'codeblock': + tag_text = '\n::\n' + elif cmd == '/codeblock': + tag_text = '' + # Strip newline if the tag was alone on one + if pre_text[-1] == '\n': + pre_text = pre_text[:-1] elif cmd == 'br': # Make a new paragraph instead of a linebreak, rst is not so linebreak friendly tag_text = '\n\n' |