{"version":3,"sources":["../../../src/pm/html-string/index.ts","../../../src/pm/extensionRenderer.ts","../../../src/helpers.ts","../../../src/json/renderer.ts","../../../src/json/html-string/string.ts","../../../src/pm/html-string/html-string.ts"],"sourcesContent":["export * from '../extensionRenderer.js'\nexport * from './html-string.js'\n","/* oslint-disable no-plusplus */\n/* oslint-disableno-explicit-any */\n\nimport type {\n  ExtensionAttribute,\n  Extensions,\n  JSONContent,\n  Mark as MarkExtension,\n  MarkConfig,\n  Node as NodeExtension,\n  NodeConfig,\n} from '@tiptap/core'\nimport {\n  extensions as coreExtensions,\n  getAttributesFromExtensions,\n  getExtensionField,\n  getSchemaByResolvedExtensions,\n  resolveExtensions,\n  splitExtensions,\n} from '@tiptap/core'\nimport type { DOMOutputSpec, Mark } from '@tiptap/pm/model'\nimport { Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport type { MarkProps, NodeProps, TiptapStaticRendererOptions } from '../json/renderer.js'\n\nexport type DomOutputSpecToElement<T> = (content: DOMOutputSpec) => (children?: T | T[]) => T\n\n/**\n * Options that mirror a subset of `EditorOptions` and affect rendered output.\n * Kept narrow on purpose: only options whose effect is reproducible without an\n * `Editor` instance belong here.\n */\nexport type StaticEditorOptions = {\n  /**\n   * Sets the text direction for all non-text nodes. Matches the `textDirection`\n   * editor option on `Editor`. The configured `TextDirection` extension is\n   * prepended to the user-supplied `extensions`; if a user-supplied\n   * `TextDirection` is also present, the user's wins (last-defined precedence —\n   * same as Editor).\n   */\n  textDirection?: 'ltr' | 'rtl' | 'auto'\n}\n\n/**\n * Apply editor-level options to the user's extension array.\n *\n * Mirrors `new Editor({ textDirection })`: the option-driven `TextDirection`\n * extension is prepended so a user-supplied `TextDirection` (which comes after)\n * can override it via tiptap's last-defined precedence for duplicate extensions.\n *\n * Known limitation: this only inspects top-level extensions. A `TextDirection`\n * bundled inside a kit (e.g. `StarterKit`) is not detected for override\n * purposes — today no shipped kit includes `TextDirection`, so this is purely\n * theoretical.\n */\nexport function applyStaticEditorOptionsToExtensions(\n  extensions: Extensions,\n  options?: StaticEditorOptions,\n): Extensions {\n  if (!options?.textDirection) {\n    return extensions\n  }\n\n  return [\n    coreExtensions.TextDirection.configure({ direction: options.textDirection }),\n    ...extensions,\n  ]\n}\n\n/**\n * This takes a NodeExtension and maps it to a React component\n * @param extension The node extension to map to a React component\n * @param extensionAttributes All available extension attributes\n * @returns A tuple with the name of the extension and a React component that renders the extension\n */\nexport function mapNodeExtensionToReactNode<T>(\n  domOutputSpecToElement: DomOutputSpecToElement<T>,\n  extension: NodeExtension,\n  extensionAttributes: ExtensionAttribute[],\n  options?: Partial<Pick<TiptapStaticRendererOptions<T, Mark, Node>, 'unhandledNode'>>,\n): [string, (props: NodeProps<Node, T | T[]>) => T] {\n  const context = {\n    name: extension.name,\n    options: extension.options,\n    storage: extension.storage,\n    parent: extension.parent,\n  }\n\n  const renderToHTML = getExtensionField<NodeConfig['renderHTML']>(extension, 'renderHTML', context)\n\n  if (!renderToHTML) {\n    if (options?.unhandledNode) {\n      return [extension.name, options.unhandledNode]\n    }\n    return [\n      extension.name,\n      () => {\n        throw new Error(\n          `[tiptap error]: Node ${extension.name} cannot be rendered, it is missing a \"renderToHTML\" method, please implement it or override the corresponding \"nodeMapping\" method to have a custom rendering`,\n        )\n      },\n    ]\n  }\n\n  return [\n    extension.name,\n    ({ node, children }) => {\n      try {\n        return domOutputSpecToElement(\n          renderToHTML({\n            node,\n            HTMLAttributes: getHTMLAttributes(node, extensionAttributes),\n          }),\n        )(children)\n      } catch (e) {\n        throw new Error(\n          `[tiptap error]: Node ${\n            extension.name\n          } cannot be rendered, it's \"renderToHTML\" method threw an error: ${(e as Error).message}`,\n          { cause: e },\n        )\n      }\n    },\n  ]\n}\n\n/**\n * This takes a MarkExtension and maps it to a React component\n * @param extension The mark extension to map to a React component\n * @param extensionAttributes All available extension attributes\n * @returns A tuple with the name of the extension and a React component that renders the extension\n */\nexport function mapMarkExtensionToReactNode<T>(\n  domOutputSpecToElement: DomOutputSpecToElement<T>,\n  extension: MarkExtension,\n  extensionAttributes: ExtensionAttribute[],\n  options?: Partial<Pick<TiptapStaticRendererOptions<T, Mark, Node>, 'unhandledMark'>>,\n): [string, (props: MarkProps<Mark, T | T[]>) => T] {\n  const context = {\n    name: extension.name,\n    options: extension.options,\n    storage: extension.storage,\n    parent: extension.parent,\n  }\n\n  const renderToHTML = getExtensionField<MarkConfig['renderHTML']>(extension, 'renderHTML', context)\n\n  if (!renderToHTML) {\n    if (options?.unhandledMark) {\n      return [extension.name, options.unhandledMark]\n    }\n    return [\n      extension.name,\n      () => {\n        throw new Error(\n          `Node ${extension.name} cannot be rendered, it is missing a \"renderToHTML\" method`,\n        )\n      },\n    ]\n  }\n\n  return [\n    extension.name,\n    ({ mark, children }) => {\n      try {\n        return domOutputSpecToElement(\n          renderToHTML({\n            mark,\n            HTMLAttributes: getHTMLAttributes(mark, extensionAttributes),\n          }),\n        )(children)\n      } catch (e) {\n        throw new Error(\n          `[tiptap error]: Mark ${\n            extension.name\n          } cannot be rendered, it's \"renderToHTML\" method threw an error: ${(e as Error).message}`,\n          { cause: e },\n        )\n      }\n    },\n  ]\n}\n\n/**\n * This function will statically render a Prosemirror Node to a target element type using the given extensions\n * @param renderer The renderer to use to render the Prosemirror Node to the target element type\n * @param domOutputSpecToElement A function that takes a Prosemirror DOMOutputSpec and returns a function that takes children and returns the target element type\n * @param mapDefinedTypes An object with functions to map the doc and text types to the target element type\n * @param content The Prosemirror Node to render\n * @param extensions The extensions to use to render the Prosemirror Node\n * @param options Additional options to pass to the renderer that can override the default behavior\n * @returns The rendered target element type\n */\nexport function renderToElement<T>({\n  renderer,\n  domOutputSpecToElement,\n  mapDefinedTypes,\n  content,\n  extensions,\n  options,\n}: {\n  renderer: (options: TiptapStaticRendererOptions<T, Mark, Node>) => (ctx: { content: Node }) => T\n  domOutputSpecToElement: DomOutputSpecToElement<T>\n  mapDefinedTypes: {\n    doc: (props: NodeProps<Node, T | T[]>) => T\n    text: (props: NodeProps<Node, T | T[]>) => T\n  }\n  content: Node | JSONContent\n  extensions: Extensions\n  options?: Partial<TiptapStaticRendererOptions<T, Mark, Node>>\n}): T {\n  // get all extensions in order & split them into nodes and marks\n  extensions = resolveExtensions(extensions)\n  const extensionAttributes = getAttributesFromExtensions(extensions)\n  const { nodeExtensions, markExtensions } = splitExtensions(extensions)\n\n  if (!(content instanceof Node)) {\n    content = Node.fromJSON(getSchemaByResolvedExtensions(extensions), content)\n  }\n\n  return renderer({\n    ...options,\n    nodeMapping: {\n      ...Object.fromEntries(\n        nodeExtensions\n          .filter(e => {\n            if (e.name in mapDefinedTypes) {\n              // These are predefined types that we don't need to map\n              return false\n            }\n            // No need to generate mappings for nodes that are already mapped\n            if (options?.nodeMapping) {\n              return !(e.name in options.nodeMapping)\n            }\n            return true\n          })\n          .map(nodeExtension =>\n            mapNodeExtensionToReactNode<T>(\n              domOutputSpecToElement,\n              nodeExtension,\n              extensionAttributes,\n              options,\n            ),\n          ),\n      ),\n      ...mapDefinedTypes,\n      ...options?.nodeMapping,\n    },\n    markMapping: {\n      ...Object.fromEntries(\n        markExtensions\n          .filter(e => {\n            // No need to generate mappings for marks that are already mapped\n            if (options?.markMapping) {\n              return !(e.name in options.markMapping)\n            }\n            return true\n          })\n          .map(mark =>\n            mapMarkExtensionToReactNode<T>(\n              domOutputSpecToElement,\n              mark,\n              extensionAttributes,\n              options,\n            ),\n          ),\n      ),\n      ...options?.markMapping,\n    },\n  })({ content })\n}\n","/* oslint-disableno-explicit-any */\nimport {\n  type ExtensionAttribute,\n  type MarkType,\n  type NodeType,\n  mergeAttributes,\n} from '@tiptap/core'\n\n/**\n * This function returns the attributes of a node or mark that are defined by the given extension attributes.\n * @param nodeOrMark The node or mark to get the attributes from\n * @param extensionAttributes The extension attributes to use\n * @param onlyRenderedAttributes If true, only attributes that are rendered in the HTML are returned\n */\nexport function getAttributes(\n  nodeOrMark: NodeType | MarkType,\n  extensionAttributes: ExtensionAttribute[],\n  onlyRenderedAttributes?: boolean,\n): Record<string, any> {\n  const nodeOrMarkAttributes = nodeOrMark.attrs\n\n  if (!nodeOrMarkAttributes) {\n    return {}\n  }\n\n  return extensionAttributes\n    .filter(item => {\n      if (\n        item.type !== (typeof nodeOrMark.type === 'string' ? nodeOrMark.type : nodeOrMark.type.name)\n      ) {\n        return false\n      }\n      if (onlyRenderedAttributes) {\n        return item.attribute.rendered\n      }\n      return true\n    })\n    .map(item => {\n      if (!item.attribute.renderHTML) {\n        return {\n          [item.name]:\n            item.name in nodeOrMarkAttributes\n              ? nodeOrMarkAttributes[item.name]\n              : item.attribute.default,\n        }\n      }\n\n      return (\n        item.attribute.renderHTML(nodeOrMarkAttributes) || {\n          [item.name]:\n            item.name in nodeOrMarkAttributes\n              ? nodeOrMarkAttributes[item.name]\n              : item.attribute.default,\n        }\n      )\n    })\n    .reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})\n}\n\n/**\n * This function returns the HTML attributes of a node or mark that are defined by the given extension attributes.\n * @param nodeOrMark The node or mark to get the attributes from\n * @param extensionAttributes The extension attributes to use\n */\nexport function getHTMLAttributes(\n  nodeOrMark: NodeType | MarkType,\n  extensionAttributes: ExtensionAttribute[],\n) {\n  return getAttributes(nodeOrMark, extensionAttributes, true)\n}\n","/* oslint-disableno-explicit-any */\nimport type { JSONContent } from '@tiptap/core'\n\n/**\n * A JSON representation of a mark (a Tiptap/ProseMirror mark serialized to JSON).\n */\nexport type JSONMarkType = NonNullable<JSONContent['marks']>[number]\n\n/**\n * A JSON representation of a node (a Tiptap/ProseMirror node serialized to JSON).\n *\n * `marks` is tied to the `TMark` type parameter so the node<->mark relationship\n * stays sound. This is also why we cannot simply default `TNodeType` to\n * `JSONContent`: the generic constraint references `TMarkType` via\n * `marks?: readonly TMarkType[]`, and `JSONContent.marks` is a *concrete* array,\n * which TypeScript rejects (\"TMarkType could be instantiated with a different\n * subtype of constraint\"). Parameterizing the node type by the same `TMark`\n * avoids that bivariance error. Please don't \"simplify\" this back to\n * `JSONContent` — it won't type-check.\n */\nexport type JSONNodeType<TMark extends { type: string | { name: string } } = JSONMarkType> = {\n  type?: string\n  attrs?: Record<string, any>\n  content?: JSONNodeType<TMark>[]\n  marks?: readonly TMark[]\n  text?: string\n  [key: string]: any\n}\n\n/**\n * Props for a node renderer\n */\nexport type NodeProps<TNodeType = any, TChildren = any> = {\n  /**\n   * The current node to render\n   */\n  node: TNodeType\n  /**\n   * Unless the node is the root node, this will always be defined\n   */\n  parent?: TNodeType\n  /**\n   * The children of the current node\n   */\n  children?: TChildren\n  /**\n   * Render a child element\n   */\n  renderElement: (props: {\n    /**\n     * Tiptap JSON content to render\n     */\n    content: TNodeType\n    /**\n     * The parent node of the current node\n     */\n    parent?: TNodeType\n  }) => TChildren\n}\n\n/**\n * Props for a mark renderer\n */\nexport type MarkProps<TMarkType = any, TChildren = any, TNodeType = any> = {\n  /**\n   * The current mark to render\n   */\n  mark: TMarkType\n  /**\n   * The children of the current mark\n   */\n  children?: TChildren\n  /**\n   * The node the current mark is applied to\n   */\n  node: TNodeType\n  /**\n   * The node the current mark is applied to\n   */\n  parent?: TNodeType\n}\n\nexport type TiptapStaticRendererOptions<\n  /**\n   * The return type of the render function (e.g. React.ReactNode, string)\n   */\n  TReturnType,\n  /**\n   * A mark type is either a JSON representation of a mark or a Prosemirror mark instance\n   */\n  TMarkType extends { type: any } = JSONMarkType,\n  /**\n   * A node type is either a JSON representation of a node or a Prosemirror node instance\n   */\n  TNodeType extends {\n    content?: { forEach: (cb: (node: TNodeType) => void) => void }\n    marks?: readonly TMarkType[]\n    type?: string | { name: string }\n  } = JSONNodeType<TMarkType>,\n  /**\n   * A node renderer is a function that takes a node and its children and returns the rendered output\n   */\n  TNodeRender extends (ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>) => TReturnType = (\n    ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>,\n  ) => TReturnType,\n  /**\n   * A mark renderer is a function that takes a mark and its children and returns the rendered output\n   */\n  TMarkRender extends (\n    ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>,\n  ) => TReturnType = (\n    ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>,\n  ) => TReturnType,\n> = {\n  /**\n   * Mapping of node types to react components\n   */\n  nodeMapping: Record<string, NoInfer<TNodeRender>>\n  /**\n   * Mapping of mark types to react components\n   */\n  markMapping: Record<string, NoInfer<TMarkRender>>\n  /**\n   * Component to render if a node type is not handled\n   */\n  unhandledNode?: NoInfer<TNodeRender>\n  /**\n   * Component to render if a mark type is not handled\n   */\n  unhandledMark?: NoInfer<TMarkRender>\n}\n\n/**\n * Tiptap Static Renderer\n * ----------------------\n *\n * This function is a basis to allow for different renderers to be created.\n * Generic enough to be able to statically render Prosemirror JSON or Prosemirror Nodes.\n *\n * Using this function, you can create a renderer that takes a JSON representation of a Prosemirror document\n * and renders it using a mapping of node types to React components or even to a string.\n * This function is used as the basis to create the `reactRenderer` and `stringRenderer` functions.\n */\nexport function TiptapStaticRenderer<\n  /**\n   * The return type of the render function (e.g. React.ReactNode, string)\n   */\n  TReturnType,\n  /**\n   * A mark type is either a JSON representation of a mark or a Prosemirror mark instance\n   */\n  TMarkType extends { type: string | { name: string } } = JSONMarkType,\n  /**\n   * A node type is either a JSON representation of a node or a Prosemirror node instance\n   */\n  TNodeType extends {\n    content?: { forEach: (cb: (node: TNodeType) => void) => void }\n    marks?: readonly TMarkType[]\n    type?: string | { name: string }\n  } = JSONNodeType<TMarkType>,\n  /**\n   * A node renderer is a function that takes a node and its children and returns the rendered output\n   */\n  TNodeRender extends (ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>) => TReturnType = (\n    ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>,\n  ) => TReturnType,\n  /**\n   * A mark renderer is a function that takes a mark and its children and returns the rendered output\n   */\n  TMarkRender extends (\n    ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>,\n  ) => TReturnType = (\n    ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>,\n  ) => TReturnType,\n>(\n  /**\n   * The function that actually renders the component\n   */\n  renderComponent: (\n    ctx:\n      | {\n          component: TNodeRender\n          props: NodeProps<TNodeType, TReturnType | TReturnType[]>\n        }\n      | {\n          component: TMarkRender\n          props: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>\n        },\n  ) => TReturnType,\n  {\n    nodeMapping,\n    markMapping,\n    unhandledNode,\n    unhandledMark,\n  }: TiptapStaticRendererOptions<TReturnType, TMarkType, TNodeType, TNodeRender, TMarkRender>,\n) {\n  /**\n   * Render Tiptap JSON and all its children using the provided node and mark mappings.\n   */\n  return function renderContent({\n    content,\n    parent,\n  }: {\n    /**\n     * Tiptap JSON content to render\n     */\n    content: TNodeType\n    /**\n     * The parent node of the current node\n     */\n    parent?: TNodeType\n  }): TReturnType {\n    const nodeType = typeof content.type === 'string' ? content.type : (content.type?.name ?? '')\n    const NodeHandler = nodeMapping[nodeType] ?? unhandledNode\n\n    if (!NodeHandler) {\n      throw new Error(`missing handler for node type ${nodeType}`)\n    }\n\n    const nodeContent = renderComponent({\n      component: NodeHandler,\n      props: {\n        node: content,\n        parent,\n        renderElement: renderContent,\n        // Lazily compute the children to avoid unnecessary recursion\n        get children() {\n          // recursively render child content nodes\n          const children: TReturnType[] = []\n\n          if (content.content) {\n            content.content.forEach(child => {\n              children.push(\n                renderContent({\n                  content: child,\n                  parent: content,\n                }),\n              )\n            })\n          }\n\n          return children\n        },\n      },\n    })\n\n    // apply marks to the content\n    const markedContent = content.marks\n      ? content.marks.reduce((acc, mark) => {\n          const markType = typeof mark.type === 'string' ? mark.type : mark.type.name\n          const MarkHandler = markMapping[markType] ?? unhandledMark\n\n          if (!MarkHandler) {\n            throw new Error(`missing handler for mark type ${markType}`)\n          }\n\n          return renderComponent({\n            component: MarkHandler,\n            props: {\n              mark,\n              parent,\n              node: content,\n              children: acc,\n            },\n          })\n        }, nodeContent)\n      : nodeContent\n\n    return markedContent\n  }\n}\n","/* oslint-disableno-explicit-any */\nimport type { JSONMarkType, JSONNodeType, TiptapStaticRendererOptions } from '../renderer.js'\nimport { TiptapStaticRenderer } from '../renderer.js'\n\nexport function renderJSONContentToString<\n  /**\n   * A mark type is either a JSON representation of a mark or a Prosemirror mark instance\n   */\n  TMarkType extends { type: any } = JSONMarkType,\n  /**\n   * A node type is either a JSON representation of a node or a Prosemirror node instance\n   */\n  TNodeType extends {\n    content?: { forEach: (cb: (node: TNodeType) => void) => void }\n    marks?: readonly TMarkType[]\n    type?: string | { name: string }\n  } = JSONNodeType<TMarkType>,\n>(options: TiptapStaticRendererOptions<string, TMarkType, TNodeType>) {\n  return TiptapStaticRenderer(ctx => {\n    return ctx.component(ctx.props as any)\n  }, options)\n}\n\n/**\n * Escape text for HTML text content.\n * @param value The text to escape\n * @returns The escaped text\n */\nexport function escapeHTML(value: string): string {\n  return value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n}\n\n/**\n * Escape values for quoted HTML attributes.\n * @param value The attribute value to escape\n * @returns The escaped attribute value\n */\nexport function escapeHTMLAttribute(value: string): string {\n  return escapeHTML(value).replace(/\"/g, '&quot;')\n}\n\n/**\n * Serialize the attributes of a node or mark to a string\n * @param attrs The attributes to serialize\n * @returns The serialized attributes as a string\n */\nexport function serializeAttrsToHTMLString(attrs: Record<string, any> | undefined | null): string {\n  // Match ProseMirror's DOMSerializer.renderSpec, which omits null/undefined attribute\n  // values rather than stringifying them — otherwise we emit attrs like class=\"null\".\n  const output = Object.entries(attrs || {})\n    .filter(([, value]) => value != null)\n    .map(([key, value]) => `${key.split(' ').at(-1)}=\"${escapeHTMLAttribute(String(value))}\"`)\n    .join(' ')\n\n  return output ? ` ${output}` : ''\n}\n\n/**\n * Serialize the children of a node or mark to a string\n * @param children The children to serialize\n * @returns The serialized children as a string\n */\nexport function serializeChildrenToHTMLString(children?: string | string[]): string {\n  return ([] as string[])\n    .concat(children || '')\n    .filter(Boolean)\n    .join('')\n}\n","/* oslint-disableno-explicit-any */\nimport type { DOMOutputSpecArray, Extensions, JSONContent } from '@tiptap/core'\nimport type { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport {\n  escapeHTML,\n  renderJSONContentToString,\n  serializeAttrsToHTMLString,\n  serializeChildrenToHTMLString,\n} from '../../json/html-string/string.js'\nimport type { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport type { StaticEditorOptions } from '../extensionRenderer.js'\nimport { applyStaticEditorOptionsToExtensions, renderToElement } from '../extensionRenderer.js'\n\nexport {\n  serializeAttrsToHTMLString,\n  serializeChildrenToHTMLString,\n} from '../../json/html-string/string.js'\n\n/**\n * HTML elements that cannot be self-closing and must always have a closing tag.\n * These elements must be rendered as <tag></tag> even when empty, not <tag />.\n */\nconst NON_SELF_CLOSING_TAGS = new Set([\n  'iframe',\n  'script',\n  'style',\n  'title',\n  'textarea',\n  'div',\n  'span',\n  'a',\n  'button',\n])\n\n/**\n * Take a DOMOutputSpec and return a function that can render it to a string\n * @param content The DOMOutputSpec to convert to a string\n * @returns A function that can render the DOMOutputSpec to a string\n */\nexport function domOutputSpecToHTMLString(\n  content: DOMOutputSpec,\n): (children?: string | string[]) => string {\n  if (typeof content === 'string') {\n    return () => escapeHTML(content)\n  }\n  if (typeof content === 'object' && 'length' in content) {\n    const [_tag, attrs, children, ...rest] = content as DOMOutputSpecArray\n    let tag = _tag\n    const parts = tag.split(' ')\n\n    if (parts.length > 1) {\n      tag = `${parts[1]} xmlns=\"${parts[0]}\"`\n    }\n\n    if (attrs === undefined) {\n      return () => `<${tag}/>`\n    }\n    if (attrs === 0) {\n      return child => `<${tag}>${serializeChildrenToHTMLString(child)}</${tag}>`\n    }\n    if (typeof attrs === 'object') {\n      if (Array.isArray(attrs)) {\n        if (children === undefined) {\n          return child =>\n            `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n        }\n        if (children === 0) {\n          return child =>\n            `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n        }\n        return child =>\n          `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}${[children]\n            .concat(rest)\n            .map(a => domOutputSpecToHTMLString(a)(child))}</${tag}>`\n      }\n      if (children === undefined) {\n        if (NON_SELF_CLOSING_TAGS.has(tag)) {\n          return () => `<${tag}${serializeAttrsToHTMLString(attrs)}></${tag}>`\n        }\n        return () => `<${tag}${serializeAttrsToHTMLString(attrs)}/>`\n      }\n      if (children === 0) {\n        return child =>\n          `<${tag}${serializeAttrsToHTMLString(attrs)}>${serializeChildrenToHTMLString(child)}</${tag}>`\n      }\n\n      return child =>\n        `<${tag}${serializeAttrsToHTMLString(attrs)}>${[children]\n          .concat(rest)\n          .map(a => domOutputSpecToHTMLString(a)(child))\n          .join('')}</${tag}>`\n    }\n  }\n\n  // TODO support DOM elements? How to handle them?\n  throw new Error(\n    '[tiptap error]: Unsupported DomOutputSpec type, check the `renderHTML` method output or implement a node mapping',\n    {\n      cause: content,\n    },\n  )\n}\n\n/**\n * This function will statically render a Prosemirror Node to HTML using the provided extensions and options.\n *\n * Limitations: this function builds the schema and runs each extension's\n * `renderHTML`, but does not instantiate an `Editor`. Extensions that mutate\n * the document inside `addProseMirrorPlugins`, `onCreate`, or transaction\n * hooks will not run. For UniqueID, pre-process the JSON with\n * `generateUniqueIds` from `@tiptap/extension-unique-id`; for TableOfContents,\n * pre-process with `generateTocIds` from `@tiptap/extension-table-of-contents`.\n *\n * @param content The content to render to HTML\n * @param extensions The extensions to use for rendering\n * @param staticEditorOptions Optional editor-level options that affect rendered output, currently `{ textDirection }`. Mirrors a subset of `EditorOptions`.\n * @param options The options to use for rendering\n * @returns The rendered HTML string\n */\nexport function renderToHTMLString({\n  content,\n  extensions,\n  staticEditorOptions,\n  options,\n}: {\n  content: Node | JSONContent\n  extensions: Extensions\n  staticEditorOptions?: StaticEditorOptions\n  options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}): string {\n  return renderToElement<string>({\n    renderer: renderJSONContentToString,\n    domOutputSpecToElement: domOutputSpecToHTMLString,\n    mapDefinedTypes: {\n      // Map a doc node to concatenated children\n      doc: ({ children }) => serializeChildrenToHTMLString(children),\n      // Map a text node to its text content\n      text: ({ node }) => escapeHTML(node.text ?? ''),\n    },\n    content,\n    extensions: applyStaticEditorOptionsToExtensions(extensions, staticEditorOptions),\n    options,\n  })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYA,IAAAA,eAOO;AAEP,mBAAqB;;;ACpBrB,kBAKO;AAQA,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI,CAAC,sBAAsB;AACzB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,oBACJ,OAAO,UAAQ;AACd,QACE,KAAK,UAAU,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO,WAAW,KAAK,OACvF;AACA,aAAO;AAAA,IACT;AACA,QAAI,wBAAwB;AAC1B,aAAO,KAAK,UAAU;AAAA,IACxB;AACA,WAAO;AAAA,EACT,CAAC,EACA,IAAI,UAAQ;AACX,QAAI,CAAC,KAAK,UAAU,YAAY;AAC9B,aAAO;AAAA,QACL,CAAC,KAAK,IAAI,GACR,KAAK,QAAQ,uBACT,qBAAqB,KAAK,IAAI,IAC9B,KAAK,UAAU;AAAA,MACvB;AAAA,IACF;AAEA,WACE,KAAK,UAAU,WAAW,oBAAoB,KAAK;AAAA,MACjD,CAAC,KAAK,IAAI,GACR,KAAK,QAAQ,uBACT,qBAAqB,KAAK,IAAI,IAC9B,KAAK,UAAU;AAAA,IACvB;AAAA,EAEJ,CAAC,EACA,OAAO,CAAC,YAAY,kBAAc,6BAAgB,YAAY,SAAS,GAAG,CAAC,CAAC;AACjF;AAOO,SAAS,kBACd,YACA,qBACA;AACA,SAAO,cAAc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