Markdown for EPUB: code, footnotes, and typography

The 0.7 draft expands ProseDown with a defined set of Markdown Extra and Pandoc-like conventions. These work alongside YAML metadata and ordinary Markdown. This is not a complete MultiMarkdown implementation.

Feature Authoring syntax EPUB output
Inline code `literal text` Monospaced code; punctuation is not typographically transformed
Code blocks Backtick or tilde fences, optionally followed by a language; four-space indented code also works Wrapped, indented code with its language retained
Nested code Indent fences four spaces inside a list; prefix with > inside a quotation Code remains inside its parent block
Definition lists A term followed by : definition Terms and definitions with hanging indentation
Rich definitions Indent subsequent paragraphs, lists, or fences four spaces Multiple blocks within a definition
Footnotes [^label] and [^label]: note Linked semantic footnotes with return links
Rich notes Indent subsequent paragraphs, lists, or fences four spaces Structured content remains inside one note
Tables Pipe tables with :---, :---:, or ---: alignment Aligned columns and tabular numerals
Abbreviations *[EPUB]: Electronic Publication <abbr title="Electronic Publication">EPUB</abbr>
Strikethrough ~~old text~~ <del>
Insertion ^^new text^^ <ins>
Marked text ==marked text== <mark> with a double underline that works without color
Subscript H~2~O H₂O using semantic <sub>
Superscript x^2^ x² using semantic <sup>

Subscript and superscript with spaces require escaped spaces, as in x^a\ b^. Backslash-escape literal ~, ^, or = delimiters when needed, or put a syntax example in code. Existing semantic HTML remains valid.

A richer definition and note

Source file
:   An editable document.

    A definition can include another paragraph.

    ```text
    manuscript/01-introduction.md
    ```

Review the source.[^review]

[^review]: Before publishing:

    - Check chapter order.
    - Follow the internal links.

    ```sh
    prosedown build manuscript/ book.epub
    ```

Typography

The default uses a coordinated serif heading/body family, a moderate line height, shorter chapter-opening spacing, and first-line indents for continuous prose. Definitions, notes, and reference tables receive their own spacing. Inline code uses a subtle neutral background, a fine border, and a readable monospace size. Code blocks use a single shaded panel without nested inline boxes. Code keeps whitespace and straight punctuation, wraps long lines and identifiers in narrow readers, and stays upright in quotations. The compiler does not add syntax colors or depend on optional Pygments installations.

Reader foreground/background preferences remain in control. Superscripts and subscripts do not stretch the line spacing. Highlighting remains recognizable on monochrome screens. Authors can still replace the default via css:.

Recovery and limits

EPUB recovery preserves these inline meanings using semantic HTML, rather than promising to reproduce the original spelling of every delimiter. Nested code, structured definitions, structured local footnotes, and table alignment have regression coverage through rebuilds. Not every external EPUB structure fits this profile.

MultiMarkdown metadata headers, citations/bibliographies, LaTeX math, automatic numbered cross-references, table spans, and task checkboxes are not enabled. The parser remains Python-Markdown; full CommonMark conformance is not claimed.

The profile is centralized in src/prosedown/markdown_profile.py. It uses PyMdown Extensions for nested fences and inline additions, plus Python-Markdown’s definition lists, footnotes, tables, and abbreviations. The complete sampler is compiled into the website’s downloadable example EPUB.

Executable compatibility fixtures

The repository's tests/fixtures/markdown/ directory contains four synthetic books and expectations.json. The matrix checks inline formatting and table alignment; lists, quotes, code, and links; and rich definitions with repeated footnotes. The collision fixture covers headings that resemble suffixes and footnote IDs. Every expectation runs on the initial EPUB and two rebuilt EPUBs. Text, structure, attributes, and unique IDs are asserted rather than byte-level Markdown spelling. Run python -m unittest discover -s tests to exercise it.

This is the ProseDown profile contract, not a CommonMark or MultiMarkdown conformance suite. Recovery can normalize delimiters while retaining semantics. The 0.7 draft also writes .prosedown/recovery.txt and recovery.json inside recovered projects to explain detected losses and normalization.