Repository navigation
fix(markdown-preview): count only words, not markdown markers - #413
Merged
anurag629 merged 1 commit intoOct 28, 2026
Merged
Conversation
anurag629
approved these changes
Oct 28, 2026
anurag629
left a comment
Member
There was a problem hiding this comment.
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.
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.
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
lib/__tests__/markdown-preview.test.tsfor 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 ondevelop.npm run test: 64 files, 2426 tests pass.npm run build: passes.AI assistance
Claude helped me w/ understand the issue
Type of change
Checklist
npm run lint && npm run test && npm run buildpasses locallylib/and have a test inlib/__tests__/page.tsx, client component,opengraph-image.tsx, and the bug report dropdown are all done