Semantic Paste
paste-semantic-html rewrites pasted HTML into a more semantic document structure. It is especially useful when content comes from Word or other rich-text sources that emit noisy markup.
Install
pnpm add @citolab/prose-extensionsUsage
import { createSemanticPastePlugin } from '@citolab/prose-extensions/paste-semantic-html';
const plugins = [createSemanticPastePlugin()];ProseKit
If your app is built on ProseKit, use the extension wrapper instead. It requires the prosekit peer dependency:
import { defineSemanticPasteExtension } from '@citolab/prose-extensions/prosekit-extensions';
const semanticPasteExtension = defineSemanticPasteExtension();Add the returned extension to your editor’s extension composition.
When to use
Use this when pasted content needs cleanup before it enters the editor document, especially for list-heavy copy/paste flows.
Image paste handling
Word, Excel, PowerPoint and Outlook all put a bitmap of the whole selection on the clipboard as a fallback for apps that cannot read HTML, alongside the real HTML. The plugin only trusts that bitmap when the HTML itself cannot supply the image:
- No usable HTML (a screenshot, or an image dragged from the desktop) — the clipboard image is inserted directly.
- HTML is images and whitespace only, with unloadable
srcs (e.g. a single picture copied out of Word, whosefile:///…/clip_image001.pngsource cannot be fetched) — the clipboard bytes replace the dead placeholders one for one. - Anything else — the HTML is the content and the clipboard bitmap is ignored, since it only duplicates what the HTML already describes. Earlier versions of this plugin trusted it more freely, which is why a plain text paste from Word could sprout an unrelated picture, or a pasted figure could come in twice.
Clipboard images
Word, Excel, PowerPoint and Outlook all put a single flattened bitmap of the whole selection on the clipboard, alongside the real HTML, as a fallback for apps that cannot read HTML. The plugin only ever trusts that bitmap as image content in the two cases where it can’t mean anything else:
- the clipboard has no usable HTML at all (a screenshot, or an image dragged in from the desktop) — the bitmap is inserted as the pasted image;
- the HTML is nothing but unloadable image placeholders (e.g.
file:///…/clip_image001.pngsrcvalues left behind by “copy a single picture out of Word”) — the bitmap data hydrates those placeholders one for one.
Any other paste — text, tables, or a mix of text and real images — uses the HTML as-is and ignores the clipboard bitmap, so a normal Word paste no longer sprouts an extra, unrelated picture or duplicates an image that was already in the HTML.