mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-24 17:47:50 +08:00
36 lines
670 B
TypeScript
36 lines
670 B
TypeScript
import { createExtension } from '@tiptap/core'
|
|
|
|
type TextAlignOptions = {
|
|
types: string[],
|
|
}
|
|
|
|
const TextAlign = createExtension({
|
|
defaultOptions: <TextAlignOptions>{
|
|
types: ['heading', 'paragraph'],
|
|
},
|
|
|
|
addGlobalAttributes() {
|
|
return [
|
|
{
|
|
types: this.options.types,
|
|
attributes: {
|
|
textAlign: {
|
|
default: 'left',
|
|
renderHTML: attributes => ({
|
|
style: `text-align: ${attributes.textAlign}`,
|
|
}),
|
|
},
|
|
},
|
|
},
|
|
]
|
|
},
|
|
})
|
|
|
|
export default TextAlign
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
interface AllExtensions {
|
|
TextAlign: typeof TextAlign,
|
|
}
|
|
}
|