How to get the editor top level node only on demand ? #61
-
Hello, I'm interested in getting the current doc node in Milkdown on-demand, such as when I click on a button for example, but the listener is only sending the doc node on updates. Is there any way I can do that ? I'm currently creating a ProseMirror editor to visually apply structure to plain text for non-tech people. I would be very interested to translate that text structure to markdown for static site generation but also translate existing markdown text into my visual formatting with nodeviews. I was thinking that I would copy the doc node from Milkdown then use it in my ProseMirror editor. I don't want to have to update the document to trigger the retrieval of the latest version of the doc node. I hope I was clear in my explanation. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
const milkdown = new Editor().create();
const node = milkdown.getNode(); Do you mean something like this? |
Beta Was this translation helpful? Give feedback.
-
In fact you can get the prosemirror view: const editor = new Editor()
editor.use(...).create()
const view = editor.view The version 4.6 has been released and you can use following code:
import { Editor, editorViewOptionsCtx, editorViewCtx } from '@milkdown/core';
async function createEditor() {
const newEditor = await new Editor()
.config(ctx => {
ctx.update(editorViewOptionsCtx, prev => ({ ...prev, root: root2, defaultValue: content2 }))
})
.use([directiveRemarkPlugin, titleNode])
.use(commonmark)
.create();
const view = newEditor.action(ctx => ctx.get(editorViewCtx));
// do whatever you want.
const doc = view.state.doc;
} |
Beta Was this translation helpful? Give feedback.
In fact you can get the prosemirror view:
The version 4.6 has been released and you can use following code: