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 viadata-devup-propsmarker and inlinestyle=""
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§
- Copied
Blocks - Subtree bundle produced by
crate::html_to_copied_blocksand consumed bycrate::blocks_to_html. - Html
- Marker type carrying the
DocumentExport/DocumentImportimpls for HTML.
Enums§
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
CopiedBlocksdirectly. - decode_
props - Decode the
data-devup-propsmarker back into a props map. - document_
to_ copied_ blocks - Promote a flat
Documentinto the clipboard{roots, byId}shape. Descendsblock.childrenso tables, toggle descendants, and any future parent→child references survive the conversion. - encode_
props - Serialize a props map into the
data-devup-propsmarker payload. - html_
to_ copied_ blocks - Parse HTML into the clipboard-shaped
CopiedBlockssubtree used by the React paste flow. Block IDs come fromid_genso 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 versiondeclaration, an explicit<!DOCTYPE, and bare tags that start with<+ an ASCII letter (so<heading>triggers but<3and< xdon’t). - slice_
content - Slice
contentby 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.