Update make_rst.py
for non-latin texts
This commit is contained in:
parent
71616630e0
commit
9844e36354
1 changed files with 31 additions and 4 deletions
|
@ -14,6 +14,11 @@ from collections import OrderedDict
|
||||||
# $DOCS_URL/path/to/page.html(#fragment-tag)
|
# $DOCS_URL/path/to/page.html(#fragment-tag)
|
||||||
GODOT_DOCS_PATTERN = re.compile(r"^\$DOCS_URL/(.*)\.html(#.*)?$")
|
GODOT_DOCS_PATTERN = re.compile(r"^\$DOCS_URL/(.*)\.html(#.*)?$")
|
||||||
|
|
||||||
|
# Based on reStructedText inline markup recognition rules
|
||||||
|
# https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
|
||||||
|
MARKUP_ALLOWED_PRECEDENT = " -:/'\"<([{"
|
||||||
|
MARKUP_ALLOWED_SUBSEQUENT = " -.,:;!?\\/'\")]}>"
|
||||||
|
|
||||||
|
|
||||||
def print_error(error, state): # type: (str, State) -> None
|
def print_error(error, state): # type: (str, State) -> None
|
||||||
print("ERROR: {}".format(error))
|
print("ERROR: {}".format(error))
|
||||||
|
@ -844,12 +849,12 @@ def rstize_text(text, state): # type: (str, State) -> str
|
||||||
if result is None:
|
if result is None:
|
||||||
return ""
|
return ""
|
||||||
text = pre_text + result[0]
|
text = pre_text + result[0]
|
||||||
pos += result[1]
|
pos += result[1] - indent_level
|
||||||
|
|
||||||
# Handle normal text
|
# Handle normal text
|
||||||
else:
|
else:
|
||||||
text = pre_text + "\n\n" + post_text
|
text = pre_text + "\n\n" + post_text
|
||||||
pos += 2
|
pos += 2 - indent_level
|
||||||
|
|
||||||
next_brac_pos = text.find("[")
|
next_brac_pos = text.find("[")
|
||||||
text = escape_rst(text, next_brac_pos)
|
text = escape_rst(text, next_brac_pos)
|
||||||
|
@ -872,6 +877,7 @@ def rstize_text(text, state): # type: (str, State) -> str
|
||||||
post_text = text[endq_pos + 1 :]
|
post_text = text[endq_pos + 1 :]
|
||||||
tag_text = text[pos + 1 : endq_pos]
|
tag_text = text[pos + 1 : endq_pos]
|
||||||
|
|
||||||
|
escape_pre = False
|
||||||
escape_post = False
|
escape_post = False
|
||||||
|
|
||||||
if tag_text in state.classes:
|
if tag_text in state.classes:
|
||||||
|
@ -880,6 +886,7 @@ def rstize_text(text, state): # type: (str, State) -> str
|
||||||
tag_text = "``{}``".format(tag_text)
|
tag_text = "``{}``".format(tag_text)
|
||||||
else:
|
else:
|
||||||
tag_text = make_type(tag_text, state)
|
tag_text = make_type(tag_text, state)
|
||||||
|
escape_pre = True
|
||||||
escape_post = True
|
escape_post = True
|
||||||
else: # command
|
else: # command
|
||||||
cmd = tag_text
|
cmd = tag_text
|
||||||
|
@ -1010,7 +1017,14 @@ def rstize_text(text, state): # type: (str, State) -> str
|
||||||
tag_text = make_link(link_url, link_title)
|
tag_text = make_link(link_url, link_title)
|
||||||
|
|
||||||
pre_text = text[:pos]
|
pre_text = text[:pos]
|
||||||
text = pre_text + tag_text + text[endurl_pos + 6 :]
|
post_text = text[endurl_pos + 6 :]
|
||||||
|
|
||||||
|
if pre_text and pre_text[-1] not in MARKUP_ALLOWED_PRECEDENT:
|
||||||
|
pre_text += "\ "
|
||||||
|
if post_text and post_text[0] not in MARKUP_ALLOWED_SUBSEQUENT:
|
||||||
|
post_text = "\ " + post_text
|
||||||
|
|
||||||
|
text = pre_text + tag_text + post_text
|
||||||
pos = len(pre_text) + len(tag_text)
|
pos = len(pre_text) + len(tag_text)
|
||||||
previous_pos = pos
|
previous_pos = pos
|
||||||
continue
|
continue
|
||||||
|
@ -1047,40 +1061,53 @@ def rstize_text(text, state): # type: (str, State) -> str
|
||||||
elif cmd == "i" or cmd == "/i":
|
elif cmd == "i" or cmd == "/i":
|
||||||
if cmd == "/i":
|
if cmd == "/i":
|
||||||
tag_depth -= 1
|
tag_depth -= 1
|
||||||
|
escape_post = True
|
||||||
else:
|
else:
|
||||||
tag_depth += 1
|
tag_depth += 1
|
||||||
|
escape_pre = True
|
||||||
tag_text = "*"
|
tag_text = "*"
|
||||||
elif cmd == "b" or cmd == "/b":
|
elif cmd == "b" or cmd == "/b":
|
||||||
if cmd == "/b":
|
if cmd == "/b":
|
||||||
tag_depth -= 1
|
tag_depth -= 1
|
||||||
|
escape_post = True
|
||||||
else:
|
else:
|
||||||
tag_depth += 1
|
tag_depth += 1
|
||||||
|
escape_pre = True
|
||||||
tag_text = "**"
|
tag_text = "**"
|
||||||
elif cmd == "u" or cmd == "/u":
|
elif cmd == "u" or cmd == "/u":
|
||||||
if cmd == "/u":
|
if cmd == "/u":
|
||||||
tag_depth -= 1
|
tag_depth -= 1
|
||||||
|
escape_post = True
|
||||||
else:
|
else:
|
||||||
tag_depth += 1
|
tag_depth += 1
|
||||||
|
escape_pre = True
|
||||||
tag_text = ""
|
tag_text = ""
|
||||||
elif cmd == "code":
|
elif cmd == "code":
|
||||||
tag_text = "``"
|
tag_text = "``"
|
||||||
tag_depth += 1
|
tag_depth += 1
|
||||||
inside_code = True
|
inside_code = True
|
||||||
|
escape_pre = True
|
||||||
elif cmd == "kbd":
|
elif cmd == "kbd":
|
||||||
tag_text = ":kbd:`"
|
tag_text = ":kbd:`"
|
||||||
tag_depth += 1
|
tag_depth += 1
|
||||||
|
escape_pre = True
|
||||||
elif cmd == "/kbd":
|
elif cmd == "/kbd":
|
||||||
tag_text = "`"
|
tag_text = "`"
|
||||||
tag_depth -= 1
|
tag_depth -= 1
|
||||||
|
escape_post = True
|
||||||
elif cmd.startswith("enum "):
|
elif cmd.startswith("enum "):
|
||||||
tag_text = make_enum(cmd[5:], state)
|
tag_text = make_enum(cmd[5:], state)
|
||||||
|
escape_pre = True
|
||||||
escape_post = True
|
escape_post = True
|
||||||
else:
|
else:
|
||||||
tag_text = make_type(tag_text, state)
|
tag_text = make_type(tag_text, state)
|
||||||
|
escape_pre = True
|
||||||
escape_post = True
|
escape_post = True
|
||||||
|
|
||||||
# Properly escape things like `[Node]s`
|
# Properly escape things like `[Node]s`
|
||||||
if escape_post and post_text and (post_text[0].isalnum() or post_text[0] == "("): # not punctuation, escape
|
if escape_pre and pre_text and pre_text[-1] not in MARKUP_ALLOWED_PRECEDENT:
|
||||||
|
pre_text += "\ "
|
||||||
|
if escape_post and post_text and post_text[0] not in MARKUP_ALLOWED_SUBSEQUENT:
|
||||||
post_text = "\ " + post_text
|
post_text = "\ " + post_text
|
||||||
|
|
||||||
next_brac_pos = post_text.find("[", 0)
|
next_brac_pos = post_text.find("[", 0)
|
||||||
|
|
Loading…
Reference in a new issue