fix(word-count): treat apostrophes as part of a word - #339
Closed
MsfPablo wants to merge 1 commit into
Closed
Conversation
WORD_COUNT_REGEX didn't include the apostrophe character, so
contractions like "can't" were split into two matches ("can" and "t")
and counted as two words instead of one.
Add ' alongside the existing hyphen in the word-character class, so
contractions and possessives ("can't", "Sarah's") count as a single
word, consistent with how hyphenated words are already handled.
Fixes kevboh#324
Contributor
|
FYI #338 |
Author
|
Closing in favor of #338, which fixes this same issue more completely (also catches a second real bug in the HTML-comment-stripping order) and has proper test coverage via a mocked |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #324.
WORD_COUNT_REGEXdidn't include the apostrophe character, so contractions like "can't" were matched as two separate words ("can" and "t") instead of one, inflating the word count.'alongside the existing\-in the word-character class (the "Option A" fix suggested in the issue), so contractions and possessives count as a single word — consistent with how hyphenated words are already handled by the same regex.Test plan
Verified the regex change against a handful of cases (contractions, possessives, hyphenated words, numbers with commas/decimals) — all count as expected, no regressions:
Can'tI can't won't hasn'tIt's Sarah's bookThis is a testwell-known factThere are 1,000 words and 3.14 piI initially added a unit test under
test/model/, butwriting-session-tracker.tsimports fromobsidian(a types-only package with no runtime entry), which vitest can't resolve outside the Obsidian runtime — the same reason the existingtest/compile/steps/remove-links.test.tsonly covers files that don't importobsidian. Happy to add a test if you'd like the word-counting logic split out into a pure module that could import cleanly.