Metadata-Version: 2.4
Name: myform
Version: 2.2.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: POSIX :: Linux
Classifier: Framework :: Pytest
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup :: Markdown
Classifier: Typing :: Typed
Requires-Dist: mdformat>=1.0,<2
Requires-Dist: mdformat-deflist>=0.1.4
Requires-Dist: mdformat-footnote>=0.1.3
Requires-Dist: mdformat-front-matters>=2.0.0
Requires-Dist: mdformat-gfm>=1.0.0
Requires-Dist: mdit-py-plugins>=0.5.0
Requires-Dist: more-itertools>=10.7.0
Requires-Dist: my-basis>=1.3.0
Requires-Dist: pydantic>=2.11.7
Requires-Dist: regex>=2024.4.28
Requires-Dist: srsly>=2.5.3
Requires-Dist: wcwidth>=0.2.13
Requires-Dist: wikiparse>=1.0.2,<2 ; extra == 'wikitext'
Provides-Extra: wikitext
License-File: LICENSE
Summary: A typed translator that reads and writes MyST, GFM, Sphinx rST, and Typst.
Author-email: Robb Doering <robb@doering.ai>
License-Expression: MPL-2.0
Requires-Python: >=3.13
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://myform.docs.doering.ai/
Project-URL: Homepage, https://gitlab.com/doering-ai/libs/myform
Project-URL: Issues, https://gitlab.com/doering-ai/libs/myform/-/issues
Project-URL: Repository, https://gitlab.com/doering-ai/libs/myform

# myform

![logo](assets/logo_512.png)

> Released versions are available from PyPI.
> This checkout may contain unreleased changes.

[![Pipeline Status](https://img.shields.io/gitlab/pipeline-status/doering-ai/libs/myform?branch=main)](https://gitlab.com/doering-ai/libs/myform/-/pipelines?ref=main) [![Test Coverage](https://img.shields.io/gitlab/pipeline-coverage/doering-ai/libs/myform?branch=main)](https://gitlab.com/doering-ai/libs/myform/-/graphs/main/charts) [![License](https://img.shields.io/gitlab/license/doering-ai/libs/myform)](LICENSE) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) [![pyrefly](https://img.shields.io/endpoint?url=https://pyrefly.org/badge.json)](https://github.com/facebook/pyrefly) [![ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

`myform` is a universal docs-format translator built around one absolute, typed document tree.
It reads MyST Markdown, GitHub Flavored Markdown (GFM), Obsidian-Flavored Markdown, Sphinx reStructuredText, and Typst, then writes idiomatic MyST, GFM, Obsidian, Sphinx reStructuredText, Typst, or a bounded MediaWiki wikitext subset.
Formatting is the identity case: `myform.convert(text, format, format)` runs through the same reader, typed tree, and writer as a cross-format conversion.

| Format                     | Read | Write |
| :------------------------- | :--: | :---: |
| MyST Markdown              | Yes  |  Yes  |
| GFM                        | Yes  |  Yes  |
| Obsidian-Flavored Markdown | Yes  |  Yes  |
| Sphinx reStructuredText    | Yes  |  Yes  |
| Typst                      | Yes  |  Yes  |
| MediaWiki wikitext         | Yes  |  Yes  |

The two Markdown identity conversions remain the compatibility rail.
They produce byte-for-byte the same text as the existing mdformat pipelines, including the MyST opinions developed in this repository.

A sixth registered dialect, `plane` (`myform.convert(text, src, 'plane')`), is a different kind of target: it emits and reads Plane's stored `description_html` -- an empirically reverse-engineered ProseMirror/Tiptap-schema HTML subset -- for exact wire fidelity to one vendor's storage, not idiomatic semantic HTML.
It is intentionally absent from the table above.

**Documentation:** [myform.docs.doering.ai](https://myform.docs.doering.ai/)

## Install

Install the public release from PyPI:

```sh
pip install myform
```

To develop from the checked-out source with `uv`:

```sh
uv sync --all-extras
uv run myform --help
```

`myform 1.0.0` includes the native Typst reader, so Typst reads as well as writes.
That reader is backed by the `_typst_native` ABI3 extension over `typst-syntax`, and its source builds require Rust 1.92. The release pipeline intentionally produces one audited `cp313-abi3-manylinux_2_28_x86_64` wheel; macOS, Windows, non-x86_64 Linux, and older-glibc Linux systems must build from source until a verified wheel matrix is added.
`import myform` itself remains pure Python and loads the extension only when a Typst document is parsed.

## Translate documents

```sh
uv run myform convert guide.md --from myst --to rst -o guide.rst
printf '# Hello\n' | uv run myform convert - --from gfm --to typst
uv run myform convert guide.md --from myst --to gfm --report json >guide.gfm
uv run myform convert guide.md --from myst --to wikitext -o guide.wiki
```

Use `-` as the input path to read stdin.
Output goes to stdout unless `-o/--output` names a file.
Conversion reports always go to stderr, keeping document output safe for pipelines.
Choose `--report summary` (the default), `--report json`, or `--report none`.

## Format documents

The `format` verb performs an identity conversion:

```sh
uv run myform format README.md
uv run myform format README.md --format myst -o README.formatted.md
```

The CLI and Python calls with `target_path` share the Markdown engine and nearest-file `.mdformat.toml` discovery: `number`, `wrap`, `end_of_line`, and `[plugin.*]` apply, and excluded Markdown paths pass through unchanged.
Myform configuration selects the typed pipeline and overrides explicitly configured MyST options.
Explicit API options and CLI flags take precedence.
String-only Python calls keep their supplied options and myform configuration; pass the document path to share an editor or CLI configuration.
Optional shared defaults live at `$XDG_CONFIG_HOME/myform/.mdformat.toml` (normally `~/.config/myform/.mdformat.toml`).
The nearest local `.mdformat.toml` overrides shared behavior by key and plugin option.
Exclusions from both remain active.
An inherited `number = true` is a shared default, so Markdown list precedent still decides unless the project or caller requests numbered output explicitly.

Several files go through one process with one of three modes.
Each takes files only (never `-o` or stdin), attempts every file even after a failure, and lets the first failure set the exit code:

```sh
uv run myform format --in-place docs/*.md   # rewrite each file whose text changed
uv run myform format --check docs/*.md      # name each file that would change; write nothing
uv run myform format --jsonl docs/*.md      # print each file's formatted text or error; write nothing
```

`--in-place` writes each file atomically: the new text goes to a temporary file beside it, with the file's mode, and is renamed over it, so a reader or a crash sees the old file or the new one.
Just before the rename it reads the file again and refuses when the file no longer holds the text it formatted, so an edit made meanwhile is never overwritten (exit 5, the other files carry on).
A file whose text did not change is left untouched, and a file you cannot write is refused.
A symlink is followed and survives; a hard link does not, and the owner and group are not carried over, because the rename gives the path a new file.
The new text is not forced to disk first (that cost about 90 ms a file on btrfs), so "atomic" holds against other processes and a crash of `myform`, not a power loss.
The directory must accept a new file.
No call makes compare-and-rename atomic, so a write that lands between that last read and the rename can still be lost.

`--check` prints the path of each file that would change on stdout, one per line, in the order given, and writes nothing.
A conversion report goes to stderr, as it does everywhere.

`--jsonl` prints one JSON object per input on stdout, in order, and writes nothing, so a caller can do its own preflight and its own writes from one process:

```json
{"path":"a.md","status":"ok","changed":true,"text":"# Title\n","report":""}
{"path":"b.md","status":"error","code":3,"error":"cannot read 'b.md': 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte"}
```

`text` is the formatted document, and `text.encode('utf-8')` is exactly the bytes `myform format -o` writes: line endings, a missing final newline and every Unicode character survive, because each line is ASCII-only JSON.
`changed` says whether `text` differs from what the file held; `report` is that file's conversion report, so nothing about a file goes to stderr (a configuration warning still does).
Input is read as strict UTF-8, as everywhere: a file that is not valid UTF-8 is an `error` record with `code` 3, never text.
`path` is the argument as given.

| Exit code | Meaning                                                                           |
| --------: | :-------------------------------------------------------------------------------- |
|         0 | every file was read and formatted (`--check`: none would change)                  |
|         1 | `--check` only: at least one file would change, and nothing was written           |
|         3 | a file could not be read: missing, or not UTF-8                                   |
|         4 | a file could not be converted                                                     |
|         5 | an output could not be written, or an `--in-place` file changed since it was read |
|         6 | `myform serve` could not start                                                    |
|       130 | interrupted                                                                       |

With several files the first failure sets the code, and under `--check` a failure outranks 1: a check that could not read a file has not passed.
The mode and the worker never change a result: all three behave identically with and without a running worker.

The Python API exposes the same contract:

```python
import myform

rst = myform.convert(source, 'myst', 'rst')
formatted = myform.convert(source, 'myst', 'myst')
wikitext = myform.convert(source, 'myst', 'wikitext')
```

Extensions that preserve unsupported nodes out of band use `myform.convert_artifact(...)`.
Its `ConversionArtifact` keeps target text, the `ConversionReport`, and deterministic typed `EnclaveRecord` carriers together.
A carrier path is `enclaves/<full-sha256>.json`; every `ENCLOSED` report row binds its exact source occurrence to one carrier, and the target writer must recover a final typed link to that exact path.
The legacy `convert()` and `convert_with_report()` shapes raise `ArtifactRequiredError` rather than silently discarding a real carrier.
Built-in writers do not yet claim `ENCLAVE`; each adoption requires a target-specific marker/carrier contract and tests.

Wikitext reading uses the optional [`wikiparse`](https://gitlab.com/doering-ai/apps/wikiparse) adapter (`myform[wikitext]` extra) and requires the `pandoc` executable on `PATH`.
The adapter translates wikitext through wikiparse's document profile into Markdown, then feeds that through the existing MyST reader to produce the typed `Doc`.
Templates are extracted as standalone citation records by the upstream parser; non-citation templates are converted to text or carried.
Install the extra and pandoc to read wikitext:

```sh
pip install myform[wikitext]
```

### Format faster with a worker

Starting Python and importing myForm costs several hundred milliseconds, almost all of a one-shot `format`.
`myform serve` keeps one warm process behind a private Unix socket (`$XDG_RUNTIME_DIR/myform/worker.sock`), and `myform format` forwards to it when it runs:

```sh
myform serve &                   # or run it from a systemd user socket unit; it exits when idle
myform format README.md          # served by the worker, in tens of milliseconds
myform format README.md --worker-debug   # say whether the worker served it, and why not
myform format README.md --no-worker      # never forward (or set MYFORM_NO_WORKER=1)
```

A worker never changes a result: output, report, exit code and files are identical with or without it, configuration is read from disk for every request, a worker running older code than the installed myForm refuses to answer and exits, and any failure falls back to formatting in-process.
The command never starts a worker itself.
See the [worker guide](https://myform.docs.doering.ai/worker.html) for the protocol, the socket and systemd-activation contract, and the environment variables.

## Plan Markdown edits

Editors can use `myform.edit` to continue a list, wrap selected text, or change a table or section.
For example, pressing Enter at the end of a bullet creates the next item:

```python
from myform.edit import Context, act

text = '- First item'
caret = len(text)
result = act(text, ((caret, caret),), 'enter', Context())
assert result is not None
for edit in reversed(result.edits):
    text = text[:edit.start] + edit.text + text[edit.end:]
assert text == '- First item\n- '
```

Edits use Python string offsets in the original text.
Apply them from right to left in one undo step, then set the selections from `result.selections`.
A return value of `None` delegates the key to the editor.
A result with a message and no edits explains why the action was declined.

## Configure translation

`myform` discovers the nearest `myform.yaml`, `.myform.yaml`, or `[tool.myform]` table by walking upward from the target path.
Within one directory, that order is also the precedence order.
The nearest directory wins rather than merging several files.

```yaml
degrade:
  mode: annotate
  comments: true
assist:
  enabled: false
typst:
  postformat: off
extensions: []
```

### Definition preservation

MyST, GFM, and Obsidian preserve unused footnote and link definitions by default, including through the mdformat `myst` facade.
A fragment can contain a definition whose call is in another fragment.
Formatting does not diagnose unused definitions over an assumed complete document.

A label that is defined more than once keeps every definition exactly where it is written, and the rest of the document is formatted as usual; see [Constructs left as written](#constructs-left-as-written).
Fenced examples are literal content.
Explicit orphan removal is suspended for a document that carries any construct as written, because a reference inside such a block is a use that removal cannot see.

For deliberate removal over a complete document, use `myform format --no-keep-footnote-orphans`, `options={'keep_orphans': False}`, or top-level `keep_orphans: false` in myform configuration.
The legacy `.mdformat.toml` setting `[plugin.footnote] keep_orphans = false` controls both definition kinds.
`--keep-footnote-orphans` forces preservation.
Preservation does not make arbitrary formatting lossless; see the remaining limitations below.

### Constructs left as written

Some constructs cannot be rewritten without discarding text, so formatting leaves each one exactly as written and formats everything around it.
No text of them is lost, and formatting the output again changes nothing.
The one to three spaces that may indent a construct's first line are structure, not text; they are removed, so that re-indenting a neighboring list cannot absorb the construct.

- A table row with more cells than its header keeps the whole table as written.
  The table grammar would otherwise drop the extra cells.
- Footnote or link definitions that share a label keep every definition in place, in the order written.
  CommonMark keeps the first definition of a link label, so none of them can start to win in its place.
  Unrelated definitions are still gathered after the text.

The command line names each such construct on stderr under `--report summary` (the default) or `--report json`; `--report none` stays silent.
The conversion report holds one `preserved` entry per construct, which is not a degradation, so `lossy` stays false.
Converting to a format other than MyST, GFM, or Obsidian carries the construct as literal code and reports that as a replacement.

### Fold-aware tables

MyST and GFM table writers size columns from visible inline content by default.
Only typically-hidden material -- link destinations, image URLs, MyST role targets, and backslash escapes -- is folded out of the measurement; rendered markup such as emphasis, code, math, and HTML still counts at its serialized width.
Markdown source remains unchanged apart from padding, so pipe positions can vary when a folded cell's serialized form is longer than its measured width.

Disable the policy per target when source-character alignment is required:

```yaml
myst:
  fold_aware_tables: false
gfm:
  fold_aware_tables: false
```

The MyST mdformat facade exposes the same default as `[plugin.myst] fold_aware_tables = true`; `--no-fold-aware-tables` disables it for one invocation.
Bare `mdformat --extensions gfm` retains the upstream GFM formatter, while `myform.format(..., 'gfm')` uses this policy.

### Safe Setext headings

MyST, GFM, and Obsidian formatting rewrite ordinary Setext headings to ATX form by default.
A list label followed by a single nested dash is preserved as an empty nested list rather than being mistaken for an H2 underline.
Set `myst.setext_headings: false` (or use `--no-setext-headings` in the MyST facade) to retain the stock CommonMark precedence for MyST; the universal API accepts `options={"setext_headings": false}` for any CommonMark-family reader.

Every non-native conversion is represented in the conversion report.
The default `annotate` degradation mode also leaves a provenance comment when the target supports comments; `silent` suppresses comments but not reports, while `strict` refuses carrying, dropping, or enclosing unsupported constructs.

The optional LM assist is degradation-only and disabled by default, which makes zero network calls.
When enabled, it uses the configured local OpenAI-compatible gateway and retains a deterministic fallback.

The committed [`myform.schema.json`](myform.schema.json) and [`myst-options.schema.json`](myst-options.schema.json) schemas describe the translator and mdformat-facade configuration surfaces.
Refresh or verify both with:

```sh
uv run myform-write-schema
uv run myform-write-schema --check
```

## Use the MyST mdformat facade

The original plugin remains available through mdformat's `myst` extension entry point:

```sh
uv run mdformat README.md
```

This repository began as a ground-up rewrite of [`mdformat-myst`](https://github.com/executablebooks/mdformat-myst), written to make uncompiled MyST documents look closer to the hand-formatted sources maintained by the MyST team.
That facade remains useful on its own:

1. [Targets](https://myst-parser.readthedocs.io/en/latest/syntax/cross-referencing.html#creating-explicit-targets) hug the headings or blocks they identify instead of being separated by an extra blank line.

2. [Directive options](https://myst-parser.readthedocs.io/en/latest/syntax/roles-and-directives.html) prefer the readable `:key: value` prefix form and escalate to a YAML block only when necessary.
   Newly quoted single-line values use YAML-compatible string encoding, preserving apostrophes, embedded quotes and literal backslashes.

3. Directive contents are formatted as first-class Markdown rather than treated as opaque text.

4. Parser and renderer rules are explicit, decorator-registered examples of a modern mdformat extension.

5. YAML values use `srsly`'s maintained `ruamel.yaml` integration.

6. The optional `sembr` mode reflows paragraphs to [one sentence per line](https://sembr.org/) without changing their rendered output:

   ```toml
   [plugin.myst]
   sembr = true
   ```

   Enable it per invocation with `mdformat --sembr <filename>`; `--no-sembr` overrides the TOML setting.
   The flags belong to the `mdformat` command: `myform format` has none and takes its options from `.mdformat.toml`.

   The splitter holds back wherever only a citation can start or continue: abbreviations (`cf.`, `nn.`, `vgl.`), labels with a number (`Prop. 17`, `art. 3`), roman numerals (`II. Def. vi`), and locators (`chap. 7 and 8`, `12:10`).
   A sentence ends at `.`, `!`, `?` or `…` and at the markup and quotes that trail it (`**Stop right here.** Then go on.`, `It ends here.[^1] Then go on.`, `«Stop right here.» Then go on.`), and the next one may start with any uppercase letter, symbol or emoji (`🔵 Then go on.`).
   A line break in the source does not decide where a sentence ends, because older versions of the splitter made many of them.
   With `sembr_keep_breaks` (the default), two kinds of break stay: one that only the splitter's guess would join (what follows cannot start a sentence: a dash, a tag, a template directive), and one before a line that opens with an emoji or another pictograph.
   Set `sembr_keep_breaks = false` (`--no-sembr-keep-breaks`) for a pass that heals old, wrong breaks: the splitter then decides every break alone.
   A sentence of at most two words stays on a neighbour's line instead of standing alone, whatever the line breaks of the source were (`Yes.`, `**Note.** The rest`): `sembr_min_words = 3` (`--sembr-min-words 3`) raises the limit and `0` turns the rule off; it takes an integer.
   A parenthesis opened in the middle of a sentence and a tight pair of dashes (`--like this. Really--`) hold their sentence ends.
   To hold one gap, put a no-break space in place of the space after the period; the `&nbsp;` entity is read as that character and written back as the character, unless `normalize_text` is on.
   Beside a space or a line break it is a double space instead, and the gap splits (`He left.&nbsp; Then she came.`).
   Never put it right before a closing emphasis delimiter (`**word&nbsp;**`), which loses the emphasis.
   To keep a paragraph as written, exempt a block with `<!-- myform-ignore sembr -->`.
   [One sentence per line](docs/sembr.md) documents every option and both devices.
   List items keep their prose on one line, so a short bullet stays compact, unless `sembr_list_items = true` is set as well; each continuation line then sits under its item's marker. An item inside a block quote always stays on one line.

7. Markdown formatting follows the document's list and table style.
   The first sibling gap at each depth of a root list determines its item spacing.
   A blank between blocks within one item can still require a loose list.
   Sibling lists with different markers stay separate, and each table keeps compact or aligned padding according to its own rows.
   The first two numbers of each ordered list normally establish repeated or consecutive numbering.
   A list that begins with a different pattern keeps its numbers.
   To keep every written number, including a deliberate gap later in the list, use:

   ```toml
   [plugin.myst]
   list_numbering = "preserve"
   ```

   `mdformat --list-numbering preserve <filename>` does the same for one invocation.
   An explicit `--number` or local `number = true` selects mdformat's consecutive zero-padded numbering unless `list_numbering` sets a mode.

   If a trait is absent in the root list, myform reads the first example at the same depth elsewhere in the file, then the document's `myform:` front matter, then project configuration, then its default.
   Declare project fallback traits inside `precedent` in `myform.yaml`:

   ```yaml
   precedent:
     spacing: loose
     depths:
       1:
         indent_step: 4
   ```

   A document can supply the same trait keys under its `myform:` front matter key.
   Emphasis and strong marks follow the first occurrence of their kind in the file when the replacement still parses the same way.
   A strong span written `__name__` around one name (`__init__`, `tests/__snapshots__/x`) keeps its marks, so it is not that first occurrence and decides nothing about how other spans are written.

8. MyST's `attrs_block` and `amsmath` extensions are read as a site that enables them reads them.
   A line holding only an attribute list (`{.glossary}`, `{#id}`, `{attribution="Immanuel Kant"}`) is a block of its own.
   It stays directly above the block it describes (a definition list, heading, quote, fence, table) and stays apart from it when it began apart.
   A bare `\begin{align*}` ... `\end{align*}` environment is display math and comes back exactly as written, indentation included, instead of escaped as prose.
   Braces that do not hold a valid attribute list (`{name}`, `{u = 0}`, `{Footnote 1: See § xviii.}`) stay text, and the line never interrupts a paragraph.

9. The optional `normalize_text` and `normalize_diacritics` modes rewrite prose into plainer text, for notes that are kept like source code:

   ```toml
   [plugin.myst]
   normalize_text = true        # curly quotes, dashes, ellipses, exotic spaces, ligatures, fractions
   normalize_diacritics = true  # strip the accents of Latin letters
   ```

   Enable them per invocation with `mdformat --normalize-text --normalize-diacritics <filename>`; `--no-normalize-text` and `--no-normalize-diacritics` override the TOML settings. `myform format` has no such flags and takes the keys from `.mdformat.toml`.

   `normalize_text` folds all quote forms to `'` and `"`, an em dash to `--` (a pair of them to `a --aside-- b`), en dashes, hyphen variants and the minus sign to `-`, `…` to `...`, exotic spaces to a space, and deletes zero-width characters, soft hyphens and bidirectional controls.
   Ligatures, vulgar fractions (`1½` becomes `1 1/2`), roman-numeral glyphs and fullwidth ASCII become plain letters and digits, and mojibake (`â€™`) and entity text that survived parsing (`&amp;amp;`) are repaired.
   A no-break space directly after a sentence-final mark is kept and written `&nbsp;`; any other becomes a plain space.
   `normalize_diacritics` strips the diacritics of Latin letters and folds `æ œ ß ø ł đ ð þ ı ſ`; other scripts are untouched.

   Only prose text changes: code, math, HTML, link destinations and titles, autolinks, reference labels, front matter, role and directive arguments, comments and targets stay as written.
   Normalization runs before `sembr`, and a second pass changes nothing.
   [Text and diacritic normalization](docs/normalization.md) holds the full table and the rules.

The facade also preserves established skip-formatting comments:

```md
<!-- myform-ignore -->

This next block is left exactly as written.
```

```md
<!-- myform-ignore-start -->

Every block in this range is preserved.

<!-- myform-ignore-end -->
```

```md
<!-- myform-ignore-file -->
```

Each marker takes the argument `sembr`, which exempts the paragraphs of the block, region or file from the sentence-per-line reflow and formats everything else (`<!-- myform-ignore sembr -->`, `<!-- myform-ignore-start sembr -->` ...
`<!-- myform-ignore-end sembr -->`, `<!-- myform-ignore-file sembr -->`).
An end marker names its scope too: `<!-- myform-ignore-end -->` does not close a `sembr` region, which then runs to the end of the file.

The markers act at the document top level.
Their strings remain configurable through `[plugin.myst]`.

### Format a library of scholarly files

OCR-derived scholarly chapters are long, citation-dense, and full of numbered prose.
This `.mdformat.toml` formats a whole file of that kind without renumbering lists or re-wrapping text:

```toml
wrap = "keep"                # line breaks stay as written; sembr alone decides them
# number is deliberately unset: list_numbering owns ordered lists

[plugin.myst]
list_numbering = "preserve"  # 2. 3. 4. stay 2. 3. 4.
sembr = true                 # optional: one sentence per line
sembr_list_items = true      # optional: numbered prose items too
sembr_keep_breaks = true     # the default: a break only the splitter's guess would join stays
sembr_min_words = 2          # the default: a sentence of two words or fewer joins a neighbour's line
```

Formatting is meant to change layout, not text, but mdformat and the CommonMark rules behind it make a few exceptions that matter for scanned books.
Check these before a library-wide run:

- A table row with more cells than its header loses the extra cells. GFM drops them when the table is parsed, so the formatter never sees them. Widen the header, or fence the table off with `<!-- myform-ignore -->`.
- Footnote definitions are written in the order of their first reference, not the order of the source.
- A link destination is percent-encoded when it holds a non-ASCII character or a backslash.
- An entity such as `&lt;` comes back as the character it names.
- A `$$...$$` pair inside a paragraph reads as inline math between two literal dollar signs, and the dollar signs come back escaped (`\$$...$\$`).
- A tangle of `*` runs (OCR'd bold and italic fragments) can re-nest differently on the first format and is not stable until the second. Clean such passages in the source.
- A role cannot hold a `{` in its name or attribute list. A stray `{` in prose therefore stays text rather than swallowing everything up to the next role.
- `sembr` preserves parsed link/image titles and wiki syntax. Escaped literal wiki-shaped text can still fail a two-pass fixed-point check; inspect the output and retain the source when that check fails.

## Documentation

- [Documentation front door](https://myform.docs.doering.ai/)
- [API reference](https://myform.docs.doering.ai/api.html)
- [One sentence per line](docs/sembr.md): every sembr option and both override devices
- [Universal translator specification](https://myform.docs.doering.ai/spec/myform-spec.html)
- [Release procedure](RELEASING.md)

## Credits

The sentence-splitting benchmark in `benchmarks/sembr/` adapts English test cases from two MIT-licensed suites: the [Pragmatic Segmenter](https://github.com/diasks2/pragmatic_segmenter) (Copyright (c) 2015 Kevin S. Dias) and [sentencex](https://github.com/wikimedia/sentencex) (Copyright (c) 2025 Santhosh Thottingal).
Their licence notices sit beside the adapted file, in `benchmarks/sembr/cases/`.

