Skip to content

feat: support section-scoped total page counts - #599

Open
yuvrajsingh2428 wants to merge 3 commits into
iamgio:mainfrom
yuvrajsingh2428:feat/totalpages-section
Open

feat: support section-scoped total page counts#599
yuvrajsingh2428 wants to merge 3 commits into
iamgio:mainfrom
yuvrajsingh2428:feat/totalpages-section

Conversation

@yuvrajsingh2428

@yuvrajsingh2428 yuvrajsingh2428 commented Jul 16, 2026

Copy link
Copy Markdown

Summary

This PR adds support for section-scoped total page counts through an optional document | section argument on .totalpages.

By default, .totalpages continues to return the total number of pages in the document, preserving backwards compatibility.

When section is specified, the total page count is calculated from the most recent .resetpagenumber (or from the start of the document if no reset exists), matching the requested behavior.

Changes

  • Added optional document | section scope to .totalpages
  • Preserved document as the default behavior
  • Updated the HTML renderer to expose the selected scope to the runtime
  • Implemented section-aware total page counting in the runtime

Testing

  • Built the project successfully
  • Ran the frontend test suite (npm test)
  • All 131 frontend tests passed

Closes #596

Summary by CodeRabbit

  • New Features

    • Added support for page total counters scoped to sections, including a totalPages(scope) API option.
    • Section totals are now calculated and rendered separately from document-wide totals.
  • Bug Fixes

    • Fixed total page number rendering so “total” values respect page numbering reset markers instead of always showing the document-wide count.
  • Tests

    • Added automated coverage to verify totals update correctly with reset-start markers and section scoping.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bbfc52a4-c820-48ed-95a3-02fb6d024823

📥 Commits

Reviewing files that changed from the base of the PR and between be74a74 and 7411648.

📒 Files selected for processing (2)
  • quarkdown-core/src/main/kotlin/com/quarkdown/core/ast/quarkdown/inline/PageCounter.kt
  • quarkdown-stdlib/src/main/kotlin/com/quarkdown/stdlib/Document.kt

📝 Walkthrough

Walkthrough

Page counters now support document-wide or section-scoped totals. The renderer emits scope metadata, and client-side pagination uses reset markers and starting values to calculate section totals while preserving document totals by default.

Changes

Page number scoping

Layer / File(s) Summary
Page counter scope contract
quarkdown-core/src/main/kotlin/.../PageCounter.kt, quarkdown-stdlib/src/main/kotlin/.../Document.kt
PageCounter defines document and section scopes, while totalPages accepts an optional scope argument and maps "section" accordingly.
Section total page number flow
quarkdown-html/src/main/kotlin/.../QuarkdownHtmlNodeRenderer.kt, quarkdown-html/src/main/typescript/document/handlers/page-numbers.ts, quarkdown-html/src/main/typescript/document/handlers/__tests__/page-numbers-document-handler.spec.ts
TOTAL counters emit scope metadata, total-page updates calculate reset-based section totals, and tests cover document and section results.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant totalPages
  participant PageCounterRenderer
  participant updateTotalPageNumbers
  totalPages->>PageCounterRenderer: provide DOCUMENT or SECTION scope
  PageCounterRenderer->>updateTotalPageNumbers: emit scoped total counter metadata
  updateTotalPageNumbers->>updateTotalPageNumbers: calculate totals from reset markers
  updateTotalPageNumbers->>PageCounterRenderer: write section or document total
Loading

Suggested reviewers: iamgio

Poem

A rabbit counts pages, one, two, three,
With reset-marked sections neatly.
Document-wide or section-wide,
Each total hops to its side.
Hop, hop—totals land just right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main change: section-scoped total page counts.
Linked Issues check ✅ Passed The PR adds an optional document/section scope to .totalpages and makes section totals honor the latest reset marker and its start value.
Out of Scope Changes check ✅ Passed The changes stay focused on .totalpages scope support, with matching renderer/runtime updates and a targeted test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@quarkdown-html/src/main/typescript/document/handlers/page-numbers.ts`:
- Around line 47-87: Update the section-total calculation around the flush
function to use the section’s reset marker start value: compute (start - 1) +
currentSection.length, defaulting to the existing behavior when no applicable
start value exists, and assign that total to every page in the section. Also
normalize indentation for the pages.forEach and total-page-number update blocks
without changing their behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 52cd7b00-23a3-45b7-a9fe-41bf0a31c12c

📥 Commits

Reviewing files that changed from the base of the PR and between 83e0057 and 091c79d.

📒 Files selected for processing (2)
  • quarkdown-html/src/main/kotlin/com/quarkdown/rendering/html/node/QuarkdownHtmlNodeRenderer.kt
  • quarkdown-html/src/main/typescript/document/handlers/page-numbers.ts

Comment thread quarkdown-html/src/main/typescript/document/handlers/page-numbers.ts Outdated

@iamgio iamgio left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'll be unavailable till Sunday 26 and won't be able to look at it closely until then -- sorry about the bad timing. I left some nitpick comments. Also, please add an end-to-end test case.

@Name("totalpages")
fun totalPages() = PageCounter(PageCounter.Target.TOTAL).wrappedAsValue()
fun totalPages(
@Name("scope") scope: String = "document",

@iamgio iamgio Jul 16, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

  • @Name is redundant here
  • You can directly make it scope: PageCounter.Scope = PageCounter.Scope.DOCUMENT skipping the string conversion
  • Please document the new param

*/
class PageCounter(
val target: Target,
val scope: Scope = Scope.DOCUMENT,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please add docs

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.

[Enhancement] Scope .totalpages to last .resetpagenumber via document|section argument

2 participants