Skip to main content

TextParseConfig

TextParseConfig (crates/show/src/parse.rs) controls how extracted text is split into cues during import. It is serializable and can be passed to import_pdf_show from the frontend (camelCase field names in JSON).

Fields​

FieldTypeDefaultDescription
maxCueLengthnumber140Target maximum cue length in characters. Longer passages are split.
minCueLengthnumber40Fragments shorter than this are merged into a neighboring cue.
splitPunctuationstring[][";", ":", "—", ","]Split points, in priority order, for over-long sentences.

Rust constants: DEFAULT_MAX_CUE_LENGTH, DEFAULT_MIN_CUE_LENGTH, DEFAULT_SPLIT_PUNCTUATION.

Splitting algorithm​

  1. Sentences are split on ., !, and ? (the terminator stays with the sentence it ends).
  2. Long sentences (over maxCueLength) are split at the strongest nearby punctuation. The splitter searches right-to-left within the window and prefers higher-priority punctuation, so a comma is used only when no semicolon, colon, or em-dash is available.
  3. If no punctuation is available, it splits at the last whitespace in the window, so a word is never cut in two. A sentence with no whitespace at all (one giant word) is kept whole.
  4. Small fragments (under minCueLength) are merged into a neighboring cue, so imports don't contain stunted one-word cues.

These steps are implemented by split_cue_text, which composes split_sentences, split_long, find_split_point, and merge_small_into_neighbours.

Example​

import { importPdfShow } from "@/lib/tauri";

// (The frontend wrapper currently passes no config; call invoke directly to
// override the defaults.)
await invoke("import_pdf_show", {
config: {
maxCueLength: 100,
minCueLength: 30,
splitPunctuation: [";", ":", "—", ","],
},
});

Notes​

  • Lengths are measured in characters, not bytes, so multi-byte characters split correctly.
  • Setting minCueLength to 0 disables merging.
  • Removing all splitPunctuation still yields word-boundary splitting.