UNPKG

nilfam-editor

Version:

A powerful, customizable rich-text editor built with TipTap, React, and Tailwind CSS. Supports RTL/LTR text, resizable media (images/videos), tables, code blocks, font styling, and more for an enhanced content creation experience.

47 lines (41 loc) 1.41 kB
import {Extension} from "@tiptap/core"; export const LineHeightExtension = Extension.create({ name: 'lineHeight', addOptions() { return { types: ['paragraph', 'heading'], defaultLineHeight: '1.5', lineHeights: ['1', '1.15', '1.5', '2', '2.5', '3'], } }, addGlobalAttributes() { return [ { types: this.options.types, attributes: { lineHeight: { default: this.options.defaultLineHeight, parseHTML: element => element.style.lineHeight || this.options.defaultLineHeight, renderHTML: attributes => { if (!attributes.lineHeight) { return {} } return { style: `line-height: ${attributes.lineHeight}`, } }, }, }, }, ] }, addCommands() { return { setLineHeight: (lineHeight) => ({ commands }) => { return this.options.types.every(type => commands.updateAttributes(type, { lineHeight }) ) }, } }, })