Under the Hood: The Architecture of Markdown Source Code to Rich-Text Clipboard Converter
Most Markdown-to-HTML pages dump a <textarea> of tags. That is not how you paste into Word or Google Docs. Convert markdown to rich text means writing a ClipboardItem with text/html and text/plain so the destination’s paste handler chooses HTML. This tool uses marked for GFM, DOMPurify to strip script-capable markup, and navigator.clipboard.write. Copy formatted markdown is the product; preview is a side effect.
Cloud “docs converters” that accept a .md upload create a document privacy problem for unpublished specs. Here the source never leaves the tab. The Clipboard API talks to the OS, not to a conversion farm.
Memory Allocation & Browser Threading Mechanics
useMemo re-parses when the input string changes. marked.parse(..., async:false) returns an HTML string. DOMPurify tokenizes that HTML against an allow-list in-page. Clipboard write must run in a user-gesture turn (the button). Very large notes allocate HTML on the order of the Markdown size; there is no virtualized editor because this is a converter. The preview dangerouslySetInnerHTML is safe only because of sanitize—never skip that step.
Algorithmic Deep-Dive: Code Snippet & Logical Analysis
const html = DOMPurify.sanitize(marked.parse(markdown, { async: false }));
await navigator.clipboard.write([
new ClipboardItem({
"text/html": new Blob([html], { type: "text/html" }),
"text/plain": new Blob([markdown], { type: "text/plain" }),
}),
]);Dual MIME is the interoperability trick: Word/Docs consume HTML; Slack/terminals take plain. If clipboard.write is blocked (insecure context, denied permission), the failure is visible rather than a silent writeText fallback that would drop formatting. Range/Selection APIs are not required for this path; we do not hijack the user’s current highlight.
The Local Storage Sandbox & Volatile Data Pipelines
After a successful write, the OS owns the clipboard. This page does not keep a paste history. The two Blobs are short-lived arguments to ClipboardItem. Markdown in the textarea is RAM-only—no autosave to IndexedDB that would retain drafts of an embargoed RFC.
Verifying True Privacy: How to Audit Your Browser's Network Tab
F12 → Network → clear. Paste a unique sentence, click Copy rich text. Search the HAR for that sentence. Clipboard APIs are not HTTP; you should get zero hits. That is the difference between a local rich-text converter and a “paste to our server, we return DOCX” service.