Hi Saul-Mirone, I used @hocuspocus/server
as milkdown collab-server to save doc to database
#1756
Unanswered
yswang0927
asked this question in
Q&A
Replies: 1 comment
-
@Saul-Mirone , I found your code and I update the code, it can parse to markdown-content, but it not supports import { yXmlFragmentToProseMirrorRootNode } from 'y-prosemirror';
import {
init,
InitReady,
initTimerCtx,
remarkCtx,
schema,
schemaCtx,
SchemaReady,
serializerCtx
} from '@milkdown/core';
import { Clock, Container, Ctx } from '@milkdown/ctx';
import { schema as commonSchema } from '@milkdown/preset-commonmark';
import { schema as gfmSchema } from '@milkdown/preset-gfm';
import { ParserState, SerializerState } from '@milkdown/transformer';
import { TimerType } from './fake-timer.js';
store: async ({ document }) => {
const clock = new Clock();
const container = new Container();
const ctx = new Ctx(container, clock);
const runInit = init({})(ctx);
const runSchema = schema(ctx);
const hackTimer = (name, target) => {
const fake = new TimerType(name);
fake.id = target.id;
const result = fake.create(clock.store);
clock.store.set(target.id, result);
return result;
};
hackTimer('InitReady', InitReady);
hackTimer('SchemaReady', SchemaReady);
ctx.set(initTimerCtx, []);
// I add commonmark-schema and gfm-schema
const allSchemas = [commonSchema, gfmSchema].flat();
await Promise.all([
runInit(),
runSchema(),
...allSchemas.map((node) => node(ctx)()),
]);
const schema2 = ctx.get(schemaCtx);
const remark = ctx.get(remarkCtx);
const serializer = SerializerState.create(schema2, remark);
const xmlFragment = document.getXmlFragment('prosemirror');
const pmNode = yXmlFragmentToProseMirrorRootNode(xmlFragment, schema2);
let markdownContent = serializer(pmNode);
console.log('>> markdownContent: ', markdownContent);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @Saul-Mirone ,
I used
@hocuspocus/server
as milkdown collab-server to save doc to database,and I also want to get the plain markdown content from yjs-Doc in the server, how to do it?
Thank you!
The client code:
The server code:
The server code
store: async ({documentName, document, state}) => {}
invoked to save milkdown yjs data to db,document
is yjs-Doc object,state
is yjs-Doc state binary data,how to use milkdown-parser or yjs-parser convert the
document
orstate
data to plain markdown content ?I only can do this:
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions