tiptap-fs
Version:
Font size extension for Tiptap editor
50 lines (49 loc) • 1.16 kB
JavaScript
// src/index.ts
import { Extension } from "@tiptap/core";
var FontSize = Extension.create({
name: "fontSize",
addOptions() {
return {
types: ["textStyle"]
};
},
addGlobalAttributes() {
return [
{
types: this.options.types,
attributes: {
fontSize: {
default: null,
parseHTML: (element) => {
var _a;
return (_a = element.style.fontSize) == null ? void 0 : _a.replace("px", "");
},
renderHTML: (attributes) => {
if (!attributes.fontSize) {
return {};
}
return {
style: `font-size: ${attributes.fontSize}px`
};
}
}
}
}
];
},
addCommands() {
return {
setFontSize: (fontSize) => ({ chain }) => {
if (fontSize === "default") {
return chain().setMark("textStyle", { fontSize: null }).run();
}
return chain().setMark("textStyle", { fontSize }).run();
}
};
}
});
var index_default = FontSize;
export {
FontSize,
index_default as default
};