Skip to content

fix: count words inside code blocks and inline code (#43)#47

Merged
adibhanna merged 1 commit into
mainfrom
claude/jolly-northcutt-478f7d
May 12, 2026
Merged

fix: count words inside code blocks and inline code (#43)#47
adibhanna merged 1 commit into
mainfrom
claude/jolly-northcutt-478f7d

Conversation

@adibhanna

Copy link
Copy Markdown
Contributor

Summary

Fixes #43 — the StatusBar word count was massively undercounting code-heavy notes (the reporter saw 127,260 words in Obsidian vs 34,608 in ZenNotes).

Root cause: the inline regex in StatusBar.tsx stripped fenced code blocks and inline code spans before splitting on whitespace. Obsidian counts those tokens, so we should too.

The fix extracts the logic into a small countWords helper that only strips YAML frontmatter (which Obsidian also excludes), then counts every non-whitespace token. Behavior verified end-to-end against a test note: 52 words (buggy) → 76 words (fixed), matching a hand count.

Test plan

  • Added packages/app-core/src/lib/word-count.test.ts — 9 vitest cases including the regression for issue [Bug] Words Count Stat is Incorrect #43 (words inside code blocks and inline code), CRLF frontmatter, --- horizontal rules in body, empty input
  • npx vitest run — all 82 tests in @zennotes/app-core pass
  • npx tsc --noEmit — clean
  • Manual verification: opened the test note in the running dev build; status bar now shows 76 words (was 52 with the buggy regex)

The old word-count regex stripped fenced code blocks and inline
code before splitting on whitespace, causing massive undercounts on
code-heavy notes (reporter saw 127,260 in Obsidian → 34,608 in
ZenNotes). Obsidian counts those tokens, so we should too.

Extracts the logic into a small `countWords` helper that only
strips YAML frontmatter, plus a vitest suite covering the
regression case and edge cases (CRLF frontmatter, --- horizontal
rules in body, empty input).
@adibhanna
adibhanna merged commit 2477c10 into main May 12, 2026
5 checks passed
@adibhanna
adibhanna deleted the claude/jolly-northcutt-478f7d branch May 12, 2026 15:41
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] Words Count Stat is Incorrect

1 participant