fix: preserve heading auto-numbering in im-markdown and warn for plain markdown#2038
fix: preserve heading auto-numbering in im-markdown and warn for plain markdown#2038godququ5-code wants to merge 2 commits into
Conversation
…n markdown Option A: handleIMMarkdownHeading now reads the seq/seq-level attrs emitted by the server for --doc-format im-markdown. seq="auto" resolves against a per-level running counter that resets deeper levels (1., 1.1., 1.2., 2., ...); an explicit seq value is used verbatim, mirroring the existing ordered-list-item logic. Capped at 6 levels like before. Option B: for --doc-format markdown the server returns literal markdown and drops seq/seq-level server-side, so the data is unrecoverable locally. addFetchMarkdownHeadingSeqWarning appends a warnings entry (reusing appendDocWarning, same precedent as addFetchDetailDowngradeWarning) telling callers to re-fetch with --doc-format xml or im-markdown.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds hierarchical heading numbering to IM Markdown conversion and warns when plain Markdown fetches lose ChangesMarkdown heading sequence support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant FetchCommand
participant executeFetchV2
participant convertToIMMarkdown
participant MarkdownOutput
FetchCommand->>executeFetchV2: request Markdown document
executeFetchV2->>convertToIMMarkdown: convert document headings
convertToIMMarkdown-->>MarkdownOutput: emit numbered headings
executeFetchV2-->>FetchCommand: append and print heading-sequence warning
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@shortcuts/doc/docs_fetch_im_markdown_test.go`:
- Around line 247-260: Add a focused test case in the existing document-fetch
Markdown tests that uses server-provided seq-level values to determine numbering
prefixes and reset behavior, rather than relying only on h1/h2 nesting. Ensure
the expected Markdown verifies seq-level is honored, including a level
transition or reset that would fail if seq-level were ignored.
In `@shortcuts/doc/docs_fetch_im_markdown.go`:
- Around line 293-318: The automatic numbering in resolveIMMarkdownHeadingSeq
currently uses only the heading level; update it to parse and honor the
server-provided seq-level attribute for sequence depth, including counter
incrementing and deeper-level resets, while preserving the existing
heading-level fallback when seq-level is absent or invalid. In
shortcuts/doc/docs_fetch_im_markdown_test.go lines 247-260, add a fixture where
seq-level differs from the heading tag and assert the resulting numbering
reflects seq-level.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 166a459c-77ee-407a-b04e-ad080bb806ff
📒 Files selected for processing (4)
shortcuts/doc/docs_fetch_im_markdown.goshortcuts/doc/docs_fetch_im_markdown_test.goshortcuts/doc/docs_fetch_v2.goshortcuts/doc/docs_fetch_v2_test.go
Read the seq-level attribute to determine a heading's depth (markdown '#' count and auto-numbering counter), falling back to the <hN> tag level when seq-level is absent or 'auto'. This preserves the seq/seq-level metadata the server attaches to headings (see larksuite#1781) and addresses a CodeRabbit review suggestion on the PR. Co-Authored-By: WorkBuddy <noreply@workbuddy.ai>
Summary
--doc-format im-markdownnow preserves heading auto-numbering (seq/seq-level) produced by the server.--doc-format markdownnow emits awarningsentry explaining that heading auto-numbering cannot be represented in plain markdown.Why
Heading auto-numbering was silently lost in im-markdown output, and plain markdown has no way to carry it. Callers (including AI agents) need either correct numbering or an explicit, machine-readable signal to re-fetch.
Root cause
--doc-format markdown: the server returns literal markdown and dropsseq/seq-levelserver-side; the CLI never receives the data, so it cannot be recovered locally. → handled via a warning (Option B).--doc-format im-markdown: the server returns HTML5/DocxXML that does containseq="auto" seq-level="auto". The renderer already preservedseqfor list items, buthandleIMMarkdownHeadingignored itsattrsargument and discarded the numbering. → fixed in-CLI (Option A).Test plan
TestConvertToIMMarkdownHeadingSeq: auto-numberedh1/h2withseq="auto" seq-level="auto"render as# 1. Section A/## 1.1. Section A.1(and nesting resets deeper counters:1.,1.1.,1.2.,2.,2.1.). Explicitseqand empty-heading regressions covered.TestDocsFetchMarkdownDetailDowngradeWarnsInOutputto expect the new heading-seq warning alongside the existing detail-downgrade warning.go test ./shortcuts/doc/...passes;go vet ./shortcuts/...,gofmt -l ., andgo mod tidyare clean.Changed files
shortcuts/doc/docs_fetch_im_markdown.go(heading seq state +handleIMMarkdownHeading/resolveIMMarkdownHeadingSeq)shortcuts/doc/docs_fetch_im_markdown_test.go(TestConvertToIMMarkdownHeadingSeq)shortcuts/doc/docs_fetch_v2.go(addFetchMarkdownHeadingSeqWarning+ call site)shortcuts/doc/docs_fetch_v2_test.go(expect new warning)Related Issues
Summary by CodeRabbit
New Features
seq-level).Bug Fixes
Documentation
Tests
seq-levelprecedence.