Skip to main content

myform

logo

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

Pipeline Status Test Coverage License pre-commit pyrefly 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

Install

Install the public release from PyPI:

pip install myform

To develop from the checked-out source with uv:

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

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:

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.

The Python API exposes the same contract:

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 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:

pip install myform[wikitext]

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:

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.

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. 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, and MyST role targets -- 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:

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 and myst-options.schema.json schemas describe the translator and mdformat-facade configuration surfaces. Refresh or verify both with:

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:

uv run mdformat README.md

This repository began as a ground-up rewrite of 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 hug the headings or blocks they identify instead of being separated by an extra blank line.

  2. Directive options 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 without changing their rendered output:

    [plugin.myst]
    sembr = true
    

    Enable it per invocation with mdformat --sembr <filename>; --no-sembr overrides the TOML setting.

    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). 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:

    [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:

    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.

  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.

The facade also preserves established skip-formatting comments:

<!-- myform-ignore -->

This next block is left exactly as written.
<!-- myform-ignore-start -->

Every block in this range is preserved.

<!-- myform-ignore-end -->
<!-- myform-ignore-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:

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

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

Metadata

Release files for myform 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for myform 2.1.0
File Size Uploaded Provenance Actions
myform-2.1.0.tar.gz 827.8 kB Without provenance Details for myform-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for myform 2.1.0
File Interpreter ABI Platform Actions
myform-2.1.0-cp313-abi3-manylinux_2_28_x86_64.whl CPython 3.13 abi3 Linux glibc 2.28+ x86-64 Details for myform-2.1.0-cp313-abi3-manylinux_2_28_x86_64.whl

Total release size: 1.6 MB

Release files / myform-2.1.0.tar.gz

Download URL myform-2.1.0.tar.gz
Size 827.8 kB
Tags Source
SHA-256 checksum
How to use checksums
908406a50fc6ad72e134acfa83e240caf0a39c7e5773553e2daf114750b9ac8f
BLAKE2b-256 checksum
How to use checksums
fa7046943ec613b743887160e6fce429b16649fecefdc6c676c9a53a0f5c112d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / myform-2.1.0-cp313-abi3-manylinux_2_28_x86_64.whl

Download URL myform-2.1.0-cp313-abi3-manylinux_2_28_x86_64.whl
Size 753.4 kB
Tags CPython 3.13 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
5f7ba6ae2ac2492a3a6a09b5f274f06e5649321a2c0f662ba24b8c8da57f0cb6
BLAKE2b-256 checksum
How to use checksums
560dc39338ee331571e462941d5ad4058fb24206e274556a6b7695e5a9845dbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for myform 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page