fix(doc): strip duplicate title H1 on the JSONML doc-create path#464
Open
PeterGuy326 wants to merge 1 commit into
Open
fix(doc): strip duplicate title H1 on the JSONML doc-create path#464PeterGuy326 wants to merge 1 commit into
PeterGuy326 wants to merge 1 commit into
Conversation
PR #448 stripped a leading H1 matching --name on the markdown path of `dws doc create`, but the JSONML path (--content-format jsonml) was never covered. Rich documents — tables, callouts, styled blocks — go through create_document + update_document(jsonml=...), which writes the body verbatim, so a leading h1 whose text equals the document name renders the title twice (the "two headings" effect the doc platform shows because it already renders --name as the page title). Add stripLeadingDuplicateTitleJSONML: parse the marshaled JSONML body, skip an optional ["root", {}, ...] wrapper, and drop the first node when it is an h1 whose concatenated leaf text equals --name (trimmed, case-insensitive). Any parse failure or non-match leaves the body untouched, so a valid write is never blocked. A stderr note mirrors the markdown path so agents learn the convention.
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.
Problem
dws doc createrenders--nameas the page title. When the body also opens with an H1 of the same text, the document shows the title twice — the "两个标题头" effect.PR #448 fixed this only on the markdown path (
stripLeadingDuplicateTitleHeading). The JSONML path (--content-format jsonml) was never covered: rich docs — tables, callouts, styled blocks — go throughcreate_document+update_document(jsonml=...), which writes the body verbatim. So a leadingh1whose text equals the document name survives and renders twice.This was hit in practice by a richly-formatted doc (tables + styled 🧪 callout) created via the JSONML path — the leading H1 duplicating the page title was not stripped.
Fix
Add
stripLeadingDuplicateTitleJSONML, the JSONML counterpart of the markdown guard, wired into theformat == "jsonml"branch ofdoc createright afterprepareDocJSONMLBodyand beforeupdate_document:["root", {}, ...]wrapper.h1whose concatenated leaf text equals--name(trimmed, case-insensitive).Scope matches #448 exactly: only a leading h1 that exactly equals the name is removed;
h2+, distinct headings, and names that merely share a prefix are kept.Tests
TestStripLeadingDuplicateTitleJSONML— unit table: root-wrapped, nested leaf text, bare body (no wrapper), case-insensitive, distinct heading kept, non-h1 kept, invalid JSON untouched.TestDocCreateStripsDuplicateTitleJSONML— end-to-end through the realdoc create --content-format jsonmlcommand, asserting the forwardedupdate_documentjsonml has the duplicate h1 removed and the body content preserved.