add basic text align extension
This commit is contained in:
@@ -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' },
|
||||
|
||||
27
packages/extension-text-align/index.ts
Normal file
27
packages/extension-text-align/index.ts
Normal 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,
|
||||
}
|
||||
}
|
||||
17
packages/extension-text-align/package.json
Normal file
17
packages/extension-text-align/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user