dprint / dprint-plugin-markdown

Markdown code formatting plugin for dprint.
MIT License
25 stars 9 forks source link

chore(cmark): upgrade pulldown-cmark to 0.11 #108

Closed waynr closed 1 month ago

waynr commented 2 months ago

Hi! I found this project when I encountered the bug described in https://github.com/denoland/deno/issues/19458.

My understanding is that in order for deno fmt not to mangle frontmatter, dprint-plugin-markdown needs to update to pulldown-cmark 0.10 or later in order to incorporate the Tag::MetadataBlock variant into the ast builder.

This PR is not quite finished since I wanted to get some early feedback about if this work is even desirable and what all needs to happen for it to be merged. I also imagine that this is the kind of work that a maintainer may have already begun working on locally so I thought I might save myself some time by not duplicating any existing efforts.

Here are what I imageine the next steps will be if I do continue this work:

It's not clear to me yet if there is anything to be done beyond merely parsing these new Tag and Event variants -- is there any special consideration needed include formatting them in the output?

CLAassistant commented 2 months ago

CLA assistant check
All committers have signed the CLA.

waynr commented 2 months ago

I've just pushed a bunch of commits for this, but it's still a work in progress.

The pulldown-cmark changes seem to be somewhat non-trivial. Eg. the introduction of HtmlBlock, and what seems to be a new possibility that TaskListMarker gets parsed not as a direct descendent of an Item but may actually be subordinate to a Paragraph contained by the Item.

So I keep running up against a couple different issues:

Anyway, this isn't meant as a criticism of your code which I do find very coherent and easy to navigate overall. Just describing some problems I've run into.

I do have a couple suggestions for a refactor which I would be willing to do myself if you're open to it:

If you're open to this kind of contribution, what I would likely to is open a separate PR to do the refactor without also pulling in pulldown-cmark since that really muddies the waters. My hope is that the refactor makes the dependency updates PR much easier to accomplish.

dsherret commented 1 month ago

@waynr I looked into this one a bit and got a little bit further (it's getting to the spec tests now, but a few are failing).

In this case, I think it's just easiest to parse the HtmlBlock as Html like before and I pushed a commit that does that. I think we can save any big architectural changes for later.

Would you be willing to add the missing variants? If not, I can take a look later (I'm done on this for now, just took a brief look).