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,
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,
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.
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/.
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.
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.
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,
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, ...] = (),
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,
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.
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".
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]).
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.
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] overlays
it. 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 [chunking] 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
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 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 | |