From 4775cc3ab4b34f3fee2f49e97b4e590f46d8f4d3 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Wed, 23 Feb 2022 23:21:30 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Heading=20anchor=20resolu?= =?UTF-8?q?tion=20for=20parallel=20builds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myst_parser/myst_refs.py | 5 ++++- myst_parser/sphinx_renderer.py | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/myst_parser/myst_refs.py b/myst_parser/myst_refs.py index 5ee2de04..d4deff15 100644 --- a/myst_parser/myst_refs.py +++ b/myst_parser/myst_refs.py @@ -202,8 +202,11 @@ def _resolve_anchor( self, node: pending_xref, fromdocname: str ) -> Optional[Element]: """Resolve doc with anchor.""" + if self.env.config.myst_heading_anchors is None: + # no target anchors will have been created, so we don't look for them + return None target = node["reftarget"] # type: str - if not ("#" in target and hasattr(self.env, "myst_anchors")): + if "#" not in target: return None # the link may be a heading anchor; we need to first get the relative path rel_path, anchor = target.rsplit("#", 1) diff --git a/myst_parser/sphinx_renderer.py b/myst_parser/sphinx_renderer.py index f5b31926..379fbb94 100644 --- a/myst_parser/sphinx_renderer.py +++ b/myst_parser/sphinx_renderer.py @@ -164,9 +164,7 @@ def render_heading(self, token: SyntaxTreeNode) -> None: clean_astext(section[0]), ) - # for debugging - if not hasattr(self.doc_env, "myst_anchors"): - self.doc_env.myst_anchors = True # type: ignore[attr-defined] + self.doc_env.metadata[self.doc_env.docname]["myst_anchors"] = True section["myst-anchor"] = doc_slug def render_math_block_label(self, token: SyntaxTreeNode) -> None: