readingtime

command
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Command readingtime counts the words in a document and estimates how long it takes to read, ignoring anything that is not prose.

Counting words is the smallest possible streaming task and it has two ways to be wrong here, both of which come from the same place: a word is a pattern, and this library reports characters.

A word can be split across chunks. Text arrives in pieces whose boundaries follow the writes, so counting with strings.Fields per chunk counts "hello" twice if the boundary falls inside it. Measured on a 200-word document written a byte at a time, that is 1093 words instead of 200. So the counter carries one bit of state - am I inside a word - across chunks, and never looks at more than one character at a time.

A word can also be split across markup, and there the answer is the opposite. <p>hello<b>world</b></p> is one word: inline markup does not separate text, so the state has to survive an element boundary too. <p>hello</p><p>world</p> is two, because a block does separate. The counter therefore resets its state on blocks and keeps it across everything else.

The rest is the same discipline as the other converters here: a character reference is decoded after the text node is accumulated, not per chunk, because a reference is another pattern a boundary can split - and it matters for counting, since "&#32;" is a word separator and "&amp;" is not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL