wooorm / markdown-rs

CommonMark compliant markdown parser in Rust with ASTs and extensions
https://docs.rs/markdown/1.0.0-alpha.18/markdown/
MIT License
836 stars 41 forks source link

Compile mdast to html #101

Closed GuillaumeDesforges closed 5 months ago

GuillaumeDesforges commented 5 months ago

I'd like to manipulate the parsed AST before it goes through compilation.

I can get the AST using to_mdast, however I can't then compile it to HTML as to_html::compile is private in the crate.

ChristianMurphy commented 5 months ago

Duplicate of https://github.com/wooorm/markdown-rs/issues/32

GuillaumeDesforges commented 5 months ago

@ChristianMurphy I agree that the end result could be about the same than with a plugin architecture.

That being said, somehow allowing to use to_html::compile directly would be a quick win that would not require any complex architecture.

Would you consider making more of the internals public in the crate?

wooorm commented 5 months ago

to_html does not work on ASTs. The functionality you are looking for is not here.

There will not be a mdast -> html transform. Eventually there will be an mdast -> hast step, and then finally a hast -> html step. The first step is already privately implemented in https://github.com/wooorm/mdxjs-rs. There is no hast -> html step yet, but it would be porting https://github.com/syntax-tree/hast-util-to-html/blob/main/lib/index.js to Rust.

Currently, this project is ± at a level of trying to figure out how people want to use it, before committing to particular APIs.

All of these steps are available in the JavaScript world. As this is Rust, the Rust part might affect it.

GuillaumeDesforges commented 5 months ago

Right, I went through the code too quickly. Now I understand why it's a duplicate of #32.

Thanks a lot :+1: