summaryrefslogtreecommitdiff
path: root/sphinx/domains/javascript.py
diff options
context:
space:
mode:
authorJeremy Maitin-Shepard <jbms@google.com>2023-02-14 21:45:28 -0800
committerGitHub <noreply@github.com>2023-02-15 05:45:28 +0000
commit8de6638697b8c785f8022e1f526b549e74d033d1 (patch)
treee258ab7ff1b435ed4ec4c45a9c566205aee25b0f /sphinx/domains/javascript.py
parent44684e165426470e8e8befa45e32d1b0b2f6302e (diff)
downloadsphinx-git-8de6638697b8c785f8022e1f526b549e74d033d1.tar.gz
Add ``content_offset`` parameter to ``nested_parse_with_titles`` (#11147)
Previously, ``nested_parse_with_titles`` always passed ``0`` as the input offset when invoking ``nested_parse``. When parsing the content of a directive, as is a common use case for ``nested_parse_with_titles``, this leads to incorrect source file/line number information, as it does not take into account the directive's ``content_offset``, which is always non-zero. This issue affects *all* object descriptions due to GH-10887. It also affects the ``sphinx.ext.ifconfig`` extension. The ``py:module`` and ``js:module`` directives employed a workaround for this issue, by wrapping the calls to ``nested_parse_with_title`` with ``switch_source_input``. That worked, but was more complicated (and likely less efficient) than necessary. This commit adds an optional ``content_offset`` parameter to ``nested_parse_with_titles``, and fixes callers to pass the appropriate content offset when needed. This commit eliminates the now-unnecessary calls to ``switch_source_input`` and instead specifies the correct ``content_offset``.
Diffstat (limited to 'sphinx/domains/javascript.py')
-rw-r--r--sphinx/domains/javascript.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py
index 97640f74b..86476582a 100644
--- a/sphinx/domains/javascript.py
+++ b/sphinx/domains/javascript.py
@@ -20,7 +20,7 @@ from sphinx.locale import _, __
from sphinx.roles import XRefRole
from sphinx.util import logging
from sphinx.util.docfields import Field, GroupedField, TypedField
-from sphinx.util.docutils import SphinxDirective, switch_source_input
+from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import make_id, make_refnode, nested_parse_with_titles
from sphinx.util.typing import OptionSpec
@@ -297,10 +297,9 @@ class JSModule(SphinxDirective):
noindex = 'noindex' in self.options
content_node: Element = nodes.section()
- with switch_source_input(self.state, self.content):
- # necessary so that the child nodes get the right source/line set
- content_node.document = self.state.document
- nested_parse_with_titles(self.state, self.content, content_node)
+ # necessary so that the child nodes get the right source/line set
+ content_node.document = self.state.document
+ nested_parse_with_titles(self.state, self.content, content_node, self.content_offset)
ret: list[Node] = []
if not noindex: