ueberdosis / tiptap

The headless rich text editor framework for web artisans.
https://tiptap.dev
MIT License
26.93k stars 2.24k forks source link

[Bug]: Span style attribute is removed when using TextStyle extension #4690

Open dkani opened 9 months ago

dkani commented 9 months ago

Which packages did you experience the bug in?

TextStyle, TextAlign, Custom

What Tiptap version are you using?

2.1.13

What’s the bug you are facing?

For my requirement I need inline elements instead of block elements to be default so I extended the paragraph extension to return span instead of p but that's conflicting with the TextStyle extension, when I try to change the text alignment it looks good but if I save and reload the page it removes the style attribute and instead adds a parent span. For example, if I have this saved in DB:

<span style='text-align: center;'>Hello</span>

It will be converted to:

<span><span>Hello</span</span>

If I remove the TextStyle extension it works fine. I know text-align would have no affect on span but I am adding display: block and this is just an example.

What browser are you using?

Chrome

Code example

https://codesandbox.io/p/sandbox/eloquent-wilson-7n77ys?file=%2Fsrc%2Findex.js

What did you expect to happen?

To not remove the style attribute from span.

Anything to add? (optional)

No response

Did you update your dependencies?

Are you sponsoring us?

kishanindegene commented 9 months ago

@dkani add this in your config TextStyle.extend({ addAttributes() { return { style: { default: this.options.HTMLAttributes.style } } }, }),

dkani commented 9 months ago

@kishanindegene Thank you for the suggestion, it works.

But do you know how this works overall - like it removes the style attribute from span but allows the color attribute if you have Color extension , is it because the extension adds a global attribute here?

kishanindegene commented 9 months ago

Yes @dkani the color attribute is retained because of the color extension

dkani commented 9 months ago

@kishanindegene Still I see an issue that it adds an empty span, do you know the reason:

<span style='text-align: center;'>Hello</span>

will be changed to:

<span><span style='text-align: center;'>Hello</span></span>

Also, if I have multiple spans it will merge them into one:

<span>Text 1</span><span>Text 2</span><span>Text 3</span>

will be changed to:

<span><span>Text1Text2Text3</span></span>
weekitmo commented 4 months ago

我仍然看到一个问题,它增加了一个空的跨度,你知道原因吗:

<span style='text-align: center;'>Hello</span>

将更改为:

<span><span style='text-align: center;'>Hello</span></span>

此外,如果我有多个跨度,它会将它们合并为一个:

<span>Text 1</span><span>Text 2</span><span>Text 3</span>

将更改为:

<span><span>Text1Text2Text3</span></span>

any progress? @dkani