A distraction-free reader for plain text and Markdown. Tap below the reading line to move to the next paragraph, above it to go back.
Click or tap anywhere on the page: below the faint reading line advances, above it goes back. The current paragraph is highlighted.
Put the text inside the element and give it a height — the reader fills its container.
<div style="height: 100dvh">
<text-reader># A heading
First paragraph, separated from the next by a blank line.
Second paragraph.</text-reader>
</div>
<script src="/text-reader/text-reader.wc.js"></script>
// or as a module import
import '/text-reader/text-reader.wc.js';
The text is read once, when the element connects. To show different text, replace the element. When inserting it as markup, escape the text first.
const reader = document.createElement('text-reader');
reader.textContent = text;
container.replaceChildren(reader);
Methods and behaviour.
// Step through paragraphs programmatically
reader.scrollToNextBlock(); // smooth by default
reader.scrollToNextBlock('instant');
reader.scrollToPreviousBlock();
// Recalculate the top/bottom padding that lets the first and last
// paragraphs reach the reading line. Runs on window resize; call it
// yourself if the reader's container changes size some other way.
reader.updatePadding();
// Behaviour notes
// - Clicks are listened for on the whole document, not just the
// reader, so a tap anywhere advances or goes back. The listener
// is removed when the element is disconnected.
// - Markdown is styled with its syntax left visible: headings,
// strong, em, strike, inline code, quotes, lists, task lists,
// fenced code and links (http/https/mailto only).
// - Each list item is its own stop; blocks too tall to sit above
// the reading line are top-aligned and paged through.
// - Links don't open on a tap (a tap steps the reader); use the
// context menu (right click / long press) to open them.
// - Follows prefers-color-scheme for light and dark colours.
// - Text selection is disabled inside the reader.