precedent: Resolve Markdown style from bounded source facts#
Editor callers scan the current root list, then supply a cached document snapshot. Formatter callers collect the same facts from their parse. Neither caller owns the priority of root, document, declaration, and built-in defaults.
Resolve Markdown style from bounded source facts.
Editor callers scan the current root list, then supply a cached document snapshot. Formatter callers collect the same facts from their parse. Neither caller owns the priority of root, document, declaration, and built-in defaults.
- class myform.precedent.ListItem(depth: int, mark: str, number: str | None = None, loose_before: bool | None = None, indent_step: int | None = None)#
One real marker, in source order, with observations relative to its list.
- class myform.precedent.ListTraits(bullet: str | None = None, delimiter: str | None = None, loose: bool | None = None, indent_step: int | None = None, numbering: Numbering | None = None)#
Partial observations at one depth, with None for each unobserved trait.
- class myform.precedent.Precedent(depths: tuple[ListTraits, ...] = (), emphasis: str | None = None, strong: str | None = None, fallback: ListTraits = ListTraits(bullet=None, delimiter=None, loose=None, indent_step=None, numbering=None), checked_box: '[x]' | '[X]' | None = None, note_home: str | None = None, note_labels: str | None = None)#
An immutable snapshot of observed or declared style.
- at(depth: int) ListTraits#
Return observations at a zero-based depth.
- class myform.precedent.ListStyle(bullet: str = '-', delimiter: str = '.', loose: bool = False, indent_step: int | None = None)#
Resolved style at a single depth.
- myform.precedent.scan_list(items: Iterable[ListItem]) Precedent#
Read the first observation of each trait independently at each depth.
- myform.precedent.resolve_list(depth: int, *, root: Precedent, document: Precedent | None = None, declared: Precedent | None = None) ListStyle#
Resolve per-depth list traits with the local list first.
- myform.precedent.infer_numbering(numbers: Sequence[str]) Numbering | None#
Read the first two numbers or report that there is no complete observation.
Preserve existing labels when the first two establish neither a repeated nor consecutive pattern. Some documents use the labels as identifiers.
- myform.precedent.resolve_numbering(numbers: Sequence[str], *, document: Numbering | None = None, declared: Numbering | None = None) Numbering#
Resolve the pattern for one ordered list.
- myform.precedent.merge_precedent(first: Precedent, second: Precedent) Precedent#
Fill missing observations from a lower-priority source.
- myform.precedent.declared_precedent(value: object) Precedent#
Read style traits from a front matter or project configuration mapping.
Scalar list traits apply at every depth. The optional
depthsmapping overrides individual traits at its zero-based depths.
- myform.precedent.infer_table_padding(rows: Sequence[Sequence[str]]) TablePadding#
Infer table padding from raw cells, with the separator row at index one.
Extra edge padding, a wide separator, or alignment colons that occupy part of a three-column separator establish aligned padding.
- myform.precedent.load_format_options(path: Path | None = None, *, options: Mapping[str, Any] | None = None) dict[str, Any]#
Resolve the MyST formatter settings for an editor’s cached context.
A file or project directory uses the formatter’s configuration discovery. Without a path, use the built-in defaults and explicit options supplied here. Refresh this snapshot when the source path or its configuration changes.
- myform.precedent.scan_markdown(text: str, *, path: Path | None = None, declared: Precedent | None = None, options: Mapping[str, Any] | None = None) Precedent#
Collect file style for a background cache without opening a conversion Session.
Use a resolved formatter options snapshot when one is cached, or pass the document path for project discovery. Front matter fills style before the project declaration.
- myform.precedent.conform_list(text: str, *, document: Precedent | None = None, declared: Precedent | None = None, options: Mapping[str, Any] | None = None, path: Path | None = None) str#
Format an isolated root list with the same rules as a document save.
A blockquote containing only a root list is also a valid window. Inputs containing other blocks are returned verbatim. The options snapshot returned by
load_format_optionstakes precedence over path discovery. This command parses its window and never opens a Session.