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

[Bug] Empty nodes are not preserved #1579

Open
2 tasks done
wintercounter opened this issue Dec 9, 2024 · 1 comment
Open
2 tasks done

[Bug] Empty nodes are not preserved #1579

wintercounter opened this issue Dec 9, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@wintercounter
Copy link

Initial checklist

  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything (or linked relevant results below)

Affected packages and versions

7.5.0

Link to runnable example

https://milkdown.dev/playground?text=DISwdgpgBAjAUAupJQExyA%3D%3D

Steps to reproduce

  1. Add an empty line to Milkdown editor
  2. Observe that Markdown in Codemirror gets updated correctly.
  3. Make an edit in the markdown content.
  4. Empty node gets removed.

Currently, when users edit their posts, they are losing the spacing between paragraphs because of this.

The markdown that gets saved into the database.

Line 1



Line 2

Upon edit we load the markdown into Milkdown, using (same code as in the playground)

const editor = get();
editor?.action((ctx) => {
  const view = ctx.get(editorViewCtx);
  const parser = ctx.get(parserCtx);
  const doc = parser(markdown);
  if (!doc) return;
  const state = view.state;
  view.dispatch(
    state.tr.replace(
      0,
      state.doc.content.size,
      new Slice(doc.content, 0, 0),
    ),
  );
});

Content becomes

Line 1

Line 2

Basically if I load again Milkdown's previous output, I won't get the same results again.

Expected behavior

Empty nodes are preserved by the parser.

Actual behavior

Empty node gets removed.

Runtime

Chrome

OS

Windows

Build and bundle tools

Next.js

@wintercounter wintercounter added the bug Something isn't working label Dec 9, 2024
@shenzhongkang
Copy link

face the same issue. @Saul-Mirone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants