fix: derive word_count from the content actually resolved - #22
Merged
Conversation
BookStack only populates page.text for markdown-authored pages, so enhancePageResponse reported word_count: 0 for every WYSIWYG page even when it returned thousands of characters of content. Fall back to markdown, then to tag-stripped html. Splitting on /\s+/ rather than a single space also corrects the count for newline-separated text on markdown-authored pages, which previously read as one word. Documents the Export Content role permission the WYSIWYG markdown fallback needs; without it the fallback fails silently and the page reads as empty.
Ashton210z
added a commit
to Ashton210z/bookstack-mcp
that referenced
this pull request
Sep 4, 2026
Brings in two fixes this fork was missing: - ttpears#22: word_count is derived from the content actually resolved, instead of always reporting 0. - ttpears#9: search filters {created_by:X}/{updated_by:X}/{owned_by:X} take a user slug or 'me' rather than a numeric ID, and say so when given one. Both sides had independently added update_book (client method and tool) and update_chapter. The implementations were equivalent, so the duplicates from upstream were dropped and this fork's kept — they carry the "Optional:" describe() prefix used throughout the file, and update_chapter retains the book_id/priority arguments for moving and reordering, which upstream's version does not have. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YadjrGWa6jL6vu2Fd8eJna
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.
enhancePageResponsederivedword_countfrompage.text, which BookStack only populates for markdown-authored pages. Every WYSIWYG page reportedword_count: 0next to acontent_total_charsin the thousands — #10 has one at 6393 chars reading as empty.countWords()falls backtext→markdown→ tag-strippedhtml, and splits on/\s+/rather than' '. The second half is a separate bug the first exposed: newline-separated text on a markdown page counted as one word.Also documents the Export Content role permission that the WYSIWYG markdown fallback in
getPagedepends on. Without it the export call throws, the catch logs to stderr, and the page reads as empty — the reporter hit this on a read-only Viewer token.What a reviewer should check
src/util/word-count.ts— the fallback order.textfirst preserves existing behaviour for markdown pages;htmlis last because it needs stripping.stripHtmldropsscript/stylebodies and , nothing else. Other entities count as part of whatever token they sit in — approximate by design.enhancePageResponsepasses the wholepage, so the count no longer depends on the requestedformat. A page now reports the sameword_countwhether it was fetched as markdown or html.Not covered
No end-to-end run against a live instance. The tests feed
enhancePageResponse's input shape (text: ''with a populatedmarkdown) rather than a real WYSIWYG page.type-check/build/testpass — 17 tests, up from 9.Closes #10.