mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
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.
This commit is contained in:
parent
5499755292
commit
9e4532d689
3 changed files with 76 additions and 34 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue