-
-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Versions
Longform version: 2.1.10
Obsidian version: 1.11.5
OS: MacOS
Theme: Typewriter
Other plugins that you think might be relevant here: Novel Word Count
Describe the bug
I noticed that Longform was consistently reporting a higher word count for every document than the Novel Word Count plugin.
After some tests I discovered that using apostrophes in contractions (can't won't hasn't, etc) are counted as two words instead of one.
To Reproduce
Steps to reproduce the behavior:
- Open a blank scene
- Type the word "Can't"
- Longform shows scene word count as 2
Expected behavior
Longform should count contractions as a single word.
Screenshots
Additional context
I had a poke around the code and suspect the issue comes from the regex in writing-session-tracker.ts
I threw the WORD_COUNT_REGEX function into AI slop and it seems to think the issue can be fixed by changing the main regex into either:
Option A — allow apostrophes anywhere inside words
"(?:[0-9]+(?:(?:,|\\.)[0-9]+)*|['\\-" + spaceDelimitedChars + "])+"
Or
Option B — allow apostrophes only between letters (more linguistically correct)
"[A-Za-z" + spaceDelimitedChars + "]+(?:'[A-Za-z" + spaceDelimitedChars + "]+)*"
I'm happy to take a crack at fixing it myself but I'm not setup for obsidian plugin development and TS isn't my language of choice so would probably take me longer to setup my environment than to write the fix.