How to get the html string? #466
-
Is there any api in mildown to get the html string? |
Beta Was this translation helpful? Give feedback.
Answered by
Saul-Mirone
Apr 19, 2022
Replies: 2 comments 5 replies
-
Why not just use |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can also write a simple action which will be provided officially in v6.0: /* Copyright 2021, Milkdown by Mirone. */
import { Ctx, editorViewCtx, schemaCtx } from '@milkdown/core';
import { DOMSerializer } from '@milkdown/prose';
export const getHTML = () => (ctx: Ctx) => {
const div = document.createElement('div');
const schema = ctx.get(schemaCtx);
const view = ctx.get(editorViewCtx);
const fragment = DOMSerializer.fromSchema(schema).serializeFragment(view.state.doc.content);
div.appendChild(fragment);
return div.innerHTML;
};
const html = editor.action(getHTML()); |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
langsz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also write a simple action which will be provided officially in v6.0: