mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 21:15:18 +09:00
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
16 lines
491 B
TypeScript
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);
|
|
},
|
|
};
|