Skip to content

fix(markdown-preview): count only words, not markdown markers - #413

Merged
anurag629 merged 1 commit into
codercops:developfrom
prakashNalla:fix/412-markdown-word-count
Oct 28, 2026
Merged

anurag629 merged 1 commit into
codercops:developfrom
prakashNalla:fix/412-markdown-word-count

Conversation

@prakashNalla

Copy link
Copy Markdown
Contributor

What and why

The word count under the Markdown editor split the source on whitespace, so every #, -, >, --- and | counted as a word, and the "min read" figure was based on the same number. getMarkdownStats() now only counts tokens that have a letter or digit in them. Ordered list numbers (1., 2)) and task boxes ([ ], [x]) have those too, so they're dropped first, but only at the start of a line (after any >, -, * or +), so prose like "I have 3." still counts the 3. The example from the issue now gives 7 words instead of 22. It still counts the source text, with no Markdown parsing.

Closes #412

How I tested this

  • Added cases to lib/__tests__/markdown-preview.test.ts for headings, lists, task lists, quotes, rules, tables, nested quote and list markers, prose with a number and brackets, and whitespace-only input. The marker cases fail without the change. The existing stats test passes unchanged.
  • npm run lint: 0 errors, the same 11 warnings as on develop.
  • npm run test: 64 files, 2426 tests pass.
  • npm run build: passes.

AI assistance

Claude helped me w/ understand the issue

Type of change

  • Bug fix

Checklist

  • I was assigned the linked issue
  • npm run lint && npm run test && npm run build passes locally
  • Logic changes live in lib/ and have a test in lib/__tests__/
  • For a bug fix: the new test fails without my change
  • No analytics, trackers, or calls that send user data off-device
  • Works in both light and dark themes (if UI changed)
  • Inputs have labels and it works with the keyboard alone (if UI changed)
  • New tool: registry entry, page.tsx, client component, opengraph-image.tsx, and the bug report dropdown are all done

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @prakashNalla. Lint (develop's 11 warnings), all 2426 tests, the build and the pages pass on top of develop, and the counts come out right: your example gives 7, 1. First item / 2) Second item 4, a task list 4, -1 is negative and 1.5 million 6, *emphasis* text 2 and an empty editor 0.

@anurag629 anurag629 added the hacktoberfest-accepted PR counts for Hacktoberfest label Oct 28, 2026
@anurag629
anurag629 merged commit 5cfbfa7 into codercops:develop Oct 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted PR counts for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown Preview: the word count counts #, -, | and --- as words

2 participants