You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
makerst: Fix format of [url] links in reST
Moved some logic to make_url in an attempt to reuse it in the parser,
but it proved too complex so I ended up not using it. I kept it as a
separate method nevertheless.
(cherry picked from commit c7246d8e1e)
This commit is contained in:
@@ -478,24 +478,7 @@ def make_rst_class(class_def, state, dry_run, output_dir): # type: (ClassDef, S
|
||||
f.write(make_heading('Tutorials', '-'))
|
||||
for t in class_def.tutorials:
|
||||
link = t.strip()
|
||||
match = GODOT_DOCS_PATTERN.search(link)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
if match.lastindex == 2:
|
||||
# Doc reference with fragment identifier: emit direct link to section with reference to page, for example:
|
||||
# `#calling-javascript-from-script in Exporting For Web`
|
||||
f.write("- `" + groups[1] + " <../" + groups[0] + ".html" + groups[1] + ">`_ in :doc:`../" + groups[0] + "`\n\n")
|
||||
# Commented out alternative: Instead just emit:
|
||||
# `Subsection in Exporting For Web`
|
||||
# f.write("- `Subsection <../" + groups[0] + ".html" + groups[1] + ">`_ in :doc:`../" + groups[0] + "`\n\n")
|
||||
elif match.lastindex == 1:
|
||||
# Doc reference, for example:
|
||||
# `Math`
|
||||
f.write("- :doc:`../" + groups[0] + "`\n\n")
|
||||
else:
|
||||
# External link, for example:
|
||||
# `http://enet.bespin.org/usergroup0.html`
|
||||
f.write("- `" + link + " <" + link + ">`_\n\n")
|
||||
f.write("- " + make_url(link) + "\n\n")
|
||||
|
||||
# Property descriptions
|
||||
if len(class_def.properties) > 0:
|
||||
@@ -787,15 +770,16 @@ def rstize_text(text, state): # type: (str, State) -> str
|
||||
tag_text = "" # ''
|
||||
elif cmd.find('url=') == 0:
|
||||
url_link = cmd[4:]
|
||||
tag_text = ':ref:`'
|
||||
tag_text = '`'
|
||||
tag_depth += 1
|
||||
url_has_name = False
|
||||
inside_url = True
|
||||
url_has_name = False
|
||||
elif cmd == '/url':
|
||||
tag_text = ('' if url_has_name else url_link) + '<' + url_link + ">`"
|
||||
tag_text = ('' if url_has_name else url_link) + " <" + url_link + ">`_"
|
||||
tag_depth -= 1
|
||||
escape_post = True
|
||||
inside_url = False
|
||||
url_has_name = False
|
||||
elif cmd == 'center':
|
||||
tag_depth += 1
|
||||
tag_text = ''
|
||||
@@ -978,5 +962,26 @@ def make_heading(title, underline): # type: (str, str) -> str
|
||||
return title + '\n' + (underline * len(title)) + "\n\n"
|
||||
|
||||
|
||||
def make_url(link): # type: (str) -> str
|
||||
match = GODOT_DOCS_PATTERN.search(link)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
if match.lastindex == 2:
|
||||
# Doc reference with fragment identifier: emit direct link to section with reference to page, for example:
|
||||
# `#calling-javascript-from-script in Exporting For Web`
|
||||
return "`" + groups[1] + " <../" + groups[0] + ".html" + groups[1] + ">`_ in :doc:`../" + groups[0] + "`"
|
||||
# Commented out alternative: Instead just emit:
|
||||
# `Subsection in Exporting For Web`
|
||||
# return "`Subsection <../" + groups[0] + ".html" + groups[1] + ">`__ in :doc:`../" + groups[0] + "`"
|
||||
elif match.lastindex == 1:
|
||||
# Doc reference, for example:
|
||||
# `Math`
|
||||
return ":doc:`../" + groups[0] + "`"
|
||||
else:
|
||||
# External link, for example:
|
||||
# `http://enet.bespin.org/usergroup0.html`
|
||||
return "`" + link + " <" + link + ">`_"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user