Skip to content

fix: clean surviving paragraph after deleteContentRange in replaceDocumentWithMarkdown#76

Merged
a-bonus merged 1 commit intoa-bonus:mainfrom
elijahr:elijahr/fix-survivor-formatting
Feb 25, 2026
Merged

fix: clean surviving paragraph after deleteContentRange in replaceDocumentWithMarkdown#76
a-bonus merged 1 commit intoa-bonus:mainfrom
elijahr:elijahr/fix-survivor-formatting

Conversation

@elijahr
Copy link
Copy Markdown
Contributor

@elijahr elijahr commented Feb 25, 2026

Summary

  • Bug: replaceDocumentWithMarkdown corrupts new content when the document being replaced contains bullet lists or text formatting. Every paragraph in the new document inherits bullet membership and/or text styles from the old content.
  • Root cause: The Google Docs API's deleteContentRange always leaves one trailing paragraph that cannot be deleted. If that survivor has bullet list membership or text formatting, all subsequently inserted text inherits those properties.
  • Fix: After deleting old content, re-read the document to locate the surviving paragraph, then strip its bullet membership (deleteParagraphBullets) and reset text styles (updateTextStyle) before inserting the new markdown.

Reproduction

  1. Create a document with bullet lists (or any formatted content)
  2. Call replaceDocumentWithMarkdown with plain markdown (no bullets)
  3. Read back the document JSON — every paragraph has "bullet": {"listId": "kix.list.X"}

Test plan

  • All 124 existing tests pass (npm run test)
  • End-to-end test: corrupted a document (123/123 paragraphs with createParagraphBullets), ran replaceDocumentWithMarkdown, verified result: 61 intentional bullet paragraphs, 62 normal paragraphs, zero inherited corruption
  • npm run build compiles cleanly

…umentWithMarkdown

When replaceDocumentWithMarkdown deletes existing content, the Google
Docs API always leaves one trailing paragraph that cannot be removed.
If that paragraph has bullet list membership or text formatting from
the old content, all subsequently inserted text inherits those
properties, corrupting the new document (e.g., every paragraph
becomes a bullet list item).

After the delete, re-read the document to locate the survivor, then
strip its bullet membership (deleteParagraphBullets) and reset text
styles before inserting the new markdown content.
@a-bonus a-bonus merged commit 5e57c86 into a-bonus:main Feb 25, 2026
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.

2 participants