Tight lists are not correctly rendered in the editor #57

Open
opened 2021-10-31 19:10:12 +01:00 by flaki · 6 comments
flaki commented 2021-10-31 19:10:12 +01:00 (Migrated from github.com)

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.

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](https://user-images.githubusercontent.com/2089432/139596191-7c868a0a-3ba8-413b-ba00-d787c135b765.png) 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](https://prosemirror.net/examples/markdown/) example on the website. I tried looking into where this gets rendered (is it [prosemirror-schema-list](https://github.com/ProseMirror/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 commented 2021-10-31 19:48:15 +01:00 (Migrated from github.com)

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

Have you tried adding styles to `ul[data-tight=true] li` that remove the margins?
flaki commented 2021-10-31 21:03:20 +01:00 (Migrated from github.com)

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?

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 commented 2021-10-31 21:29:29 +01:00 (Migrated from github.com)

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.

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 commented 2021-10-31 21:40:02 +01:00 (Migrated from github.com)

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

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 commented 2023-08-02 15:23:54 +02:00 (Migrated from github.com)
Same subject here: https://discuss.prosemirror.net/t/lists-paragraph-inside-li-instead-of-new-list-item/455/8
stephane-klein commented 2023-08-03 06:49:34 +02:00 (Migrated from github.com)

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: github.com/stephane-klein/poc-svelte-prosemirror-markdown@6a27f64eb7/src/routes/editor.css (L336)

> 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: ```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 in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-markdown#57
No description provided.