UNPKG

@tiptap/extension-text-style

Version:

text style extension for tiptap

58 lines (53 loc) 2 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')) : typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-text-style"] = {}, global.core)); })(this, (function (exports, core) { 'use strict'; /** * This extension allows you to create text styles. It is required by default * for the `textColor` and `backgroundColor` extensions. * @see https://www.tiptap.dev/api/marks/text-style */ const TextStyle = core.Mark.create({ name: 'textStyle', priority: 101, addOptions() { return { HTMLAttributes: {}, }; }, parseHTML() { return [ { tag: 'span', getAttrs: element => { const hasStyles = element.hasAttribute('style'); if (!hasStyles) { return false; } return {}; }, }, ]; }, renderHTML({ HTMLAttributes }) { return ['span', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, addCommands() { return { removeEmptyTextStyle: () => ({ state, commands }) => { const attributes = core.getMarkAttributes(state, this.type); const hasStyles = Object.entries(attributes).some(([, value]) => !!value); if (hasStyles) { return true; } return commands.unsetMark(this.name); }, }; }, }); exports.TextStyle = TextStyle; exports.default = TextStyle; Object.defineProperty(exports, '__esModule', { value: true }); })); //# sourceMappingURL=index.umd.js.map