diff options
author | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-01-10 15:34:55 +0000 |
---|---|---|
committer | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-01-10 15:51:37 +0000 |
commit | 31162a9b6335f2abce9ffb90b905a314f6bdfe6b (patch) | |
tree | 8b6d81acb47c7abdcd420f7ce39c77e0f46bf23f | |
parent | dcb4429abacda015f98875fe9489ced696155bd7 (diff) | |
download | sphinx-git-31162a9b6335f2abce9ffb90b905a314f6bdfe6b.tar.gz |
Handle exceptions for ``get_node_source`` and ``get_node_line``
-rw-r--r-- | sphinx/builders/linkcheck.py | 5 | ||||
-rw-r--r-- | sphinx/util/nodes.py | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 8b750df2d..b7baa719d 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -509,7 +509,10 @@ class HyperlinkCollector(SphinxPostTransform): if newuri: uri = newuri - lineno = get_node_line(node) + try: + lineno = get_node_line(node) + except ValueError: + lineno = None uri_info = Hyperlink(uri, self.env.docname, lineno) if uri not in hyperlinks: hyperlinks[uri] = uri_info diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index 794eea255..9599dbc23 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -172,7 +172,10 @@ def apply_source_workaround(node: Element) -> None: ))): logger.debug('[i18n] PATCH: %r to have source and line: %s', get_full_module_name(node), repr_domxml(node)) - node.source = get_node_source(node) or '' + try: + node.source = get_node_source(node) + except ValueError: + node.source = '' node.line = 0 # need fix docutils to get `node.line` return @@ -561,8 +564,9 @@ def set_role_source_info(inliner: Inliner, lineno: int, node: Node) -> None: def copy_source_info(src: Element, dst: Element) -> None: - dst.source = get_node_source(src) - dst.line = get_node_line(src) + with contextlib.suppress(ValueError): + dst.source = get_node_source(src) + dst.line = get_node_line(src) NON_SMARTQUOTABLE_PARENT_NODES = ( |