Infra: Use relative links to ease development (#2972)
This commit is contained in:
parent
b173099ac6
commit
6fc3a4ddf3
|
@ -25,8 +25,9 @@ def _depart_maths():
|
||||||
|
|
||||||
def _update_config_for_builder(app: Sphinx) -> None:
|
def _update_config_for_builder(app: Sphinx) -> None:
|
||||||
app.env.document_ids = {} # For PEPReferenceRoleTitleText
|
app.env.document_ids = {} # For PEPReferenceRoleTitleText
|
||||||
|
app.env.settings["builder"] = app.builder.name
|
||||||
if app.builder.name == "dirhtml":
|
if app.builder.name == "dirhtml":
|
||||||
app.env.settings["pep_url"] = "/pep-{:0>4}"
|
app.env.settings["pep_url"] = "pep-{:0>4}"
|
||||||
|
|
||||||
# internal_builder exists if Sphinx is run by build.py
|
# internal_builder exists if Sphinx is run by build.py
|
||||||
if "internal_builder" not in app.tags:
|
if "internal_builder" not in app.tags:
|
||||||
|
@ -46,7 +47,7 @@ def _post_build(app: Sphinx, exception: Exception | None) -> None:
|
||||||
def setup(app: Sphinx) -> dict[str, bool]:
|
def setup(app: Sphinx) -> dict[str, bool]:
|
||||||
"""Initialize Sphinx extension."""
|
"""Initialize Sphinx extension."""
|
||||||
|
|
||||||
environment.default_settings["pep_url"] = "/pep-{:0>4}.html"
|
environment.default_settings["pep_url"] = "pep-{:0>4}.html"
|
||||||
environment.default_settings["halt_level"] = 2 # Fail on Docutils warning
|
environment.default_settings["halt_level"] = 2 # Fail on Docutils warning
|
||||||
|
|
||||||
# Register plugin logic
|
# Register plugin logic
|
||||||
|
|
|
@ -15,6 +15,10 @@ class PEPRole(roles.ReferenceRole):
|
||||||
prb = self.inliner.problematic(self.rawtext, self.rawtext, msg)
|
prb = self.inliner.problematic(self.rawtext, self.rawtext, msg)
|
||||||
return [prb], [msg]
|
return [prb], [msg]
|
||||||
pep_base = self.inliner.document.settings.pep_url.format(pep_num)
|
pep_base = self.inliner.document.settings.pep_url.format(pep_num)
|
||||||
|
if self.inliner.document.settings.builder == "dirhtml":
|
||||||
|
pep_base = "../" + pep_base
|
||||||
|
if "topic" in self.get_location():
|
||||||
|
pep_base = "../" + pep_base
|
||||||
if fragment:
|
if fragment:
|
||||||
ref_uri = f"{pep_base}#{fragment}"
|
ref_uri = f"{pep_base}#{fragment}"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -137,7 +137,11 @@ class PEPHeaders(transforms.Transform):
|
||||||
new_body = []
|
new_body = []
|
||||||
for topic_name in body.astext().split(","):
|
for topic_name in body.astext().split(","):
|
||||||
if topic_name:
|
if topic_name:
|
||||||
target = f"/topic/{topic_name.lower().strip()}/"
|
target = f"topic/{topic_name.lower().strip()}"
|
||||||
|
if self.document.settings.builder == "html":
|
||||||
|
target = f"{target}.html"
|
||||||
|
else:
|
||||||
|
target = f"../{target}/"
|
||||||
new_body += [
|
new_body += [
|
||||||
nodes.reference("", topic_name, refuri=target),
|
nodes.reference("", topic_name, refuri=target),
|
||||||
nodes.Text(", "),
|
nodes.Text(", "),
|
||||||
|
|
Loading…
Reference in New Issue