udecode / plate

A rich-text editor powered by AI
https://platejs.org
Other
11.67k stars 710 forks source link

When calling serializeHtml (from @udecode/plate-serializer-html), output will strip with color #2853

Open tomdyqin opened 10 months ago

tomdyqin commented 10 months ago

Description

When calling serializeHtml (from @udecode/plate-serializer-html), output will strip with color

Steps to Reproduce

it.only('serialize nested with color', () => {
  const editor = createPlateUIEditor({
    plugins: [
      createFontColorPlugin(),
      createParagraphPlugin({
        props: {
          className: 'slate-test',
        },
      }),
    ],
  });

  expect(
    serializeHtml(editor, {
      nodes: [
        {
          type: ELEMENT_PARAGRAPH,
          children: [
            { text: 'I am blue', color: 'blue' },
            { text: ' text!' },
          ],
        },
      ],
      preserveClassNames: ['slate-'],
    })
  ).toBe(
    '<div class="slate-test"><span style="color: blue">I am</span> text!</div>'
  );
});

Expected Behavior

output will with color

Expected: "<div class=\"slate-p slate-test\"><span style=\"color: blue\">I am blue</span> text!</div>"
Received: "<div class=\"slate-p slate-test\">I am blue text!</div>"

Environment

Funding

Fund with Polar

tomdyqin commented 10 months ago

and if text has like bold or italic attribute , the color will not strip

tomdyqin commented 10 months ago

@zbeyens can u help this?

seanbruce commented 8 months ago

I've run into this bug too. After view the source code, I find the code of @udecode/plate-font plugin may cause the issue. Comparing code of @udecode/plate-basic-marks:

export const createBoldPlugin = createPluginFactory<ToggleMarkPlugin>({
  key: MARK_BOLD,
  isLeaf: true,
  ...

export const createItalicPlugin = createPluginFactory<ToggleMarkPlugin>({
  key: MARK_ITALIC,
  isLeaf: true,
  ...

and

export const createFontColorPlugin = createPluginFactory({
  key: MARK_COLOR,
  inject: {
    props: {
      nodeKey: MARK_COLOR,
      defaultNodeValue: 'black',
    },
  },

It seems that the createFontColorPlugin function doesn't treat font color as a leaf element

adelsagemilang commented 5 months ago

Same issue here

maayanalgresie commented 1 month ago

@zbeyens, could you let me know if this issue occurs in the latest version? I'm currently using version 36.

zbeyens commented 1 month ago

Not yet fixed