Skip to main content

Crate devup_editor_html

Crate devup_editor_html 

Source
Expand description

HTML ↔ devup_editor_core::Document conversion for the devup editor.

Implements [DocumentExport] and [DocumentImport] from devup-editor-core, plus a clipboard-oriented API (blocks_to_html / html_to_copied_blocks) that mirrors the behaviour of the React TypeScript clipboardHtml.ts exactly so clipboard interop with Word / Notion / Google Docs keeps working.

§Structural support

Export and import both cover:

  • Headings (h1–h6)
  • Paragraphs (p)
  • Quotes (blockquote)
  • Pre / code (language class preserved)
  • Unordered & ordered lists (with nested indent tracking)
  • Todo lists (via <ul data-devup-type="todo"> marker OR <input type="checkbox"> heuristic OR Notion <ul class="to-do-list">)
  • Dividers (hr)
  • Toggle blocks: <details><summary>, Notion <ul class="toggle">, plus Notion v3’s <li>-with-multiple-block-children heuristic
  • Tables: colspan, rowspan, <colgroup> widths, cell / row / table styling via data-devup-props marker and inline style=""

Marks on export wrap text in <strong>, <em>, <u>, <s>, <code>, <a href="…" rel="noopener noreferrer">, and <span style="color:…"> / <span style="background-color:…"> for color / highlight. Unknown mark types survive via a <span data-mark="type"> fallback so copy never silently drops text.

§Clipboard-specific features

The clipboard module provides:

  • encode_props / decode_props — base64+JSON round-trip marker (data-devup-props="…") for lossless devup→devup copy/paste of table prop maps.
  • clean_html — strips Word / HWP preprocessing artifacts (<!--StartFragment-->, <o:p> tags) before parsing.

See CopiedBlocks for the clipboard subtree shape used by the React layer.

Structs§

CopiedBlocks
Subtree bundle produced by crate::html_to_copied_blocks and consumed by crate::blocks_to_html.
Html
Marker type carrying the DocumentExport / DocumentImport impls for HTML.

Enums§

HtmlError

Functions§

blocks_to_html
Clipboard-oriented serialiser. Mirrors the React blocksToHtml: emits toggle blocks in Notion’s canonical nested format and consumes indent-based siblings as toggle children.
clean_html
Strip Microsoft / HWP preprocessing artifacts that would otherwise confuse the HTML parser. Safe to call on arbitrary input including multi-byte UTF-8.
copied_blocks_to_html
Convenience for the WASM boundary: accepts CopiedBlocks directly.
decode_props
Decode the data-devup-props marker back into a props map.
document_to_copied_blocks
Promote a flat Document into the clipboard {roots, byId} shape. Descends block.children so tables, toggle descendants, and any future parent→child references survive the conversion.
encode_props
Serialize a props map into the data-devup-props marker payload.
html_to_copied_blocks
Parse HTML into the clipboard-shaped CopiedBlocks subtree used by the React paste flow. Block IDs come from id_gen so the caller controls determinism.
looks_like_xml
Pre-check for XML-shaped input so we don’t pay the html5ever cost on pure-Markdown text. Accepts the canonical <?xml version declaration, an explicit <!DOCTYPE, and bare tags that start with < + an ASCII letter (so <heading> triggers but <3 and < x don’t).
slice_content
Slice content by the UTF-16 offset range [start, end). Preserves per-span marks; spans that don’t intersect the range are dropped.
strip_xml_prolog
Remove the XML prolog (<?xml ... ?>) and DOCTYPE + leading comments so html5ever’s HTML5 parser doesn’t see tokens it doesn’t recognise. The caller is then free to hand the result to the HTML parser.