add basic text align extension

This commit is contained in:
Philipp Kühn
2020-10-23 15:23:40 +02:00
parent ecadf7ea0a
commit 5976d6083c
7 changed files with 134 additions and 30 deletions

View File

@@ -8,36 +8,6 @@ const Paragraph = createNode({
content: 'inline*',
// addGlobalAttributes() {
// return [
// {
// types: ['paragraph'],
// attributes: {
// align: {
// default: 'right',
// renderHTML: attributes => ({
// class: 'foo',
// style: `text-align: ${attributes.align}`,
// }),
// },
// },
// },
// ]
// },
// addAttributes() {
// return {
// id: {
// default: '123',
// rendered: true,
// renderHTML: attributes => ({
// class: 'bar',
// style: 'color: red',
// }),
// },
// }
// },
parseHTML() {
return [
{ tag: 'p' },

View File

@@ -0,0 +1,27 @@
import { createExtension } from '@tiptap/core'
const TextAlign = createExtension({
addGlobalAttributes() {
return [
{
types: ['paragraph'],
attributes: {
align: {
default: 'left',
renderHTML: attributes => ({
style: `text-align: ${attributes.align}`,
}),
},
},
},
]
},
})
export default TextAlign
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
TextAlign: typeof TextAlign,
}
}

View File

@@ -0,0 +1,17 @@
{
"name": "@tiptap/extension-text-align",
"version": "1.0.0",
"source": "index.ts",
"main": "dist/tiptap-extension-text-align.js",
"umd:main": "dist/tiptap-extension-text-align.umd.js",
"module": "dist/tiptap-extension-text-align.mjs",
"unpkg": "dist/tiptap-extension-text-align.js",
"jsdelivr": "dist/tiptap-extension-text-align.js",
"files": [
"src",
"dist"
],
"peerDependencies": {
"@tiptap/core": "2.x"
}
}