@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
34 lines (31 loc) • 989 B
text/typescript
import { Extension } from "@tiptap/core";
export const TextAlignmentExtension = Extension.create({
name: "textAlignment",
addGlobalAttributes() {
return [
{
// Generally text alignment is handled through props using the custom
// blocks API. Tables are the only blocks that are created as TipTap
// nodes and ported to blocks, so we need to add text alignment in a
// separate extension.
types: ["tableCell", "tableHeader"],
attributes: {
textAlignment: {
default: "left",
parseHTML: (element) => {
return element.getAttribute("data-text-alignment");
},
renderHTML: (attributes) => {
if (attributes.textAlignment === "left") {
return {};
}
return {
"data-text-alignment": attributes.textAlignment,
};
},
},
},
},
];
},
});