mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-28 07:40:13 +08:00
add color support
This commit is contained in:
parent
1fc7a6b37e
commit
b5359a305f
@ -38,6 +38,7 @@ export default {
|
||||
content: `
|
||||
<p>This isn’t highlighted.</s></p>
|
||||
<p><mark>But this one is.</mark></p>
|
||||
<p><mark style="background-color: pink;">And this is highlighted too, but in a different color.</mark></p>
|
||||
`,
|
||||
})
|
||||
},
|
||||
|
@ -13,12 +13,25 @@ declare module '@tiptap/core/src/Editor' {
|
||||
export default new Mark()
|
||||
.name('highlight')
|
||||
.schema(() => ({
|
||||
attrs: {
|
||||
color: {
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
parseDOM: [
|
||||
{
|
||||
tag: 'mark',
|
||||
getAttrs: node => {
|
||||
return {
|
||||
color: (node as HTMLElement).style.backgroundColor,
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
toDOM: () => ['mark', 0],
|
||||
toDOM: node => ['mark', {
|
||||
...node.attrs,
|
||||
style: node.attrs.color && `background-color: ${node.attrs.color};`,
|
||||
}, 0],
|
||||
}))
|
||||
.commands(({ name }) => ({
|
||||
highlight: () => ({ commands }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user