mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 22:36:14 +08:00
add defaultAlignment option to text align extension
This commit is contained in:
parent
2c52f0ce06
commit
b962890de5
@ -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,
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user