|
11 | 11 | # Uncomment to do type checks. I have it commented out so it works below Python 3.5
|
12 | 12 | # from typing import List, Dict, TextIO, Tuple, Iterable, Optional, DefaultDict, Any, Union
|
13 | 13 |
|
14 |
| -# http(s)://docs.godotengine.org/<langcode>/<tag>/path/to/page.html(#fragment-tag) |
15 |
| -GODOT_DOCS_PATTERN = re.compile( |
16 |
| - r"^http(?:s)?://docs\.godotengine\.org/(?:[a-zA-Z0-9.\-_]*)/(?:[a-zA-Z0-9.\-_]*)/(.*)\.html(#.*)?$" |
17 |
| -) |
| 14 | +# $DOCS_URL/path/to/page.html(#fragment-tag) |
| 15 | +GODOT_DOCS_PATTERN = re.compile(r"^\$DOCS_URL/(.*)\.html(#.*)?$") |
18 | 16 |
|
19 | 17 |
|
20 | 18 | def print_error(error, state): # type: (str, State) -> None
|
@@ -857,16 +855,11 @@ def rstize_text(text, state): # type: (str, State) -> str
|
857 | 855 |
|
858 | 856 | # Handle [tags]
|
859 | 857 | inside_code = False
|
860 |
| - inside_url = False |
861 |
| - url_has_name = False |
862 |
| - url_link = "" |
863 | 858 | pos = 0
|
864 | 859 | tag_depth = 0
|
865 | 860 | previous_pos = 0
|
866 | 861 | while True:
|
867 | 862 | pos = text.find("[", pos)
|
868 |
| - if inside_url and (pos > previous_pos): |
869 |
| - url_has_name = True |
870 | 863 | if pos == -1:
|
871 | 864 | break
|
872 | 865 |
|
@@ -995,17 +988,23 @@ def rstize_text(text, state): # type: (str, State) -> str
|
995 | 988 | elif cmd.find("image=") == 0:
|
996 | 989 | tag_text = "" # ''
|
997 | 990 | elif cmd.find("url=") == 0:
|
998 |
| - url_link = cmd[4:] |
999 |
| - tag_text = "`" |
1000 |
| - tag_depth += 1 |
1001 |
| - inside_url = True |
1002 |
| - url_has_name = False |
1003 |
| - elif cmd == "/url": |
1004 |
| - tag_text = ("" if url_has_name else url_link) + " <" + url_link + ">`__" |
1005 |
| - tag_depth -= 1 |
1006 |
| - escape_post = True |
1007 |
| - inside_url = False |
1008 |
| - url_has_name = False |
| 991 | + # URLs are handled in full here as we need to extract the optional link |
| 992 | + # title to use `make_link`. |
| 993 | + link_url = cmd[4:] |
| 994 | + endurl_pos = text.find("[/url]", endq_pos + 1) |
| 995 | + if endurl_pos == -1: |
| 996 | + print_error( |
| 997 | + "Tag depth mismatch for [url]: no closing [/url], file: {}".format(state.current_class), state |
| 998 | + ) |
| 999 | + break |
| 1000 | + link_title = text[endq_pos + 1 : endurl_pos] |
| 1001 | + tag_text = make_link(link_url, link_title) |
| 1002 | + |
| 1003 | + pre_text = text[:pos] |
| 1004 | + text = pre_text + tag_text + text[endurl_pos + 6 :] |
| 1005 | + pos = len(pre_text) + len(tag_text) |
| 1006 | + previous_pos = pos |
| 1007 | + continue |
1009 | 1008 | elif cmd == "center":
|
1010 | 1009 | tag_depth += 1
|
1011 | 1010 | tag_text = ""
|
@@ -1252,21 +1251,22 @@ def make_link(url, title): # type: (str, str) -> str
|
1252 | 1251 | if match.lastindex == 2:
|
1253 | 1252 | # Doc reference with fragment identifier: emit direct link to section with reference to page, for example:
|
1254 | 1253 | # `#calling-javascript-from-script in Exporting For Web`
|
1255 |
| - return "`" + groups[1] + " <../" + groups[0] + ".html" + groups[1] + ">`_ in :doc:`../" + groups[0] + "`" |
1256 |
| - # Commented out alternative: Instead just emit: |
1257 |
| - # `Subsection in Exporting For Web` |
1258 |
| - # return "`Subsection <../" + groups[0] + ".html" + groups[1] + ">`__ in :doc:`../" + groups[0] + "`" |
| 1254 | + # Or use the title if provided. |
| 1255 | + if title != "": |
| 1256 | + return "`" + title + " <../" + groups[0] + ".html" + groups[1] + ">`__" |
| 1257 | + return "`" + groups[1] + " <../" + groups[0] + ".html" + groups[1] + ">`__ in :doc:`../" + groups[0] + "`" |
1259 | 1258 | elif match.lastindex == 1:
|
1260 | 1259 | # Doc reference, for example:
|
1261 | 1260 | # `Math`
|
| 1261 | + if title != "": |
| 1262 | + return ":doc:`" + title + " <../" + groups[0] + ">`" |
1262 | 1263 | return ":doc:`../" + groups[0] + "`"
|
1263 | 1264 | else:
|
1264 | 1265 | # External link, for example:
|
1265 | 1266 | # `http://enet.bespin.org/usergroup0.html`
|
1266 | 1267 | if title != "":
|
1267 | 1268 | return "`" + title + " <" + url + ">`__"
|
1268 |
| - else: |
1269 |
| - return "`" + url + " <" + url + ">`__" |
| 1269 | + return "`" + url + " <" + url + ">`__" |
1270 | 1270 |
|
1271 | 1271 |
|
1272 | 1272 | def sanitize_operator_name(dirty_name, state): # type: (str, State) -> str
|
|
0 commit comments