ueberdosis / tiptap

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

Color extension allows variables inside #3198

Open nucleartux opened 1 year ago

nucleartux commented 1 year ago

What’s the bug you are facing?

If you paste text which contains for example color: --somevar tiptap will insert this as is.

Which browser was this experienced in? Are any special extensions installed?

Any browser, color extension

How can we reproduce the bug on our side?

Select text from source, my example was from reddit site:

image

Problem in little grey dot inside this header. It contains color: var(--newCommunityTheme-metaText

Can you provide a CodeSandbox?

No response

What did you expect to happen?

All non color text should be removed.

Anything to add? (optional)

I used such solution:

const colorRegxp =
  /(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\b|(?:rgb|hsl)a?\([^\)]*\)/gi;

...

Color.configure({
                  types: ["textStyle"],
                }).extend({
                  addGlobalAttributes: function () {
                    return [
                      {
                        types: this.options.types,
                        attributes: {
                          color: {
                            default: null,
                            parseHTML: (element) =>
                              element.style.color
                                ?.replace(/['"]+/g, "")
                                .match(colorRegxp)?.[0],
                            renderHTML: (attributes) => {
                              if (!attributes.color) {
                                return {};
                              }

                              return {
                                style: `color: ${attributes.color}`,
                              };
                            },
                          },
                        },
                      },
                    ];
                  },
                })

Did you update your dependencies?

Are you sponsoring us?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

nucleartux commented 1 year ago

I think issue is still actual

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

nucleartux commented 1 year ago

Bump

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

nucleartux commented 1 year ago

Bump