config¶
Loading and representation of opm.toml. See the
Configuration guide for the TOML schema.
opm.config ¶
Project-level configuration loaded from opm.toml.
All relative paths in the config (templates, CSS, documents, ODDs,
pythonpath) are resolved relative to the directory containing the
config file, so opm commands work regardless of the current working
directory.
DEFAULT_WEBCOMPONENTS_URL
module-attribute
¶
DEFAULT_WEBCOMPONENTS_URL = "https://cdn.jsdelivr.net/npm/@teipublisher/pb-components@3.6.8/dist/pb-components-bundle.js"
Bundle loaded when web-component mode is on and the project names no URL.
Pinned here so the version is bumped in one place rather than in every
project; override it per project with [transform.web.context]
webcomponents_url.
FragmentConfig
dataclass
¶
FragmentConfig(
name: str,
scope: str,
xpath: str,
xpath_dynamic: str | None = None,
parameters: dict[str, Any] | None = None,
module: Path | None = None,
odd: Path | None = None,
mode: str = "web",
)
xpath_dynamic
class-attribute
instance-attribute
¶
The xpath the consuming pb-view sends, when it differs from xpath.
Used only to build --format pb-view index keys. See
ChunkingConfig.xpath_dynamic.
module
class-attribute
instance-attribute
¶
Resolved compiled transform path (set after compile-on-demand, not from TOML).
odd
class-attribute
instance-attribute
¶
ODD to compile on demand for this fragment.
mode
class-attribute
instance-attribute
¶
Output channel used when compiling odd (default: web).
ChunkingConfig
dataclass
¶
ChunkingConfig(
xpath: str | None = None,
name: str | None = None,
xpath_dynamic: str | None = None,
selector: str | None = None,
depth: int = 1,
output_dir: str = "chunks",
template: Path | None = None,
index_template: Path | None = None,
index_title: str | None = None,
assets: tuple[Path, ...] = (),
fragments: list[FragmentConfig] | None = None,
file_pattern: str | None = None,
document_name: str | None = None,
link_pattern: str | None = None,
link_doc: str | None = None,
module: Path | None = None,
odd: Path | None = None,
view: str = "div",
map: str | None = None,
parameters: dict[str, Any] | None = None,
doc_path: str | None = None,
)
The [chunking] section: how opm chunk splits a document into pages.
Relative paths are resolved against the config file's directory, except
output_dir, which is relative to the project root.
One [chunking] table is one run. A [[chunking]] array declares
several, executed in order over each document into one output directory
(see ProjectConfig.chunking_runs).
name
class-attribute
instance-attribute
¶
Optional label of a run, for [[chunking]] arrays: tags the run's
entries in manifest.json and names it in progress and error messages.
xpath_dynamic
class-attribute
instance-attribute
¶
The xpath the consuming pb-view sends, when it differs from xpath.
--format pb-view writes an index.json whose keys mirror
createKey() in pb-view.js, and pb-view looks itself up by the
literal value of its own xpath attribute. That attribute names the
region a view displays (//text[@type = 'source']), while xpath here
selects chunk roots (.//text[@type='source']/div) — different
expressions that are nonetheless compared as exact strings, so the lookup
misses and pb-view requests a URL ending in undefined. Set this to the
attribute's exact value to register the key pb-view will ask for. Only the
index key changes; chunk selection still uses xpath.
index_template
class-attribute
instance-attribute
¶
Optional Jinja2 template for the collection index written when chunking a directory.
Rendered to <output_dir>/index.html so opm serve shows a real
landing page instead of the bare directory listing. When None the
packaged default_index.html.j2 is used.
index_title
class-attribute
instance-attribute
¶
Heading for the generated collection index (default: the output directory name).
assets
class-attribute
instance-attribute
¶
Files or directories copied into <output-root>/assets/.
Inherited from [transform.web] assets (see
web_assets) when the run sets
none; assets = [] opts a run out.
An entry may be a glob: iiif/* copies every directory under iiif/,
so a project that adds a document does not have to add a line here.
Chunk output directories are wiped on every rebuild, so anything a template
references — a stylesheet, an image, a font — has to be placed there by the
build. Templates receive assets as a relative URL prefix
(assets from the index, ../assets from a chunk page), and a
stylesheet copied here can reference a sibling asset by plain filename,
since its URLs resolve against its own location rather than the page's.
file_pattern
class-attribute
instance-attribute
¶
Optional filename template for chunk pages.
Placeholders
{xml_id} – the chunk root's xml:id (or @id)
{ident} – @ident (ODD specs), falling back to {xml_id}
{index} – 1-based chunk index ({index:03d} zero-pads)
{stem} – {xml_id} or {ident}, whichever is set
When None (default) files are 001.html, 002.html, … as before.
A chunk that has neither xml:id nor @ident still uses the numbered
form, even when this pattern is set.
document_name
class-attribute
instance-attribute
¶
XPath that names the per-document output directory.
By default that directory is the source file name (K_0096.xml/). Set
this to derive a different name from the document instead, so URLs and the
template variables document / documents use an identifier from the
XML rather than the file name:
document_name = "/TEI/@xml:id" # → K_0096/
document_name = "'B' || substring-after(/TEI/@xml:id, 'K_')" # → B0096/
The expression is evaluated on the document root, in the project's XPath
environment. An empty result, or a name already used by another document
in the run, is an error. With several [[chunking]] runs, only the
first may set this; later runs share that directory. Ignored for
--format pb-view, which addresses documents by file path.
link_pattern
class-attribute
instance-attribute
¶
Optional URL template for cross-chunk links.
Placeholders
{file} – full filename, e.g. 002.html
{stem} – stem without extension, e.g. 002
{anchor} – the fragment identifier, e.g. Pers
{doc} – the document's own subdirectory, e.g. quickstart.xml
(empty only when chunking with no link_doc)
When None (default) the rewriter falls back to the relative form
{file}#{anchor}. Example values:
link_doc
class-attribute
instance-attribute
¶
Document path segment for {doc} in link_pattern (not from TOML).
Set by the CLI when chunking a directory of XML files into per-document
output subdirectories (e.g. quickstart.xml).
module
class-attribute
instance-attribute
¶
Resolved compiled transform path (set after compile-on-demand, not from TOML).
odd
class-attribute
instance-attribute
¶
ODD to compile on demand for chunking.
view
class-attribute
instance-attribute
¶
View mode (div, page or single) used in pb-view lookup keys.
map
class-attribute
instance-attribute
¶
Optional map parameter included in pb-view lookup keys.
parameters
class-attribute
instance-attribute
¶
Optional user parameters for pb-view lookup keys.
Each entry is emitted as user.<key>=<value> and must match the
pb-param children declared on the consuming pb-view.
doc_path
class-attribute
instance-attribute
¶
Document path subdirectory for --format pb-view output.
pb-view resolves static data as ${static}/${path}/...; the data is
written to <output_dir>/<doc_path>/ (CSS stays shared at
<output_dir>/css/). Must match the path of the consuming
pb-document. When unset the data is written directly into output_dir.
DocumentConfig
dataclass
¶
The [document] table: this project is an opm odd document site.
opm init --example odd writes it. Run inside such a project,
opm odd document builds with the project's ODD, runs, template, page
assets and extension modules instead of the packaged ones, and takes what
to document from here unless the command line says otherwise.
CollectionConfig
dataclass
¶
One fn:collection URI and the documents it contains.
uri is matched against the argument of collection() after elementpath
resolves it (get_absolute_uri). A URI with a scheme, or an absolute path
such as /db/apps/serafin/data/registers, is passed through verbatim, so
the same string an eXist $config:register-root holds can be used here and
will match from any source document. A relative URI would instead resolve
against each document's own base URI, so it is rejected.
ProjectConfig
dataclass
¶
ProjectConfig(
webcomponents_enabled: bool | None = None,
template_context: dict[str, Any] = dict(),
template_context_by_type: dict[
str, dict[str, Any]
] = dict(),
document_template: Path | None = None,
web_pages: str | None = None,
web_assets: tuple[Path, ...] = (),
document_css: Path | None = None,
document_docx_template: Path | None = None,
typst_template: Path | None = None,
print_template: Path | None = None,
epub_css: Path | None = None,
epub_skip_title: bool = False,
epub_chunk_overrides: dict[str, Any] = dict(),
xpath_extensions: tuple[str, ...] = (),
footnote_order: str | None = None,
xpath_documents: tuple[Path, ...] = (),
xpath_collections: tuple[CollectionConfig, ...] = (),
xpath_variables: dict[str, Any] = dict(),
xpath_namespaces: dict[str, str] = dict(),
parameters: dict[str, str] = dict(),
chunking: ChunkingConfig | None = None,
chunking_runs: tuple[ChunkingConfig, ...] = (),
document: DocumentConfig | None = None,
index_max_chars: int = 1500,
index_min_chars: int = 40,
index_overlap: int = 1,
index_fields: tuple = (),
index_units: tuple = (),
pythonpath: tuple[Path, ...] = (),
transform_odd: Path | None = None,
transform_odds: dict[str, Path] = dict(),
)
The settings in opm.toml, as load_project_config reads them.
Every field has a default, so ProjectConfig() is a project with no
config file. Paths are already resolved against the config file's
directory. To run anything with these settings, pass them to
opm.project.Project.
webcomponents_enabled
class-attribute
instance-attribute
¶
Web-component mode, from [transform.web] webcomponents.
None means the project said nothing, leaving --webcomponents /
--no-webcomponents to decide. The bundle URL is not configured here:
it is an ordinary template value, webcomponents_url, defaulted by
context_for and overridable in
[transform.web.context].
template_context
class-attribute
instance-attribute
¶
Arbitrary values exposed to every Jinja2 template as context ([context]).
Unlike parameters, which is bound to XPath $parameters and so
must be a flat map of strings, this keeps TOML types intact — booleans,
numbers, arrays and nested tables all survive — because nothing but the
template ever reads it. It is how a project drives its own template
without a code change.
template_context_by_type
class-attribute
instance-attribute
¶
Per-output-type context overlays from [transform.<type>.context].
Merged over template_context by context_for, so a value the
web template needs never leaks into the Typst one.
document_template
class-attribute
instance-attribute
¶
Jinja2 HTML shell for web output from [transform.web] template.
Chunking runs without a template of their own use it too.
web_pages
class-attribute
instance-attribute
¶
Dotted path of a page splitter, from [transform.web] pages.
When set, opm transform renders the document as a sequence of pages,
each in its own <section class="opm-page">, instead of one flow. It
takes the same functions as [chunking] selector, e.g.
tei_pb_chunks.
web_assets
class-attribute
instance-attribute
¶
Files the web template references, from [transform.web] assets.
opm transform copies them into an assets/ directory beside its
output and opm chunk into <output-root>/assets/; either way the
template receives the stylesheets among them as asset_styles. A
chunking run with its own assets uses those instead.
document_css
class-attribute
instance-attribute
¶
Base rules compiled into the ODD stylesheet, from [transform] css.
Replaces the packaged defaults for every output type.
print_template
class-attribute
instance-attribute
¶
Jinja2 HTML shell for -t print from [transform.print] template.
Print does not fall back to document_template — web shells usually
include nav and web components that do not belong on a paged-media page.
When unset, the packaged default_print.html.j2 is used.
epub_css
class-attribute
instance-attribute
¶
Stylesheet appended to the EPUB package from [transform.epub] css.
Cascades last — after the packaged EPUB baseline and the ODD's own CSS — so it can restyle rules the reading view brought along.
epub_skip_title
class-attribute
instance-attribute
¶
When true, omit the generated EPUB title page ([transform.epub] skip_title).
epub_chunk_overrides
class-attribute
instance-attribute
¶
xpath / selector / depth from [transform.epub].
What belongs in the book is not always what the reading view pages through.
A parallel-text edition shows the translation in a second panel and chunks
only the source; an EPUB has no second panel, so selecting the same chunks
would drop half the document. Empty means "use [chunking] unchanged".
footnote_order
class-attribute
instance-attribute
¶
Dotted path of the callable that orders a run's footnotes ([transform] footnote_order).
Resolved by load_callable and set on
RenderContext.footnote_order.
opm.runtime.footnote_order ships the common
orderings. Only the output modes with
collects_footnotes place
footnotes themselves, so it has no effect on the others.
xpath_collections
class-attribute
instance-attribute
¶
xpath_collections: tuple[CollectionConfig, ...] = ()
Collections addressable from XPath via fn:collection ([[transform.collections]]).
xpath_variables
class-attribute
instance-attribute
¶
XPath variables in Clark notation ({ns}local).
From [transform.variables.<prefix>], where prefix is one declared in
[transform.namespaces]; a namespace URI may be used as the key instead.
Scalars directly under [transform.variables] are in no namespace.
xpath_namespaces
class-attribute
instance-attribute
¶
Prefix -> namespace URI for XPath in the ODD ([transform.namespaces]).
Merged over the ODD root's own declarations, so a project can bind prefixes the ODD never declares — variables in particular, whose prefix is meaningful only to XPath and has no XML meaning inside an attribute value.
parameters
class-attribute
instance-attribute
¶
User parameters bound to XPath $parameters (from [transform.parameters]).
chunking
class-attribute
instance-attribute
¶
chunking: ChunkingConfig | None = None
The first chunking run — for a [chunking] table, the only one.
Kept as a single config so code written before [[chunking]] arrays sees
exactly what it saw then. Code that chunks should use
chunking_runs.
chunking_runs
class-attribute
instance-attribute
¶
chunking_runs: tuple[ChunkingConfig, ...] = ()
Every chunking run, in order: one per [[chunking]] entry, or the
single [chunking] table. Later runs are handed the anchors of earlier
ones, so links between their pages resolve.
document
class-attribute
instance-attribute
¶
document: DocumentConfig | None = None
[document]: set when the project is an opm odd document site.
index_max_chars
class-attribute
instance-attribute
¶
[index] max_chars — split a section longer than this for opm index.
index_min_chars
class-attribute
instance-attribute
¶
[index] min_chars — drop units shorter than this; bare headings are noise.
index_overlap
class-attribute
instance-attribute
¶
[index] overlap — records of context carried into the next part on a split.
index_fields
class-attribute
instance-attribute
¶
[[index.fields]] — opm.indexing.FieldSpecs from a passage or a chunking fragment.
index_units
class-attribute
instance-attribute
¶
[[index.units]] — opm.indexing.UnitSpecs that open a passage.
transform_odd
class-attribute
instance-attribute
¶
Default transform ODD from [transform].odd or [transform.web].odd.
transform_odds
class-attribute
instance-attribute
¶
Map of transform type → ODD path (compiled on demand).
Per-type [transform.<type>].odd entries override [transform].odd.
epub_chunking
property
¶
epub_chunking: ChunkingConfig | None
Chunking config the EPUB packager selects chapters with.
With a [[chunking]] array, the first run: a book has one reading
order, and further runs (reference pages, registers) are a website's
concern rather than chapters.
extend_sys_path ¶
Put the [project] pythonpath directories on sys.path.
Project modules named in the config (XPath extensions, chunk
selectors) import from there. Each entry goes to the front, as
PYTHONPATH would put it; entries already present are left alone,
so calling this again is harmless.
Source code in src/opm/config.py
context_for ¶
Return the template context for transform_type.
[context] supplies the base; [transform.<type>.context] is
merged over it with merge_deep:
tables combine key by key, lists are joined. When webcomponents is on, webcomponents_url falls back to
DEFAULT_WEBCOMPONENTS_URL —
unless the project set that key itself, which then wins.
Whether the mode is on is a parameter rather than a config lookup
because only the caller knows the effective mode for a run:
--webcomponents overrides the config and the json/pb-view
formats force it on.
Source code in src/opm/config.py
odd_for_type ¶
Return the ODD for transform_type.
Precedence: [transform.<type>].odd → [transform].odd → None.
The JSON channels (json-typst, …) read [transform.json].
Source code in src/opm/config.py
resolve_base_css ¶
Return the base stylesheet compiled into the ODD's generated CSS.
[transform] css / --css replaces the packaged default wholesale — it
is an override for the rules the runtime's markup needs, not an extra layer.
Project design CSS belongs in [transform.web] assets instead, where it can
sit beside the images and fonts it references.
Source code in src/opm/config.py
load_project_config ¶
load_project_config(
path: Path | None = None,
) -> ProjectConfig
Load opm.toml from path or CWD; return defaults if absent.
Source code in src/opm/config.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |