Expand description
Guided fixation reading: the leading letters of every word are emphasised so the eye lands on an artificial fixation point and the brain completes the rest of the word.
This crate is an independent, clean-room, zero-dependency implementation of the algorithm defined in the Smooth Reading specification, producing byte-identical output with the TypeScript, Swift, Kotlin, Python and Dart ports across all shared fixtures.
§Quick start
use smooth_reading::{HtmlOptions, Options, Token, to_html, to_markdown, tokenize};
// HTML: the first half of each word is wrapped in <b>.
let html = to_html("Smooth reading works.", &Options::new(), &HtmlOptions::new());
assert_eq!(html, "<b>Smo</b>oth <b>read</b>ing <b>wor</b>ks.");
// Markdown.
assert_eq!(to_markdown("Smooth reading", &Options::new(), "**"), "**Smo**oth **read**ing");
// Tokens, for rendering with your own text engine.
for token in tokenize("Smooth reading", &Options::new().fixation(4)) {
match token {
Token::Word { fixation_text, rest_text, .. } => println!("{fixation_text} | {rest_text}"),
Token::Separator { text } => print!("{text}"),
}
}§Options
Options holds the algorithm settings (fixation strength 1..=5,
saccade interval, min_word_length, emphasize_numbers, locale, a
custom fixation_length override and a pluggable Segmenter);
HtmlOptions holds the markup settings for to_html. Both are
configured with chaining setters and clamp out-of-range values instead of
failing.
§Unicode
The default SpecSegmenter is the spec’s regular-expression scanner over
a generated Unicode general-category table (unicode_data, no runtime
dependencies), with grapheme clustering that keeps combining marks, Hangul
jamo, Indic conjuncts and emoji sequences whole. Right-to-left text is
never reordered: the fixation is always the logical start of the word. A
continuous run of Chinese, Japanese or Thai is one word; plug in a
dictionary-based Segmenter for finer breaks.
Modules§
- unicode_
data - Unicode general-category range tables (
L,N,Nd,M).
Structs§
- Html
Options - Markup options for
to_html. - Options
- Algorithm options with the spec defaults (SPEC §4).
- Segment
- A raw segment of the input: a slice of the text plus whether it is a word.
- Spec
Segmenter - The spec’s regular-expression segmenter (SPEC §3, fallback segmentation).
- Tokenize
State - Saccade bookkeeping shared across several
tokenize_with_statecalls, soto_htmlkeeps counting words across markup (SPEC §4).
Enums§
- Token
- A piece of the input: a word or a separator.
Constants§
- DEFAULT_
SKIP_ TAGS - Elements whose text content
to_htmlnever touches (SPEC §4). - VERSION
- The crate version, kept in step with every other Smooth Reading port.
Traits§
- Segmenter
- Supplies word boundaries and grapheme clusters to the tokenizer (SPEC §3).
Functions§
- escape_
html - Escapes exactly
& < > "(SPEC §4);'stays sodon'treads naturally. - fixation_
length - How many leading grapheme clusters of
word(graphemeslong) to emphasise,0meaning none (SPEC §2). - to_html
- Renders
textas HTML with the leading part of each word emphasised (SPEC §4). - to_
markdown - Renders
textas Markdown, wrapping each fixation inmarker. - tokenize
- Splits
textinto words and separators and computes each word’s fixation prefix (SPEC §3, §4). - tokenize_
with_ state tokenizewith an externally owned saccade counter.
Type Aliases§
- Fixation
Length Fn - A custom fixation-length algorithm (SPEC §2, “Custom override”).