makerst: use link titles for external tutorials

This commit is contained in:
merumelu 2021-07-29 21:55:39 +02:00
parent 140905df8d
commit b8752d91dc

View file

@ -108,7 +108,7 @@ class ClassDef:
self.brief_description = None # type: Optional[str] self.brief_description = None # type: Optional[str]
self.description = None # type: Optional[str] self.description = None # type: Optional[str]
self.theme_items = None # type: Optional[OrderedDict[str, List[ThemeItemDef]]] self.theme_items = None # type: Optional[OrderedDict[str, List[ThemeItemDef]]]
self.tutorials = [] # type: List[str] self.tutorials = [] # type: List[Tuple[str, str]]
# Used to match the class with XML source for output filtering purposes. # Used to match the class with XML source for output filtering purposes.
self.filepath = "" # type: str self.filepath = "" # type: str
@ -257,7 +257,7 @@ class State:
assert link.tag == "link" assert link.tag == "link"
if link.text is not None: if link.text is not None:
class_def.tutorials.append(link.text) class_def.tutorials.append((link.text.strip(), link.get("title", "")))
def sort_classes(self): # type: () -> None def sort_classes(self): # type: () -> None
self.classes = OrderedDict(sorted(self.classes.items(), key=lambda t: t[0])) self.classes = OrderedDict(sorted(self.classes.items(), key=lambda t: t[0]))
@ -431,9 +431,8 @@ def make_rst_class(class_def, state, dry_run, output_dir): # type: (ClassDef, S
# Online tutorials # Online tutorials
if len(class_def.tutorials) > 0: if len(class_def.tutorials) > 0:
f.write(make_heading("Tutorials", "-")) f.write(make_heading("Tutorials", "-"))
for t in class_def.tutorials: for url, title in class_def.tutorials:
link = t.strip() f.write("- " + make_link(url, title) + "\n\n")
f.write("- " + make_url(link) + "\n\n")
# Properties overview # Properties overview
if len(class_def.properties) > 0: if len(class_def.properties) > 0:
@ -1062,8 +1061,8 @@ def make_footer(): # type: () -> str
# fmt: on # fmt: on
def make_url(link): # type: (str) -> str def make_link(url, title): # type: (str, str) -> str
match = GODOT_DOCS_PATTERN.search(link) match = GODOT_DOCS_PATTERN.search(url)
if match: if match:
groups = match.groups() groups = match.groups()
if match.lastindex == 2: if match.lastindex == 2:
@ -1080,7 +1079,10 @@ def make_url(link): # type: (str) -> str
else: else:
# External link, for example: # External link, for example:
# `http://enet.bespin.org/usergroup0.html` # `http://enet.bespin.org/usergroup0.html`
return "`" + link + " <" + link + ">`_" if title != "":
return "`" + title + " <" + url + ">`_"
else:
return "`" + url + " <" + url + ">`_"
if __name__ == "__main__": if __name__ == "__main__":