0
Fork 0
mirror of https://projects.blender.org/infrastructure/gitea-custom.git synced 2024-12-22 07:13:09 -05:00

Fix various issues in Sphinx .rst rendering for the blender-manual repo

This commit is contained in:
Brecht Van Lommel 2023-04-06 19:36:58 +02:00
parent da950a93e2
commit 968618dac3

View file

@ -28,10 +28,17 @@ if gitea_prefix.startswith(local_url):
gitea_prefix = gitea_prefix[len(local_url):] gitea_prefix = gitea_prefix[len(local_url):]
if len(gitea_prefix): if len(gitea_prefix):
org, repo, view, ref, branch = gitea_prefix.strip('/').split('/')[:5] path_tokens = gitea_prefix.strip('/').split('/')
org, repo, view, ref, branch = path_tokens[:5]
doc_url = f"{base_url}/{org}/{repo}/{view}/{ref}/{branch}" doc_url = f"{base_url}/{org}/{repo}/{view}/{ref}/{branch}"
image_url = f"{base_url}/{org}/{repo}/raw/{ref}/{branch}" image_url = f"{base_url}/{org}/{repo}/media/{ref}/{branch}"
# Hardcoded exception for blender-manual, that has links relative
# to manual/ folder.
if len(path_tokens) > 5 and path_tokens[5] == 'manual':
doc_url += "/manual"
image_url += "/manual"
else: else:
doc_url = "" doc_url = ""
image_url = "" image_url = ""
@ -48,10 +55,17 @@ with tempfile.TemporaryDirectory(dir=args.user_work_dir) as tmp_dir:
page_contents = page_filepath.read_text() page_contents = page_filepath.read_text()
# Turn links into external links since internal links are not found and stripped. # Turn links into external links since internal links are not found and stripped.
def doc_link(matchobj): def path_to_label(path):
path = path.removesuffix('/index')
return path.split('/')[-1].replace('_', ' ').replace('-', ' ').capitalize()
def doc_label_link(matchobj):
return f"`{matchobj.group(1)}<{doc_url}/{matchobj.group(2).strip('/')}.rst>`_" return f"`{matchobj.group(1)}<{doc_url}/{matchobj.group(2).strip('/')}.rst>`_"
def ref_link(matchobj): def doc_link(matchobj):
return f"`{path_to_label(matchobj.group(1))} <{doc_url}/{matchobj.group(1).strip('/')}.rst>`_"
def ref_label_link(matchobj):
return f"`{matchobj.group(1)} <{placeholder_url}>`_" return f"`{matchobj.group(1)} <{placeholder_url}>`_"
def ref_link(matchobj):
return f"`{path_to_label(matchobj.group(1))} <{placeholder_url}>`_"
def term_link(matchobj): def term_link(matchobj):
return f"`{matchobj.group(1)} <{placeholder_url}>`_" return f"`{matchobj.group(1)} <{placeholder_url}>`_"
def figure_link(matchobj): def figure_link(matchobj):
@ -59,12 +73,14 @@ with tempfile.TemporaryDirectory(dir=args.user_work_dir) as tmp_dir:
def image_link(matchobj): def image_link(matchobj):
return f"image:: {image_url}/{matchobj.group(1).strip('/')}" return f"image:: {image_url}/{matchobj.group(1).strip('/')}"
page_contents = re.sub(":doc:`(.*)<(.+)>`", doc_link, page_contents) page_contents = re.sub(":doc:`/(.+?)`", doc_link, page_contents)
page_contents = re.sub(":ref:`(.+)<(.+)>`", ref_link, page_contents) page_contents = re.sub(":doc:`(.+?)<(.+?)>`", doc_label_link, page_contents)
page_contents = re.sub(":ref:`(.+)`", ref_link, page_contents) page_contents = re.sub(":ref:`(.+?)<(.+?)>`", ref_label_link, page_contents)
page_contents = re.sub(":term:`(.+)`", term_link, page_contents) page_contents = re.sub(":ref:`([\w\s-]+?)`", ref_link, page_contents)
page_contents = re.sub("figure:: (.+)", figure_link, page_contents) page_contents = re.sub(":term:`(.+?)<(.+?)>`", term_link, page_contents)
page_contents = re.sub("image:: (.+)", image_link, page_contents) page_contents = re.sub(":term:`([\w\s-]+?)`", term_link, page_contents)
page_contents = re.sub("figure:: (.+?)", figure_link, page_contents)
page_contents = re.sub("image:: (.+?)", image_link, page_contents)
# Disable include directives and raw for security. They are already disabled # Disable include directives and raw for security. They are already disabled
# by docutils.py, this is just to be extra careful. # by docutils.py, this is just to be extra careful.