Files
webstudio/apps/builder/app/shared/copy-paste/plugin-html.ts
T
Bogdan Chadkin 59b6471c4f experimental: support paste html (#5185)
Ref https://github.com/webstudio-is/webstudio/issues/4404

Slightly reworked paste story. Now minimal API to insert html looks like
this

```js
const fragment = generateFragmentFromHtml(html);
insertWebstudioFragmentAt(fragment);
```

- attributes are casted to string, number and boolean types
- text is wrapped with spans when outside of rich text
- unsupported tags are ignored in result



https://github.com/user-attachments/assets/c8072d86-72bd-4446-a26a-e678b193f93e
2025-05-06 13:31:13 +04:00

16 lines
491 B
TypeScript

import { isFeatureEnabled } from "@webstudio-is/feature-flags";
import { generateFragmentFromHtml } from "../html";
import { insertWebstudioFragmentAt } from "../instance-utils";
import type { Plugin } from "./init-copy-paste";
export const html: Plugin = {
mimeType: "text/plain",
onPaste: (html: string) => {
if (!isFeatureEnabled("element")) {
return false;
}
const fragment = generateFragmentFromHtml(html);
return insertWebstudioFragmentAt(fragment);
},
};