tiptap-extension-line-height
Version:
A line-height extension for tiptap paragraph.
38 lines (36 loc) • 831 B
JavaScript
import { Extension } from "@tiptap/core";
export default Extension.create({
name: "lineHeight",
addGlobalAttributes() {
return [
{
types: ["paragraph"],
attributes: {
lineHeight: {
default: null,
parseHTML: (element) => element.style.lineHeight,
renderHTML: (attributes) => {
if (!attributes.lineHeight) {
return {};
}
return {
style: `line-height: ${attributes.lineHeight}`,
};
},
},
},
},
];
},
addCommands() {
return {
setLineHeight:
(lineHeight) =>
({ commands }) => {
return commands.updateAttributes("paragraph", {
lineHeight,
});
},
};
},
});