Repository navigation
fix(docx-io): drop the blank paragraph written after each void element - #5333
Merged
Merged
Conversation
Plate's static HTML renders each void element's empty text inside a hidden data-slate-spacer span that holds a U+FEFF and a line break. The DOCX converter turned that span into its own paragraph, so every exported image was followed by a paragraph holding only U+FEFF, in the body and in table cells. The converter now prunes those spacers right after it parses the HTML.
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
🦋 Changeset detectedLatest commit: 408927b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch was successfully deployed
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.
Why
Every image exported with
@platejs/docx-iois followed by an extra paragraph that holds only U+FEFF, in the body and in table cells. Plate's static HTML puts each void element's empty text inside a hidden<span data-slate-spacer="true">, and the converter wrote that span as a paragraph of its own.Scope
packages/docx-io/src/lib/internal/helpers/render-document-file.ts:renderDocumentFileprunes everydata-slate-spacernode from the parsed tree before it converts it. The spacer only holds the hidden empty text, so nothing visible is lost.packages/docx-io/src/lib/internal/html-to-docx.slow.ts: two cases export Plate's static image markup, in the body and in a table cell, throughhtmlToDocxBloband check that no paragraph holds only U+FEFF..changeset/docx-void-spacer.md: a patch changeset for@platejs/docx-io.Blast Radius
This touches body export through
htmlToDocxBlobandexportToDocx. The converter drops only nodes markeddata-slate-spacer, and Plate renders that attribute only on the hidden spacer of a void element. Header and footer HTML stay as they were.It leaves alone the figure code that #5330 changes for table cells and list items, so the two PRs merge in either order.
Verification
bun test ./packages/docx-io/src/lib/internal/html-to-docx.slow.ts: 58 pass. Without the fix, both new cases fail with a""paragraph.pnpm test -- ./packages/docx-io: 105 fast tests pass.pnpm --filter @platejs/docx-io lintandtypecheckpass.0a5ea5127a), the same fast tests and all 79 slow ones pass.