summaryrefslogtreecommitdiff
path: root/doc/tools
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2016-02-17 21:09:28 +0100
committerRémi Verschelde <rverschelde@gmail.com>2016-02-17 21:17:08 +0100
commit9e4532d68910873b65fef8616e7ebde180220b5c (patch)
tree6ed20443ffe75ee8852c0ebf9f4b14da2b7bca1e /doc/tools
parent54997552922a9eb3b2ca08a6a54add17abc35ff9 (diff)
Implement support for [codeblock] tag in help
It allows to define a multiline space-indented code block that will be properly parsed by the reST converter for the online docs. The in-editor help understand the [codeblock] tag as it supposedly understand [code] already (i.e. it just seems to discard it, though the code was supposed to switch it to a monospace font, but that's likely another issue.
Diffstat (limited to 'doc/tools')
-rw-r--r--doc/tools/makerst.py45
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'