Repository navigation
fix(conversion): keep inline formatting when converting to a Tool with per-field sanitize rules - #3049
Open
playlikeboy wants to merge 3 commits into
Open
fix(conversion): keep inline formatting when converting to a Tool with per-field sanitize rules#3049playlikeboy wants to merge 3 commits into
playlikeboy wants to merge 3 commits into
Conversation
playlikeboy
requested review from
TatianaFomina,
gohabereg,
ilyamore88 and
neSpecc
as code owners
November 13, 2026 18:10
…ules
A Block Tool's sanitize config describes its data fields, for example
{ text: { b: true }, caption: false }. On conversion and on merging
Blocks of different Tools, this config was passed to HTMLJanitor as the
rules for the exported string, so the field names were read as tag names
and every real tag was removed: bold, italic and links were lost when
converting to any Tool with per-field sanitize rules.
The exported string is now imported into the target Tool's data first,
and the data is sanitized with sanitizeBlocks, the same way as on saving.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ules sanitizeBlocks() leaves data untouched when the tool sanitize config is empty, so a trailing <br> added by Firefox survived the conversion. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been 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.
Summary
Converting a Block to a Tool that declares per-field
sanitizerules removes all inline formatting from the text: bold, italic and links are lost. The same happens when two Blocks of different Tools are merged with Backspace. This is the "Convert to" part of #2814.Root cause
A Block Tool's sanitize config describes its data fields:
BlockManager.convert()and the different-Tools branch ofBlockManager.mergeBlocks()passed this config toclean()as the rules for the exported string. HTMLJanitor then readstextandcaptionas tag names, finds no rule forb,iora, and strips them. Tools without asanitizegetter are not affected, because their config is the flat inline-tools config.Changes
src/components/modules/blockManager.ts: the exported string is first imported into the target Tool's data withconvertStringToBlockData(), and that data is sanitized withsanitizeBlocks(), the same way as on saving. Bothconvert()andmergeBlocks()use one private helper for this. Tags the target field does not allow are still removed.test/cypress/tests/api/blocks.cy.ts: test thatblocks.convert()keeps<b>and removes<u>for a Tool withsanitize: { text: { b: true } }.docs/CHANGELOG.mdline andpackage.jsonbumped to2.32.0-rc.4(I'll re-bump if fix(sanitizer): merge sanitize rules for the same tag instead of overwriting them #3041 or fix(inline-toolbar): make tool shortcuts work with several Editors on a page #3048 lands first).Related issue
#2814 (the conversion part; the note there about
savenot cleaning the data is not covered)Testing
eslinton the changed files: no errors.vite build --mode test: passes.plain <b>bold</b> <i>italic</i> <a href="https://editorjs.io">link</a>.nextsanitize: { text: { b, i, a }, caption: false }plain bold italic linksanitize: { text: {}, caption: false }and the inline toolbar onplain bold italic linksanitizemerged <b>bold</b> <u>underlined</u>into a Tool withsanitize: { text: { b: true } }merged bold underlinedmerged <b>bold</b> underlined🤖 Generated with Claude Code