Skip to content

Commit 6e9477c

Browse files
committed
Add support for sphinx dirhtml builder
1 parent 47d3293 commit 6e9477c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/sphinx_codeautolink/extension/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self) -> None:
8989
@print_exceptions()
9090
def build_inited(self, app) -> None:
9191
"""Handle initial setup."""
92-
if app.builder.name != "html":
92+
if app.builder.name not in ("html", "dirhtml"):
9393
self.do_nothing = True
9494
return
9595

@@ -289,6 +289,7 @@ def apply_links(self, app, exception) -> None:
289289
self.inventory,
290290
self.custom_blocks,
291291
self.search_css_classes,
292+
builder_name=app.builder.name,
292293
)
293294

294295
self.cache.write()

src/sphinx_codeautolink/extension/block.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,14 @@ def link_html(
375375
inventory: dict,
376376
custom_blocks: dict,
377377
search_css_classes: list,
378+
builder_name: str = "html",
378379
) -> None:
379380
"""Inject links to code blocks on disk."""
380-
html_file = Path(out_dir) / (document + ".html")
381+
if builder_name == "dirhtml" and Path(document).name != "index":
382+
html_file = Path(out_dir) / document / "index.html"
383+
else:
384+
html_file = Path(out_dir) / (document + ".html")
385+
381386
text = html_file.read_text("utf-8")
382387
soup = BeautifulSoup(text, "html.parser")
383388

0 commit comments

Comments
 (0)