Skip to content

Commit e3b8c1c

Browse files
committed
🐛 FIX: gettext builder compatibility
1 parent 38672bf commit e3b8c1c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

sphinx_external_toc/events.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ class TableofContents(SphinxDirective):
153153
# TODO allow for name option of tableofcontents (to reference it)
154154
def run(self) -> List[TableOfContentsNode]:
155155
"""Insert a ``TableOfContentsNode`` node."""
156-
return [TableOfContentsNode()]
156+
node = TableOfContentsNode()
157+
self.set_source_info(node)
158+
return [node]
157159

158160

159161
def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None:
@@ -220,7 +222,8 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None:
220222

221223
subnode = toctree_node()
222224
subnode["parent"] = app.env.docname
223-
subnode.source = doctree.source
225+
subnode.source = doctree["source"]
226+
subnode.line = 1
224227
subnode["entries"] = []
225228
subnode["includefiles"] = []
226229
subnode["maxdepth"] = toctree.maxdepth

tests/test_sphinx.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ def test_success(path: Path, tmp_path: Path, sphinx_build_factory, file_regressi
8181
file_regression.check(doctree.pformat(), extension=".xml", encoding="utf8")
8282

8383

84+
def test_gettext(tmp_path: Path, sphinx_build_factory):
85+
"""Test the gettext builder runs correctly."""
86+
src_dir = tmp_path / "srcdir"
87+
# write document files
88+
toc_path = Path(__file__).parent.joinpath("_toc_files", "basic.yml")
89+
create_site_from_toc(toc_path, root_path=src_dir, toc_name=None)
90+
# write conf.py
91+
content = f"""
92+
extensions = ["sphinx_external_toc"]
93+
external_toc_path = {Path(os.path.abspath(toc_path)).as_posix()!r}
94+
95+
"""
96+
src_dir.joinpath("conf.py").write_text(content, encoding="utf8")
97+
# run sphinx
98+
builder = sphinx_build_factory(src_dir, buildername="gettext")
99+
builder.build()
100+
101+
84102
@pytest.mark.parametrize(
85103
"path", TOC_FILES_WARN, ids=[path.name.rsplit(".", 1)[0] for path in TOC_FILES_WARN]
86104
)

0 commit comments

Comments
 (0)