View as Markdown

API reference

@salmonui/rich-text

130 exported symbols: 1 component, 26 functions, 1 class, 60 interfaces, 38 types and 4 constants. Each name links its page with the signature, docs and members.

import { … } from '@salmonui/rich-text';

Components

  • RichTextContentRead-only rendering of rich text content; root class salmon-rich-text-content.

Functions

  • BlockEditorThe block editor (@salmonui/rich-text); value is Block[] JSON.
  • RichTextEditorRich text editor on ProseMirror (@salmonui/rich-text). HTML value, toolbar, quick toolbars, dialogs, mentions, slash and emoji menus.
  • blocksToHtmlSerializes blocks to sanitized HTML in the shared vocabulary (getDataAsHtml). Block ids are written as data-block-id. Pure and server-safe; unsafe values in th…
  • cleanPastedHtmlCleans clipboard HTML for the editors: Word (mso styles, o:p, conditional comments, MsoListParagraph runs into real nested lists from the mso-list levels, clas…
  • createContentEditableMentionTargetA MentionEditorTarget over a contenteditable element.
  • detectPasteSourceDetects Word (desktop and online) and Google Docs clipboard HTML.
  • embedAllowedWhether an iframe src points at an allowed embed host. embedHosts entries are exact hostnames (www.youtube-nocookie.com) or *.example.com for any subdomain of…
  • escapeAttributeEscapes text for use inside a double-quoted HTML attribute value.
  • escapeHtmlEscapes text for use as HTML element content.
  • findBlockFinds a block by id anywhere in the tree (depth-first, document order).
  • findParentIdId of the block's parent (null at the top level, undefined when not found).
  • forEachBlockCalls fn on every block in document order.
  • htmlToBlocksParses HTML into blocks (parseHtmlToBlocks). The HTML is sanitized first. Ids come from data-block-id; missing or duplicate ids get deterministic ones from the…
  • htmlToTextText content of HTML as the editors count it: the sanitized content, block boundaries become blockSeparator, <br> a newline, table cells are separated by tabs,…
  • insertBlocksInserts blocks before or after the block before / after, or into parent's children at index (default: last). Without a position they go at the end. Returns the…
  • loadRichTextEngineLoads the headless ProseMirror engine on demand: const { createEngine } = await loadRichTextEngine().
  • moveBlockMoves a block (with its children) before or after another block, or into another block's children. Moving a block into itself or its own subtree, or relative t…
  • parseHtmlParses an HTML fragment into a tree. Never throws; malformed input yields the closest well-formed tree. <!DOCTYPE> is skipped, CDATA becomes text.
  • pasteNeedsPromptWhether mode: 'prompt' needs to ask for this paste (formatted HTML; plain text never asks).
  • plainTextToHtmlHTML for plain text (plain-text paste): paragraphs on blank lines, <br> on single newlines, runs of spaces kept as no-break spaces, all text escaped. Empty inp…
  • removeBlocksRemoves the blocks with these ids (with their children).
  • sanitizeHtmlSanitizes HTML against the shared vocabulary. Pure and server-safe: no DOM, no globals, deterministic, linear in the input size. sanitizeHtml(sanitizeHtml(x))…
  • sanitizeNodesSanitizes a parsed tree (see sanitizeHtml); returns a new tree.
  • sanitizeUrlReturns the URL to keep for use, or null when it is not allowed. Leading and trailing whitespace and control characters are trimmed and tabs and newlines remov…
  • serializeHtmlSerializes a parsed (or sanitized) tree back to HTML.
  • updateBlockUpdates one block: props are merged, type, content and children replace; or pass a function returning the new block (its id is kept).

Classes

Interfaces

Types

Constants