mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 22:53:08 +08:00
8014ba3ab7
* #1196/feat: add text background highlight * unify text color * dark mode support * unify text color and highlight * dark mode support for color selector trigger * fix see through in color selector dark mode * fix selection highlight in dark mode * brown color * clean up --------- Co-authored-by: sanua356 <sanek.pankratov356@gmail.com>
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import {
|
|
Highlight as TiptapHighlight,
|
|
type HighlightOptions,
|
|
} from "@tiptap/extension-highlight";
|
|
|
|
export const Highlight = TiptapHighlight.extend<HighlightOptions>({
|
|
addAttributes() {
|
|
return {
|
|
...this.parent?.(),
|
|
color: {
|
|
default: null,
|
|
parseHTML: (element) =>
|
|
element.getAttribute("data-color") || element.style.backgroundColor,
|
|
renderHTML: (attributes) => {
|
|
if (!attributes.color) {
|
|
return {};
|
|
}
|
|
|
|
return {
|
|
"data-color": attributes.color,
|
|
style: `background-color: ${attributes.color}; color: inherit`,
|
|
};
|
|
},
|
|
},
|
|
colorName: {
|
|
default: null,
|
|
parseHTML: (element) =>
|
|
element.getAttribute("data-highlight-color-name") || null,
|
|
renderHTML: (attributes) => {
|
|
if (!attributes.colorName) {
|
|
return {};
|
|
}
|
|
return {
|
|
"data-highlight-color-name": attributes.colorName.toLowerCase(),
|
|
};
|
|
},
|
|
},
|
|
};
|
|
},
|
|
});
|