Skip to content

caption.js 2.2.0: sentence and paragraph rules as options - #289

Merged
maboa merged 1 commit into
mainfrom
feat/caption-sentence-rules
Sep 21, 2026
Merged

maboa merged 1 commit into
mainfrom
feat/caption-sentence-rules

Conversation

@maboa

@maboa maboa commented Sep 21, 2026

Copy link
Copy Markdown
Member

caption.js closes a caption at every word ending in a full stop. Two consequences, both measured in the editor:

  • An abbreviation cuts a sentence in two: "We spoke to Dr. Smith about it." generates We spoke to Dr. · Smith about it.
  • A run of short sentences comes out one to a caption: "Yes. No. Maybe. I see." generates four cues, which in fast dialogue flash past, since the minimum-duration safeguard can only extend a cue as far as the next one's start.

init() takes an optional eighth argument of rules. With no options the output is unchanged, and a test pins that.

option effect
detectAbbreviations A dotted abbreviation (e.g., U.S., p.m., Ph.D.) ends a sentence only when the next word starts with a capital, so "We left at 5 p.m. Then it rained." still breaks. A lone initial (J.) never ends one; I. is a word and does.
abbreviations Words that never end a sentence — titles such as Dr. or Prof., which no rule can tell from a sentence end because a capital follows them too. An array or Set; case and the trailing full stop are ignored. Language-specific, so the caller supplies them and the library ships no list.
joinSentences A short sentence shares the caption before it when the whole sentence fits there: on the same line, or as the second line of a one-line caption. A sentence is never split in order to fill a caption, and nothing is joined across a speaker label or a pause longer than maxJoinGap.
maxJoinGap Seconds of silence that still allow a join. Default 1.
paragraphBreaks A new paragraph always starts a new caption — also where a paragraph ended without punctuation, which today runs straight on.

?, !, , ؟ and an ellipsis behave as before. Joining measures the pause from where the previous caption's speech really ends, not from a stop time the timing safeguards may later extend.

caption.d.ts gains CaptionOptions, and the README documents the argument. 15 new tests; the caption suite is 28/28 and the whole suite 89/89.

The version header moves to 2.2.0. changelog.md and the package version are left for the release commit.

Refs hyperaudio/hyperaudio-lite-editor#661, hyperaudio/hyperaudio-lite-editor#662

A caption was closed at every word ending in a full stop, so an
abbreviation cut a sentence in two ("We spoke to Dr." / "Smith about
it.") and a run of short sentences came out one to a caption ("Yes." /
"No." / "Maybe."). init() takes an optional eighth argument:

- detectAbbreviations: a dotted abbreviation (e.g., U.S., p.m.) ends a
  sentence only when a capital follows; a lone initial never does.
- abbreviations: words that never end a sentence, such as titles. They
  are language-specific, so the caller supplies them.
- joinSentences: a short sentence shares the caption before it when the
  whole sentence fits there. A sentence is never split to fill a
  caption, and nothing is joined across a speaker label or a pause
  longer than maxJoinGap (default 1s).
- paragraphBreaks: a new paragraph always starts a new caption, also
  where the paragraph ended without punctuation.

With no options the output is unchanged.

Refs hyperaudio/hyperaudio-lite-editor#661, hyperaudio/hyperaudio-lite-editor#662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant