document_site¶
Build a static HTML documentation site from a compiled ODD or Guidelines document.
opm.document_site ¶
Build a static HTML documentation site from a compiled ODD or Guidelines document.
prepare_document_tree turns the
compiled schema into a TEI tree that already holds every page (title page,
chapters, catalogs, reference entries) and the schema-wide content those pages show —
spec relations, A–Z lists, and so on, via
expand_document_tree.
build_document_site then runs
chunk_document three times over that tree, as
configured in resources/document/opm.toml: Guidelines chapters, the home
page (the titlePage), and one HTML page per spec. tagdocs.odd supplies the processing
models that render each chunk.
DocumentSite
dataclass
¶
DocumentSite(
output_dir: Path,
index: SpecIndex,
pages: int,
chapters: int,
unsupported: list[dict] = list(),
warnings: list[str] = list(),
)
Result of build_document_site.
build_document_site ¶
build_document_site(
compiled: CompiledSchema,
output_dir: Path | str,
*,
lang: str = "en",
title: str | None = None,
odd: Path | str | None = None,
on_progress: ProgressFn | None = None,
config_path: Path | str | None = None,
) -> DocumentSite
Write a static HTML site for compiled into output_dir.
config_path is the opm.toml to build with: a documentation project's
(opm init --example odd), or by default the packaged one. It supplies
the ODD, the chunking runs, the page template and the extension modules;
the page assets and nav.xml come from the page template's directory.
Source code in src/opm/document_site.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
prepare_document_tree ¶
prepare_document_tree(
compiled: CompiledSchema,
*,
lang: str = "en",
title: str | None = None,
nav: Path | None = None,
) -> _Element
Return a deep copy of compiled ready for opm chunk / tagdocs.
nav is the sidebar nav.xml to inject; the packaged copy is used when
omitted.
The preparation has three steps:
-
Normalize. Drop Guidelines appendix dumps that our catalog pages replace and give every page node an
xml:id. Specs getref-{ident}sofile_pattern = "{xml_id}.html"matches the URLs tagdocs emits. -
Inject site pages. Chunking selects nodes by XPath, so every page needs a node in the tree. The home page is
front/titlePage, built from theteiHeaderwhen the document has none. A–Z catalogs go intotext/backas appendices. The sidebar list goes intotext/body. -
Expand.
expand_document_treefills in relations, catalog lists, and the other content each page shows.
Source code in src/opm/document_site.py
site_assets_dir ¶
site_assets_dir(
cfg: ProjectConfig, config_file: Path
) -> Path
Where the page assets and nav.xml live: beside the page template.
The first run with a template decides; without one, the directory of config_file.
Source code in src/opm/document_site.py
site_assets ¶
The stylesheets, scripts, fonts and logo every page links from assets/.
Each is taken from site_dir where it has one — a project's own — else
from the packaged resources/document, so a project only keeps the
files it changes. logo is context.logo: a bare filename found in
site_dir is added, since the page template resolves it under assets/.
Source code in src/opm/document_site.py
figure_urls ¶
The relative graphic/@url values tree shows, in document order.
A graphic quoted in an example is markup being explained, not a figure; an absolute URL, or one climbing out of the output, is left as it is.
Source code in src/opm/document_site.py
figure_files ¶
figure_files(
compiled: CompiledSchema, tree: _Element
) -> tuple[dict[str, Path], list[str]]
Map each figure tree shows to its file, and say which were not found.
Figures resolve against the documented source, as they do in its own
repository. For the TEI Guidelines that is the cached p5all.xml, and
their Images/ are fetched beside it the first time a page needs one.
Source code in src/opm/document_site.py
copy_figures ¶
Copy figures under dest, each at the path its URL names.
Source code in src/opm/document_site.py
Expanding the tree¶
Before rendering, everything a page shows that depends on the schema as a
whole is written into the prepared tree as plain TEI: the relations of each
spec, the A–Z catalogs, the table of contents, heading numbers, chapter
navigation and link targets. opm odd document --prepare writes that tree out.
opm.odd_expand ¶
Expand a prepared documentation tree so tagdocs renders it without lookups.
prepare_document_tree ends with
expand_document_tree: everything a
page shows that depends on the schema's graph or on the document as a whole is
computed here, from a SpecIndex, and written into
the tree as plain TEI: contained-by, may-contain, members, used-by and the
attribute tree onto each spec, the A–Z lists into the catalog pages, and a
spec's notes, examples, processing models and content model into sections of
their own.
What a page can read off the document itself stays with tagdocs.odd,
which resolves it while rendering: a division's outline label, the table of
contents, the chapter before and after, how many specs a catalog lists, the
chapters a spec cites, and every link from a name to the spec it names.
What depends on the language is left for the ODD to choose: every
xml:lang variant of a note, an example or a description stays in the tree.
So is what depends on the output format: links are plain pointers to an id
(#ref-p, #COEDADD), which the web and the PDF each resolve their own
way.
expand_document_tree ¶
expand_document_tree(
root: _Element, index: SpecIndex
) -> None
Write everything tagdocs needs into root, so it renders without lookups.
index must be built from root before this runs: the relations are read
from it, never from what this adds. Each spec that has a page (the copy
stamped xml:id="ref-{ident}") gets its relation lists and its sections;
the catalog pages get their A–Z lists; and every gi/ident naming a
spec points at it.
Source code in src/opm/odd_expand.py
tp: function¶
The one spec-specific function tagdocs.odd still calls; it formats the node
being rendered.
opm.runtime.spec_xpath_functions ¶
The one tp: function tagdocs needs beyond the generic ones.
Everything else a documentation page shows is written into the tree before
rendering, by opm.odd_expand; what remains is formatting
the node being rendered.
serialize_spec ¶
Pretty-print a spec subtree (content model, Schematron, pb:template)
without a default TEI xmlns declaration.
with_tail=False so mixed-content examples (element + following text)
stay well-formed; tails are handled by
serialize_egxml.