/** * Full TipTap extension set matching the real Docmost document schema. * * The default StarterKit-only schema silently destroys Docmost-specific * nodes (callout, table) and drops attributes it does not know about * (node ids, image sizing, link targets). Every code path that converts * to or from ProseMirror JSON must use THIS set, otherwise a round-trip * loses content. */ import StarterKit from "@tiptap/starter-kit"; import Image from "@tiptap/extension-image"; import TaskList from "@tiptap/extension-task-list"; import TaskItem from "@tiptap/extension-task-item"; import Highlight from "@tiptap/extension-highlight"; import Subscript from "@tiptap/extension-subscript"; import Superscript from "@tiptap/extension-superscript"; import { Node, Extension, Mark } from "@tiptap/core"; // Inlined from @tiptap/core's getStyleProperty (added after 3.20.x) so this // package can stay on the same @tiptap/core version as the editor and avoid a // duplicate-tiptap version split in the monorepo. Reads a single declaration // from an element's inline `style` attribute, last-wins, case-insensitive. function getStyleProperty(element, propertyName) { const styleAttr = element.getAttribute("style"); if (!styleAttr) { return null; } const decls = styleAttr.split(";").map((decl) => decl.trim()).filter(Boolean); const target = propertyName.toLowerCase(); for (let i = decls.length - 1; i >= 0; i -= 1) { const decl = decls[i]; const colonIndex = decl.indexOf(":"); if (colonIndex === -1) { continue; } const prop = decl.slice(0, colonIndex).trim().toLowerCase(); if (prop === target) { return decl.slice(colonIndex + 1).trim(); } } return null; } /** Allowed Docmost callout types; anything else falls back to "info". */ const CALLOUT_TYPES = ["info", "warning", "danger", "success"]; export const clampCalloutType = (value) => value && CALLOUT_TYPES.includes(value.toLowerCase()) ? value.toLowerCase() : "info"; /** * Allowlist guard for CSS color values imported from HTML. * * Docmost interpolates stored mark colors straight into an inline style * attribute (e.g. style="background-color: ${color}" / "color: ${color}"). * An unsanitized value such as `red; --x: url(...)` or `red">