-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Serialize mdast to markdown #127
Conversation
While working on this, I noticed that the JS implementation relies heavily on regular expressions in some places. I believe we can rewrite some parts of the code in Rust instead of depending on the regex crate. Although the regex crate guarantees linear time complexity, we can eliminate the need for the regex engine in places where simpler Rust code would work. Maybe we can benchmark first but this won't happen until I move over most of the tests into Rust. what do you think @wooorm ? One more question what do you think make more sense here for the maintainability of this utility :
|
While the core of As for workspace vs module, I have to particular preference currently. You? |
Since we're working with an AST and this is a utility a workspace sounds better to me this will help to isolate the tests when we quickly run cargo test and version this util by it's own too. It's not that hard to change that decision later on, I updated the PR to use a workspace instead and kept the no_std constrain. |
I completed copying over the tests so now all of the tests are a match, I also did a quick review everything looks fine to me, defiantly a few performance improvements and refactors can be done in a separate PR but now since the tests are moved over it's easy to make changes without worrying about something breaking. I've also added comments as proposed for some data structures. |
Just a heads-up, serializing a yaml node to markdown gives an error. I don't know if that was intentional, but if not you might be missing a yaml handler |
Thank you so much for this PR btw! Really needed this feature |
wooorm knows more about this than me, but I think Yaml and Toml are not part of the CommonMark specs they're part of the frontmatter extension this PR ports over the JS implementation here mdast-util-to-markdown In order for Yaml and Toml to work we need to add support for frontmatter serialization I believe the JS version is here mdast-util-frontmatter |
Ah gotcha! Thanks for the info & links! |
Some extensions have built in parsers that can be turned on with an option. It could make sense to support serialization for those tools. |
Also additional testing, using a fuzzer to to validate that content can round trip. In other words markdown can be parsed to a tree, be serialized again, and parsed again should have the same tree structure (though positions and exact characters may change). That technique found a lot of quirks in the original micromark/remark parser and serialized. References: |
Right yes, that indeed. Somewhere above @bnchi and I talked about this too and concluded the same. I believe @bnchi has used up a lot of the time they have to work on this. So if @augustkline or others are up for follow up PRs, I’d love that! |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Only thing perhaps is some docs in this readme here? |
Thank you so much for writing this PR! |
Yeah I can add instructions on how to use this code in a readme
Alpha sounds alright, what do you think ? |
Sounds good to me! 👍 |
fixes #64
TODO handlers :