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:
|
||||
app.env.document_ids = {} # For PEPReferenceRoleTitleText
|
||||
app.env.settings["builder"] = app.builder.name
|
||||
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
|
||||
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]:
|
||||
"""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
|
||||
|
||||
# Register plugin logic
|
||||
|
|
|
@ -15,6 +15,10 @@ class PEPRole(roles.ReferenceRole):
|
|||
prb = self.inliner.problematic(self.rawtext, self.rawtext, msg)
|
||||
return [prb], [msg]
|
||||
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:
|
||||
ref_uri = f"{pep_base}#{fragment}"
|
||||
else:
|
||||
|
|
|
@ -137,7 +137,11 @@ class PEPHeaders(transforms.Transform):
|
|||
new_body = []
|
||||
for topic_name in body.astext().split(","):
|
||||
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 += [
|
||||
nodes.reference("", topic_name, refuri=target),
|
||||
nodes.Text(", "),
|
||||
|
|
Loading…
Reference in New Issue