Skip to content

Commit 6781777

Browse files
authored
Merge pull request #311 from has2k1/more-extendable-quartodoc
More extendable quartodoc
2 parents e7eb12d + e50d3de commit 6781777

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

quartodoc/autosummary.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from .renderers import Renderer
2323
from .validation import fmt_all
2424
from ._pydantic_compat import ValidationError
25+
from .pandoc.blocks import Blocks, Header
26+
from .pandoc.components import Attr
2527

2628

2729
from typing import Any
@@ -463,6 +465,8 @@ class Builder:
463465
title: str
464466

465467
renderer: Renderer
468+
items: list[layout.Item]
469+
"""Documented items by this builder"""
466470

467471
def __init_subclass__(cls, **kwargs):
468472
super().__init_subclass__(**kwargs)
@@ -553,7 +557,7 @@ def build(self, filter: str = "*"):
553557
blueprint = blueprint(self.layout, dynamic=self.dynamic, parser=self.parser)
554558

555559
_log.info("Collecting pages and inventory items.")
556-
pages, items = collect(blueprint, base_dir=self.dir)
560+
pages, self.items = collect(blueprint, base_dir=self.dir)
557561

558562
# writing pages ----
559563

@@ -562,11 +566,12 @@ def build(self, filter: str = "*"):
562566

563567
_log.info("Writing docs pages")
564568
self.write_doc_pages(pages, filter)
569+
self.renderer._pages_written(self)
565570

566571
# inventory ----
567572

568573
_log.info("Creating inventory file")
569-
inv = self.create_inventory(items)
574+
inv = self.create_inventory(self.items)
570575
if self._fast_inventory:
571576
# dump the inventory file directly as text
572577
# TODO: copied from __main__.py, should add to inventory.py
@@ -591,7 +596,9 @@ def write_index(self, blueprint: layout.Layout):
591596
content = self.renderer.summarize(blueprint)
592597
_log.info(f"Writing index to directory: {self.dir}")
593598

594-
final = f"# {self.title}\n\n{content}"
599+
final = str(
600+
Blocks([Header(1, self.title, Attr(classes=["doc", "doc-index"])), content])
601+
)
595602

596603
p_index = Path(self.dir) / self.out_index
597604
p_index.parent.mkdir(exist_ok=True, parents=True)

quartodoc/renderers/base.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import re
2+
import typing
23

34
from plum import dispatch
45

6+
if typing.TYPE_CHECKING:
7+
from ..autosummary import Builder
58

69
# utils -----------------------------------------------------------------------
710

@@ -81,3 +84,23 @@ def from_config(cls, cfg: "dict | Renderer | str"):
8184
@dispatch
8285
def render(self, el):
8386
raise NotImplementedError(f"render method does not support type: {type(el)}")
87+
88+
def _pages_written(self, builder: "Builder"):
89+
"""
90+
Called after all the qmd pages have been render and written to disk
91+
92+
It is called before the documented items are written to an inventory
93+
file. This is a chance for the renderer to add to the documented items
94+
and write the pages to them to disk.
95+
96+
Parameters
97+
----------
98+
builder :
99+
There builder using this renderer to generate documentation.
100+
101+
Notes
102+
-----
103+
This method is provided for experimental purposes and it is not bound
104+
to be available for long, or have the same form.
105+
"""
106+
...

0 commit comments

Comments
 (0)