mui-tiptap
Version:
A Material-UI (MUI) styled WYSIWYG rich text editor, using Tiptap
52 lines (51 loc) • 1.66 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
/// <reference types="@tiptap/extension-text-style" />
const core_1 = require("@tiptap/core");
/**
* Allow for setting the font size of text. Requires the TextStyle extension
* https://tiptap.dev/api/marks/text-style, as Tiptap suggests.
*/
const FontSize = core_1.Extension.create({
name: "fontSize",
addOptions() {
return {
types: ["textStyle"],
};
},
addGlobalAttributes() {
return [
{
types: this.options.types,
attributes: {
fontSize: {
default: null,
parseHTML: (element) => element.style.fontSize.replace(/['"]+/g, ""),
renderHTML: (attributes) => {
if (!attributes.fontSize) {
return {};
}
return {
style: `font-size: ${attributes.fontSize}`,
};
},
},
},
},
];
},
addCommands() {
return {
setFontSize: (fontSize) => ({ chain }) => {
return chain().setMark("textStyle", { fontSize }).run();
},
unsetFontSize: () => ({ chain }) => {
return chain()
.setMark("textStyle", { fontSize: null })
.removeEmptyTextStyle()
.run();
},
};
},
});
exports.default = FontSize;
;