Pagination test
A long walk through every element a story can hold, written to be cut into pages and to show exactly where the cuts fall.
This story exists to be measured. It is longer than anything else in the collection on purpose, and it uses each kind of block at least twice: once where it sits comfortably in the middle of a page, and once where it is likely to land on a boundary. If a page breaks badly anywhere, it should break badly here first.
Plain paragraphs
A paragraph is the unit everything else is measured against. This one is short.
This one is deliberately long, so that it cannot fit in whatever space is left at the foot of a page and has to be cut at a line and carried over. When that happens the first part should end on a full line, the second part should begin at the top of the next page with no extra space above it, and nothing about the join should suggest that two paragraphs met there. If the lines on this page look like any other lines, the paginator has done its job.
Then a short one again, to see how little it takes to start a new page.
Inline marks
Every mark the story understands appears in this section. Some words are set in bold, some are set in italic, and some are both at once. A mark can run across a line break, so here is a long one meant to wrap: this bold phrase is written to be long enough that it will almost certainly be divided between two lines on a phone, and it should stay bold on both.
Code is the other inline mark. A slug such as pagination-test, a tag such as <Slide> or a
function such as paginate(blocks, size) is set in a fixed-width face, which changes how wide
each character is and so changes where the line breaks.
Links are measured like any other text but painted differently: this one goes back to Field Notes, this one to About, and this one is a link with marks inside it, the Colophon, in full. A link at the very end of a page is worth checking, because a tap on it must open the link and not turn the page.
Headings
A heading belongs to what follows it, so it must never be left alone at the foot of a page.
A third-level heading that is long enough to wrap onto a second line on a phone
A heading that wraps is two lines that must never be separated, which is a stricter rule than the one that governs a paragraph.
Lists
An unordered list:
- A short item.
- A second short item, with bold, italic and
codein it. - A long item, written to wrap over several lines so that the marker sits beside the first line only and the lines after it hang underneath, aligned with the text and not with the marker.
- A last short item.
An ordered list, counting from one:
- Parse the file into blocks.
- Measure every block at the width of the page.
- Break each block into lines, and pack the lines into pages.
- When a block does not fit, cut it at a line and carry the rest forward.
- Paint exactly the lines that were measured.
A list that starts at seven:
- The seventh thing.
- The eighth thing.
- The ninth thing.
A list can also hold a list:
- An outer item.
- An inner item.
- Another inner item.
- A second outer item.

A full page
A slide takes the whole page, edge to edge, with its title and caption over the picture.
Quotes
A quote is set apart from the text with a rule at its side, and is narrower than a paragraph because of it.
A short quote, one line or two.
A long quote is the more useful test. It is narrower than the text around it, so it has more lines than a paragraph of the same length would, and it is more likely to be cut by the foot of a page. When it is cut, the rule at its side has to stop at the last line on one page and start again at the first line on the next, as though it had never been interrupted.
A quote can carry marks too:
Measure twice, cut once, and never trust a line-height you have not seen painted.Callouts
A callout is a box. The box has padding, so the text inside it is measured at a narrower width than the text outside it.
A lead is not only for the opening. Used again in the middle of a story it sets one paragraph larger than the rest, and larger type means fewer words to the line.
Pictures in the text
A picture in the run of the text keeps its own shape. It is given its width and height, so the space for it is known before a single byte of it has loaded.

A tall picture, two to three, with a caption that must stay on the same page as the picture above it.
A picture too tall for the space that is left has to move to the next page whole, since a picture cannot be cut at a line. What stays behind is a gap at the foot of the page before it.

The same kind of picture declared wide, three to two, with a caption holding a link, bold and italic.
A picture can also be written as plain Markdown, with no size. On a line of its own it is a figure, and the title in quotes becomes its caption:

A Markdown picture, with its title as the caption.
Hard breaks
Everything so far has let the paginator decide where a page ends. A break takes that decision away. The rule below this paragraph ends the page here, however much room is left on it.
This paragraph starts a new page because of the rule above it. The tag <Break /> does the
same thing, and one is written just above the Headings section.
Code
A block of code is rare in a story, but it is allowed. It is set as one box, in a fixed-width face, and its lines are wrapped like any other text.
export function paginate(blocks: Block[], size: { width: number; height: number }) {
const pages: StoryPage[] = [];
for (const block of blocks) place(block, pages, size);
return pages;
}
Two in a row

The slide before this one had a title and no caption. This one has a caption and no title.

The last slide
One more full page before the end.
The end
If you have reached this page by tapping, the count at the foot of the screen should match the number on the cover, and going back one page should show the last slide, whole.
This is the final paragraph. It is followed by nothing, so whatever space is left beneath it is the last thing the paginator had to decide, and it should simply be left empty.