-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
Rework lists #364
Rework lists #364
Conversation
remark-parse: * Remove `loose` fields from `list`, `listItem` * Add support for empty list-items in any non-pedantic mode * Add `spread` to `list`, to signal that its items should have blank lines between them, set to true if any blank line exists between items * Add `spread` to `listItem`, to signal that its children should have blank lines between them * Fix bug where two lists, if they are both ordered or both not ordered, was seen in commonmark as one list remark-stringify: * Add support for missing `ordered` field * Add support for missing `start` field * Add support for `list.spread` (default: false) * Add support for `listItem.spread` (default: true) * Fix bug where two lists, if they are both ordered or both not ordered, and in commonmark, were not properly stringified, resulting in a new parse seeing them as one list * Fix bug where a list followed by an indented code block, in commonmark, was not correctly stringified, resulting in a new parse seeing the code as content of the list * Remove trailing white-space on empty list-items * Add support for stringifying list-items without parent
This looks great! 👍 But I think we still need the old |
@ikatyang Of course! I think we can do it as some tiny utility! |
I love the idea of decoupling the two, and it makes sense that that would be necessary to best serve both sets of interests. It does seem - if I am correctly understanding this change - that this isn't really breaking from the commonmark definition in any significant way, just changing the time at which the definition is applied. We still apply the same rules to determine whether items or lists are loose or tight, and when rendering to HTML a list's tightness will still be determined by either its own tightness or that of its children, just now that is being determined when we consume the AST rather than when we generate it. Is that correct? If so, it's not clear to me that it's best to rename the field from |
@Hamms Thanks for reviewing!
Perfect!
I meant a break away from commonmark terminology, and I think if these properties do not really do what CommonMark calls “loose”, then it makes more sense to have a different word for it! |
Agreed! I'm just having a hard time convincing myself one way or the other whether or not this is still doing what commonmark calls "loose" 🙃
In the current approach say that a list node is treated as being loose if it or any of its list items is labeled with I think the thing I'm not clear on is whether we want a property on a node to imply that the node is that property, or that it's labeled with that property. I can see it being confusing if a node that is labeled with Of course, either way I think this rework is great! I'm interested in the terminology change because the distinction seems subtle, but that also means it will likely be fine either way. |
It’s doing different things but it could be mapped to the same looseness definition!
Currently |
Related to remarkjs/remark#364.
Related to syntax-tree/mdast#4. Related to remarkjs/remark#349. Related to remarkjs/remark#350. Related to remarkjs/remark#364. Closes GH-23. Co-authored-by: Titus Wormer <tituswormer@gmail.com>
* Related to remarkjs/remark#364
Is there a utility to allow for |
Hi folks! 👋
After some thinking about lists, such as syntax-tree/mdast-util-to-hast#23 and #349, and the changes in syntax-tree/mdast#24, I reworked the lists as they are currently handled by remark-parse and remark-stringify. Below you can see the changes, but the most importent one is that I propose to remove
loose
onlist
and onlistItem
, instead replacing them byspread
.This PR additionally closes GH-350, GH-332, and GH-358.
/cc Could you review this @Hamms, as you spend some time thinking about this as well, and @ikatyang, as this will affect prettier?
Spread
So, previously we had loose. Any list item that was followed by a blank line between in and its next sibling, or if it had a blank line between any of its children, would result in that list item to receive
loose: true
, and otherwiseloose: false
.A list would have
loose: true
if any of its children hadloose: true
, andloose: false
otherwise.This was based on the
loose
definition of CommonMark, which means it is meant for HTML (namely, in a loose list, all<p>
tags are output, whereas in atight
list they are not).This was okay, but wasn’t really useful for either markdown (
remark-stringify
) or html (mdast-util-to-hast
), as both need different mechanisms (remark needs to know where to place blank lines, in the list, and in the items;mdast-util-to-hast
needs to know whether to output<p>
tags).In this new solution, we break from the commonmark definition, by introducing a new term:
spread: true
if there is a blank line between any of its children (not in them), in which caseremark-stringify
will join all children with blank lines between themspread: true
if there is a blank line between any of its children (not in them), in which caseremark-stringify
will join all children with blank lines between themThis decouples the two, which makes for a simpler AST, but it comes with the downside that
mdast-util-to-hast
, when stringifying an item, needs to calculate whether its parent list or any of its siblings hasspread: true
, to see whether it needs to generate<p>
tags.This is good though, because the tree stable. Say we injected a new item into a list, that would previously create an unstable tree (stringifying it and parsing it again, would result in a different tree).
Changes
See c600489.