add defaultAlignment option to text align extension

This commit is contained in:
Philipp Kühn 2020-10-27 11:55:13 +01:00
parent 2c52f0ce06
commit b962890de5

View File

@ -3,12 +3,14 @@ import { Command, createExtension } from '@tiptap/core'
type TextAlignOptions = {
types: string[],
alignments: string[],
defaultAlignment: string,
}
const TextAlign = createExtension({
defaultOptions: <TextAlignOptions>{
types: ['heading', 'paragraph'],
alignments: ['left', 'center', 'right'],
defaultAlignment: 'left',
},
addGlobalAttributes() {
@ -17,12 +19,12 @@ const TextAlign = createExtension({
types: this.options.types,
attributes: {
textAlign: {
default: 'left',
default: this.options.defaultAlignment,
renderHTML: attributes => ({
style: `text-align: ${attributes.textAlign}`,
}),
parseHTML: node => ({
textAlign: node.style.textAlign || 'left',
parseHTML: element => ({
textAlign: element.style.textAlign || this.options.defaultAlignment,
}),
},
},