Skip to main content

Crate smooth_reading

Crate smooth_reading 

Source
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§

HtmlOptions
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.
SpecSegmenter
The spec’s regular-expression segmenter (SPEC §3, fallback segmentation).
TokenizeState
Saccade bookkeeping shared across several tokenize_with_state calls, so to_html keeps 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_html never 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 so don't reads naturally.
fixation_length
How many leading grapheme clusters of word (graphemes long) to emphasise, 0 meaning none (SPEC §2).
to_html
Renders text as HTML with the leading part of each word emphasised (SPEC §4).
to_markdown
Renders text as Markdown, wrapping each fixation in marker.
tokenize
Splits text into words and separators and computes each word’s fixation prefix (SPEC §3, §4).
tokenize_with_state
tokenize with an externally owned saccade counter.

Type Aliases§

FixationLengthFn
A custom fixation-length algorithm (SPEC §2, “Custom override”).