refactor some attributes to new syntax

This commit is contained in:
Philipp Kühn
2020-10-27 14:53:23 +01:00
parent 77f67bceae
commit ed7d3862b2
3 changed files with 43 additions and 29 deletions

View File

@@ -10,9 +10,13 @@ const OrderedList = createNode({
addAttributes() {
return {
order: {
start: {
default: 1,
rendered: false,
parseHTML: element => ({
start: element.hasAttribute('start')
? parseInt(element.getAttribute('start') || '', 10)
: 1,
}),
},
}
},
@@ -21,19 +25,16 @@ const OrderedList = createNode({
return [
{
tag: 'ol',
getAttrs: node => ({
order: (node as HTMLElement).hasAttribute('start')
? parseInt((node as HTMLElement).getAttribute('start') || '', 10)
: 1,
}),
},
]
},
renderHTML({ node, attributes }) {
return node.attrs.order === 1
? ['ol', attributes, 0]
: ['ol', { ...attributes, start: node.attrs.order }, 0]
renderHTML({ attributes }) {
const { start, ...attributesWithoutStart } = attributes
return start === 1
? ['ol', attributesWithoutStart, 0]
: ['ol', attributes, 0]
},
addCommands() {