"
+ def footnote_anchor(self, token: Token, tokens: Sequence[Token], i: int) -> str:
+ href = self._xref_targets[token.meta['target']].href()
+ return (
+ f''
+ f'[{token.meta["id"] + 1}]'
+ ''
+ )
def _make_hN(self, level: int) -> tuple[str, str]:
return f"h{min(6, max(1, level + self._hlevel_offset))}", ""
diff --git a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py
index ef81e4d7e1ab8..03c5a5dd39604 100644
--- a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py
+++ b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py
@@ -1,4 +1,5 @@
import argparse
+import hashlib
import html
import json
import re
@@ -235,27 +236,48 @@ class HTMLParameters(NamedTuple):
generator: str
stylesheets: Sequence[str]
scripts: Sequence[str]
+ # number of levels in the rendered table of contents. tables are prepended to
+ # the content they apply to (entire document / document chunk / top-level section
+ # of a chapter), setting a depth of 0 omits the respective table.
toc_depth: int
chunk_toc_depth: int
+ section_toc_depth: int
+ media_dir: Path
class ManualHTMLRenderer(RendererMixin, HTMLRenderer):
_base_path: Path
+ _in_dir: Path
_html_params: HTMLParameters
def __init__(self, toplevel_tag: str, revision: str, html_params: HTMLParameters,
manpage_urls: Mapping[str, str], xref_targets: dict[str, XrefTarget],
- base_path: Path):
+ in_dir: Path, base_path: Path):
super().__init__(toplevel_tag, revision, manpage_urls, xref_targets)
- self._base_path, self._html_params = base_path, html_params
+ self._in_dir = in_dir
+ self._base_path = base_path.absolute()
+ self._html_params = html_params
+
+ def _pull_image(self, src: str) -> str:
+ src_path = Path(src)
+ content = (self._in_dir / src_path).read_bytes()
+ # images may be used more than once, but we want to store them only once and
+ # in an easily accessible (ie, not input-file-path-dependent) location without
+ # having to maintain a mapping structure. hashing the file and using the hash
+ # as both the path of the final image provides both.
+ content_hash = hashlib.sha3_256(content).hexdigest()
+ target_name = f"{content_hash}{src_path.suffix}"
+ target_path = self._base_path / self._html_params.media_dir / target_name
+ target_path.write_bytes(content)
+ return f"./{self._html_params.media_dir}/{target_name}"
def _push(self, tag: str, hlevel_offset: int) -> Any:
- result = (self._toplevel_tag, self._headings, self._attrspans, self._hlevel_offset)
+ result = (self._toplevel_tag, self._headings, self._attrspans, self._hlevel_offset, self._in_dir)
self._hlevel_offset += hlevel_offset
self._toplevel_tag, self._headings, self._attrspans = tag, [], []
return result
def _pop(self, state: Any) -> None:
- (self._toplevel_tag, self._headings, self._attrspans, self._hlevel_offset) = state
+ (self._toplevel_tag, self._headings, self._attrspans, self._hlevel_offset, self._in_dir) = state
def _render_book(self, tokens: Sequence[Token]) -> str:
assert tokens[4].children
@@ -284,6 +306,7 @@ def _render_book(self, tokens: Sequence[Token]) -> str:
def _file_header(self, toc: TocEntry) -> str:
prev_link, up_link, next_link = "", "", ""
prev_a, next_a, parent_title = "", "", " "
+ nav_html = ""
home = toc.root
if toc.prev:
prev_link = f''
@@ -299,6 +322,22 @@ def _file_header(self, toc: TocEntry) -> str:
if toc.next:
next_link = f''
next_a = f'Next'
+ if toc.prev or toc.parent or toc.next:
+ nav_html = "\n".join([
+ '
',
+ '
',
+ '
',
+ f'
{toc.target.title}
',
+ '
',
+ '
',
+ f'
{prev_a}
',
+ f'
{parent_title}
',
+ f'
{next_a}
',
+ '
',
+ '
',
+ ' ',
+ '
',
+ ])
return "\n".join([
'',
''
for script in self._html_params.scripts)),
f' ',
- f' ',
+ f' ' if home.target.href() else "",
f' {up_link}{prev_link}{next_link}',
' ',
' ',
- '