Skip to content

Pagination rules

MDLeaf applies a few rules when it lays text out on pages, in page view and in the PDF.

  1. No stranded headings. A heading is never the last thing on a page. It moves to the next page together with the block after it. A run of headings (## followed by ###) moves as a unit.
  2. Atomic blocks stay whole if they fit. Tables, code blocks, display math, aligned images, paragraphs of only images, and table-of-contents entries are not split when they fit on one page; if they do not fit in the space left, they start on the next page.
  3. Oversized blocks are split. A table or code block taller than a whole page is split (tables between rows, code between lines). Images cannot be split; they are cut off at the page bottom.
keep-together/document.md
# Keep together
MDLeaf lays Markdown out on real pages. Paragraphs flow from page to page, and the page view shows exactly what the PDF will contain.
MDLeaf lays Markdown out on real pages. Paragraphs flow from page to page, and the page view shows exactly what the PDF will contain.
MDLeaf lays Markdown out on real pages. Paragraphs flow from page to page, and the page view shows exactly what the PDF will contain.
## A heading near the bottom
MDLeaf lays Markdown out on real pages. Paragraphs flow from page to page, and the page view shows exactly what the PDF will contain.
| Tree | Leaf | Height |
| --- | --- | --- |
| Tree 1 | Simple | 3 m |
| Tree 2 | Simple | 6 m |
| Tree 3 | Simple | 9 m |
| Tree 4 | Simple | 12 m |
| Tree 5 | Simple | 15 m |
| Tree 6 | Simple | 18 m |
| Tree 7 | Simple | 21 m |
| Tree 8 | Simple | 24 m |
| Tree 9 | Simple | 27 m |
| Tree 10 | Simple | 30 m |
## An oversized table
| # | Note |
| --- | --- |
| 1 | Row 1 of a table taller than one page |
| 2 | Row 2 of a table taller than one page |
| 3 | Row 3 of a table taller than one page |
| 4 | Row 4 of a table taller than one page |
| 5 | Row 5 of a table taller than one page |
| 6 | Row 6 of a table taller than one page |
| 7 | Row 7 of a table taller than one page |
| 8 | Row 8 of a table taller than one page |
| 9 | Row 9 of a table taller than one page |
| 10 | Row 10 of a table taller than one page |
| 11 | Row 11 of a table taller than one page |
| 12 | Row 12 of a table taller than one page |
| 13 | Row 13 of a table taller than one page |
| 14 | Row 14 of a table taller than one page |
| 15 | Row 15 of a table taller than one page |
| 16 | Row 16 of a table taller than one page |
| 17 | Row 17 of a table taller than one page |
| 18 | Row 18 of a table taller than one page |
| 19 | Row 19 of a table taller than one page |
| 20 | Row 20 of a table taller than one page |
| 21 | Row 21 of a table taller than one page |
| 22 | Row 22 of a table taller than one page |
| 23 | Row 23 of a table taller than one page |
| 24 | Row 24 of a table taller than one page |
| 25 | Row 25 of a table taller than one page |
| 26 | Row 26 of a table taller than one page |
| 27 | Row 27 of a table taller than one page |
| 28 | Row 28 of a table taller than one page |
| 29 | Row 29 of a table taller than one page |
| 30 | Row 30 of a table taller than one page |
| 31 | Row 31 of a table taller than one page |
| 32 | Row 32 of a table taller than one page |
| 33 | Row 33 of a table taller than one page |
| 34 | Row 34 of a table taller than one page |
| 35 | Row 35 of a table taller than one page |
| 36 | Row 36 of a table taller than one page |
| 37 | Row 37 of a table taller than one page |
| 38 | Row 38 of a table taller than one page |
| 39 | Row 39 of a table taller than one page |
| 40 | Row 40 of a table taller than one page |
| 41 | Row 41 of a table taller than one page |
| 42 | Row 42 of a table taller than one page |
| 43 | Row 43 of a table taller than one page |
| 44 | Row 44 of a table taller than one page |
| 45 | Row 45 of a table taller than one page |
| 46 | Row 46 of a table taller than one page |
| 47 | Row 47 of a table taller than one page |
| 48 | Row 48 of a table taller than one page |
| 49 | Row 49 of a table taller than one page |
| 50 | Row 50 of a table taller than one page |
| 51 | Row 51 of a table taller than one page |
| 52 | Row 52 of a table taller than one page |
| 53 | Row 53 of a table taller than one page |
| 54 | Row 54 of a table taller than one page |
| 55 | Row 55 of a table taller than one page |
| 56 | Row 56 of a table taller than one page |
| 57 | Row 57 of a table taller than one page |
| 58 | Row 58 of a table taller than one page |
| 59 | Row 59 of a table taller than one page |
| 60 | Row 60 of a table taller than one page |
Headings move with the next block, tables and code that fit stay on one page, and an oversized table is split between rows.
Download sample (.mdl)

Open it in MDLeaf with Library → Import .mdl. If MDLeaf is installed, you can also open the file directly.

In page view, each split atomic block and each image taller than the page gets a warning in the editor gutter and the problems panel: This table is taller than one page and will be split across pages. The warnings disappear in draft view.

Themes can add standard CSS break rules; they are applied as far as the layout engine supports them:

/* Every chapter on a new page */
.mdl-document h1 { break-before: page; }
/* Never split quotes */
.mdl-document blockquote { break-inside: avoid; }
/* Tables never directly after a page break */
.mdl-keep { break-before: auto; }

orphans and widows (two lines by default) are best-effort. Only the three rules above are guaranteed. See the CSS contract.