Skip to content

Bug: Apostrophes break word count #324

Open

Description

@sometallgit

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:

  1. Open a blank scene
  2. Type the word "Can't"
  3. Longform shows scene word count as 2

Expected behavior
Longform should count contractions as a single word.

Screenshots

Image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions