Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
) 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``.
- Loading branch information
Showing
11 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
"""Test sphinx.ext.ifconfig extension.""" | ||
|
||
import docutils.utils | ||
import pytest | ||
|
||
from sphinx import addnodes | ||
from sphinx.testing import restructuredtext | ||
|
||
|
||
@pytest.mark.sphinx('text', testroot='ext-ifconfig') | ||
def test_ifconfig(app, status, warning): | ||
app.builder.build_all() | ||
result = (app.outdir / 'index.txt').read_text(encoding='utf8') | ||
assert 'spam' in result | ||
assert 'ham' not in result | ||
|
||
|
||
def test_ifconfig_content_line_number(app): | ||
app.setup_extension("sphinx.ext.ifconfig") | ||
text = (".. ifconfig:: confval1\n" + | ||
"\n" + | ||
" Some link here: :ref:`abc`\n") | ||
doc = restructuredtext.parse(app, text) | ||
xrefs = list(doc.findall(condition=addnodes.pending_xref)) | ||
assert len(xrefs) == 1 | ||
source, line = docutils.utils.get_source_line(xrefs[0]) | ||
assert 'index.rst' in source | ||
assert line == 3 |