add color support
This commit is contained in:
@@ -38,6 +38,7 @@ export default {
|
|||||||
content: `
|
content: `
|
||||||
<p>This isn’t highlighted.</s></p>
|
<p>This isn’t highlighted.</s></p>
|
||||||
<p><mark>But this one is.</mark></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()
|
export default new Mark()
|
||||||
.name('highlight')
|
.name('highlight')
|
||||||
.schema(() => ({
|
.schema(() => ({
|
||||||
|
attrs: {
|
||||||
|
color: {
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
parseDOM: [
|
parseDOM: [
|
||||||
{
|
{
|
||||||
tag: 'mark',
|
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 }) => ({
|
.commands(({ name }) => ({
|
||||||
highlight: () => ({ commands }) => {
|
highlight: () => ({ commands }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user