Skip to content

Commit 1a733c3

Browse files
authored
Merge branch 'master' into du22-title-style-context
2 parents ae781c0 + f928da1 commit 1a733c3

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

sphinx/directives/other.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
from typing import TYPE_CHECKING, cast
77

8+
import docutils
89
from docutils import nodes
910
from docutils.parsers.rst import directives
1011
from docutils.parsers.rst.directives.misc import Class
@@ -21,14 +22,15 @@
2122

2223
if TYPE_CHECKING:
2324
from collections.abc import Sequence
24-
from typing import Any, ClassVar
25+
from typing import Any, ClassVar, Final
2526

2627
from docutils.nodes import Element, Node
2728

2829
from sphinx.application import Sphinx
2930
from sphinx.util.typing import ExtensionMetadata, OptionSpec
3031

3132

33+
DU_22_PLUS: Final = docutils.__version_info__ >= (0, 22, 0, 'alpha', 0)
3234
glob_re = re.compile(r'.*[*?\[].*')
3335
logger = logging.getLogger(__name__)
3436

@@ -330,6 +332,14 @@ def run(self) -> list[Node]:
330332
surrounding_section_level = memo.section_level
331333
memo.title_styles = []
332334
memo.section_level = 0
335+
if DU_22_PLUS:
336+
# https://github.com/sphinx-doc/sphinx/issues/13539
337+
# https://sourceforge.net/p/docutils/code/10093/
338+
# https://sourceforge.net/p/docutils/patches/213/
339+
surrounding_section_parents = memo.section_parents
340+
memo.section_parents = []
341+
else:
342+
surrounding_section_parents = []
333343
try:
334344
self.state.nested_parse(
335345
self.content, self.content_offset, node, match_titles=True
@@ -365,6 +375,8 @@ def run(self) -> list[Node]:
365375
return []
366376
finally:
367377
memo.title_styles = surrounding_title_styles
378+
if DU_22_PLUS:
379+
memo.section_parents = surrounding_section_parents
368380
memo.section_level = surrounding_section_level
369381

370382

tests/test_directives/test_directive_only.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@
55
import re
66
from typing import TYPE_CHECKING
77

8-
import docutils
98
import pytest
109
from docutils import nodes
1110

1211
if TYPE_CHECKING:
1312
from sphinx.testing.util import SphinxTestApp
1413

15-
xfail_du_22 = pytest.mark.xfail(
16-
docutils.__version_info__ >= (0, 22, 0, 'alpha', 0),
17-
reason='expected failure on Docutils 0.22+',
18-
)
1914

20-
21-
@xfail_du_22
2215
@pytest.mark.sphinx('text', testroot='directive-only')
2316
def test_sectioning(app: SphinxTestApp) -> None:
2417
def getsects(section):

tests/test_environment/test_environment_toctree.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from typing import TYPE_CHECKING
66

7-
import docutils
87
import pytest
98
from docutils import nodes
109
from docutils.nodes import bullet_list, list_item, literal, reference, title
@@ -18,13 +17,7 @@
1817
if TYPE_CHECKING:
1918
from sphinx.testing.util import SphinxTestApp
2019

21-
xfail_du_22 = pytest.mark.xfail(
22-
docutils.__version_info__ >= (0, 22, 0, 'alpha', 0),
23-
reason='expected failure on Docutils 0.22+',
24-
)
2520

26-
27-
@xfail_du_22
2821
@pytest.mark.sphinx('xml', testroot='toctree')
2922
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
3023
def test_process_doc(app):
@@ -471,7 +464,6 @@ def test_domain_objects_document_scoping(app: SphinxTestApp) -> None:
471464
)
472465

473466

474-
@xfail_du_22
475467
@pytest.mark.sphinx('xml', testroot='toctree')
476468
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
477469
def test_document_toc(app):
@@ -529,7 +521,6 @@ def test_document_toc(app):
529521
assert_node(toctree[2][0], [compact_paragraph, reference, 'Indices and tables'])
530522

531523

532-
@xfail_du_22
533524
@pytest.mark.sphinx('xml', testroot='toctree')
534525
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
535526
def test_document_toc_only(app):

0 commit comments

Comments
 (0)