Skip to content

Fix/324 apostrophe word count - #338

Open
b-camphart wants to merge 3 commits into
kevboh:mainfrom
b-camphart:fix/324-apostrophe-word-count
Open

Fix/324 apostrophe word count#338
b-camphart wants to merge 3 commits into
kevboh:mainfrom
b-camphart:fix/324-apostrophe-word-count

Conversation

@b-camphart

@b-camphart b-camphart commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Two bugs in the countWords function:

1. Apostrophes split contractions into multiple words

Words like can't, don't, it's, o'clock were counted as 2 words because ' was not in the WORD_COUNT_REGEX character class. The regex only matched [\-A-Za-z\u00AA...], so can't tokenized as can + t.

fix #324

2. HTML comments not fully stripped when both flags active

With the default removeMarkdown=true, removeComments=true, the markdown syntax regex ran first. Its > pattern stripped the > from --> (the HTML comment closing tag), so Hello <!-- comment --> world became Hello <!-- comment -- world. The HTML comment regex then couldn't find --> and left fragments behind.

Fix: Swapped the execution order so comments (<!--...-->, %%...%%) are removed before markdown syntax is stripped. This prevents > from interfering with HTML comment delimiters.

Testing

  • 28 tests total (3 pre-existing + 25 new), all passing
  • mocked obsidian module in tests

Brendan added 3 commits July 6, 2026 10:25
- Export countWords function for testability
- Add comprehensive test suite for current countWords behavior
- Add vitest config alias for obsidian module (test-only)
- Add obsidian module stub for test resolution

All 20 baseline tests pass.
Markdown's '> ' replacement strips '>' from '-->',
breaking HTML comment removal.

Swap the blocks so comments are removed before
markdown syntax is stripped.
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.

Bug: Apostrophes break word count

1 participant