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

Tight lists are not correctly rendered in the editor #57

Open
flaki opened this issue Oct 31, 2021 · 6 comments
Open

Tight lists are not correctly rendered in the editor #57

flaki opened this issue Oct 31, 2021 · 6 comments

Comments

@flaki
Copy link

flaki commented Oct 31, 2021

I ran into a list-rendering-related inconsistency in ProseMirror. After digging around, I found #51 (TIL about "list tightness" in Markdown!), and the fix does seem to correctly detect the "hidden" attributes in Markdown-it's tokens and correctly attaches them on lists, but the then the (default) list rendering does not take these into account:

screenshot

In the above screenshot, the left-hand side is plain Markdown-it, the right-hand side is ProseMirror. As evidenced by the data-tight="true" in the list DOM, the tightness is correctly detected but ignored on render.

This behavior can also be reproduced by the Friendly Markdown example on the website.

I tried looking into where this gets rendered (is it prosemirror-schema-list?) but arguably I'm still a bit new to ProseMirror's internals and couldn't quite get to it, would be happy to help to have this fixed.

@marijnh
Copy link
Member

marijnh commented Oct 31, 2021

Have you tried adding styles to ul[data-tight=true] li that remove the margins?

@flaki
Copy link
Author

flaki commented Oct 31, 2021

Appreciate the swift response, yes making the <p> inside display: contents is how I'm currently working around this, but I suspected that perhaps it was worthy to have a more clean solution of not rendering the paragraph elements in the first place?

@marijnh
Copy link
Member

marijnh commented Oct 31, 2021

The schema puts a block node there, which makes sense (you can have nested lists and such in tight list items), and the editor view expects nodes in the document to have a DOM node equivalent, so I don't think not rendering the paragraph is a very practical approach.

@flaki
Copy link
Author

flaki commented Oct 31, 2021

I see! Thanks for elaborating! Maybe then including the above CSS snippet by default and documenting this behavior would be a better recourse?

@stephane-klein
Copy link

@stephane-klein
Copy link

Have you tried adding styles to ul[data-tight=true] li that remove the margins?

I've corrected the display with these lines of css:

.ProseMirror ul li p:first-child {
    margin-top: 0;
}
.ProseMirror ul li p:last-child {
    margin-bottom: 0;
}

See in my POC project: https://github.com/stephane-klein/poc-svelte-prosemirror-markdown/blob/6a27f64eb7bd23663021a945d180b29c88d073d6/src/routes/editor.css#L336

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

3 participants