Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importing a HTML file #96

Open
pan2za opened this issue Sep 29, 2024 · 4 comments
Open

importing a HTML file #96

pan2za opened this issue Sep 29, 2024 · 4 comments

Comments

@pan2za
Copy link

pan2za commented Sep 29, 2024

I want to import a HTML file and rending it into the rich editor,
there are 3 ways,
1 do as the lexical has suggested,
getEditor,
getRoot
insertNode
2 make a HTML plugin like the Image plugin, there's so many difference there.
3 examine the copy/paste method in rich editor, which supports HTML content paste.
Any suggestions?

@pan2za
Copy link
Author

pan2za commented Sep 29, 2024

or make a HTML plugin like the Import plugin.

@pan2za
Copy link
Author

pan2za commented Oct 2, 2024

I try to create a HTML plugin, the main INSERT command does not work, the code is,

onMount(() => {
return editor.registerCommand(
INSERT_HTML_COMMAND,
(payload) => {
console.log("insert html command received.")
// In the browser you can use the native DOMParser API to parse the HTML string.
const parser = new DOMParser();
const dom = parser.parseFromString(payload, "text/html");
// Once you have the DOM instance it's easy to generate LexicalNodes.
const nodes = generateNodesFromDOM(editor, dom);
// Select the root
// getRoot().select();
// Insert them at a selection.
insertNodes(nodes);
return true;
},
COMMAND_PRIORITY_EDITOR,
);
});

@pan2za
Copy link
Author

pan2za commented Oct 2, 2024

I've add a HTML plugin for this project. I will try to push to this project later...

@pan2za
Copy link
Author

pan2za commented Oct 5, 2024

I've made a HTML plugin, the core code is pasted in the upper comment. but I'm not sure whether it's really needed by others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant