From df53417850a58f46f39c563c494febaea032b1da Mon Sep 17 00:00:00 2001 From: oleg <67059482+OlegDev1@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:25:48 +0000 Subject: [PATCH] fix(blocks): text colors are not saved when importing to html --- .../delta-converter/inline-delta.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/blocks/src/_common/adapters/html-adapter/delta-converter/inline-delta.ts b/packages/blocks/src/_common/adapters/html-adapter/delta-converter/inline-delta.ts index edd7c15e637c..d603cba10f19 100644 --- a/packages/blocks/src/_common/adapters/html-adapter/delta-converter/inline-delta.ts +++ b/packages/blocks/src/_common/adapters/html-adapter/delta-converter/inline-delta.ts @@ -74,6 +74,33 @@ export const underlineDeltaToHtmlAdapterMatcher: InlineDeltaToHtmlAdapterMatcher }, }; +export const backgroundDeltaToHtmlAdapterMatcher: InlineDeltaToHtmlAdapterMatcher = + { + name: 'background', + match: delta => !!delta.attributes?.background, + toAST: (_, context) => { + return { + type: 'element', + tagName: 'span', + properties: { style: `background-color: ${_.attributes?.background}` }, + children: [context.current], + }; + }, + }; + +export const colorDeltaToHtmlAdapterMatcher: InlineDeltaToHtmlAdapterMatcher = { + name: 'color', + match: delta => !!delta.attributes?.color, + toAST: (_, context) => { + return { + type: 'element', + tagName: 'span', + properties: { style: `color: ${_.attributes?.color}` }, + children: [context.current], + }; + }, +}; + export const referenceDeltaToHtmlAdapterMatcher: InlineDeltaToHtmlAdapterMatcher = { name: 'reference', @@ -141,6 +168,8 @@ export const inlineDeltaToHtmlAdapterMatchers: InlineDeltaToHtmlAdapterMatcher[] strikeDeltaToHtmlAdapterMatcher, underlineDeltaToHtmlAdapterMatcher, inlineCodeDeltaToMarkdownAdapterMatcher, + backgroundDeltaToHtmlAdapterMatcher, + colorDeltaToHtmlAdapterMatcher, referenceDeltaToHtmlAdapterMatcher, linkDeltaToHtmlAdapterMatcher, ];