-
-
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
Enable custom plugins #32
Comments
Thanks! Extensions for me (and as this extends micromark/mdast/remark/etc, I’d like to stick with those terms) mean extending the syntax of markdown with custom things. E.g., JSX, math with dollars, etc. The first is as far as I understand impossible in Rust. The extensibility needed to support extensions is not there in Rust. None of the other rust markdown parsers that I know support them either. The second can be supported. Here’s a PR on the MDX repo: wooorm/mdxjs-rs#8. Something like that can be made on top of this (hence its there). I want to develop such features based on needs of people that know the Rust ecosystem, instead of baking it in immediately. So I’d like to hear some ideas and have discussions first :) |
@wooorm Oh yes, I definitely mean plugins built on top of a provided AST 😄 I've updated the issue title to reflect that. Extensions are officially above my pay grade 🤣 I think it'd be nice to be able to specify plugins without too much extra plumbing. Maybe something like this: let mut options = Options::default();
options.custom_plugins = vec![
fancy_code_blocks,
mermaid_diagrams,
];
let result = to_html_with_options("Big long fancy doc...", &options)?; Or another option, of course, would be to see if #8 lands and I can just use
|
MDX also allows the vanilla markdown format. However, it still compiles to a string of JS, not a string of HTML.
This project here currently is positioned a bit lower than that. You can get a string of HTML out directly (no ASTs), or you can get an AST (which you can then do whatever with yourself) |
I am totally new to Rust, so I could very well be wrong. But it seems like https://github.com/rlidwka/markdown-it.rs/tree/master/src/plugins supports adding extensions to the language, as opposed to just modifying the AST. |
@digitalmoksha Oh wow, this may just be perfect for my use case! Thanks! |
@wooorm I haven't played with trying to add this to markdown-rs yet (and don't know if/when I'll have time to), but a design that I find quite powerful is the one exposed by pulldown-cmark. That crate's public API for generating HTML expressly operates against the stream of syntax "events" it emits. The internals of how that works are extremely similar to the way that I recognize that one large different is that this crate's I totally get why you don't have the Caveat to all of this: I like this library's approach so much that I may end up implementing what I want using its mdast and doing just that—it's far more approachable than trying to implement "standard" footnotes in pulldown-cmark, which I have not managed to find a way to do without rewriting huge swaths of the lex-and-parse stuff (…which I really do not want to do)! |
I think the way to go about it is doing the same as what we do in JS:
And to have plugins operate on either mdast or on hast! |
That definitely seems reasonable as a design, though I will note that it also comes with non-trivial performance overhead (lots of extra copies and allocations for the AST→AST transforms)! It's quite possible that this is already in the "it's more than fast enough" bucket such that it doesn't especially matter, though. |
This seems more strongly worded than what I’d think. I mean, events are also objects, that are mapped. But they are terrible to work with. ASTs are great to work with. Having spent 10 years on ASTs for markdown in the JavaScript world, I’m pretty convinced that ASTs and plugins are the way to go about it. See also wooorm/mdxjs-rs#27 |
I'm a huge fan of this library, especially the MDX support 🎉, but I'd like to be able to provide my own extensions (such as super-fancy code blocks with all the bells and whistles and support for fun things like Mermaid diagrams). As far as I can tell, there isn't currently a way to do that. If I'm wrong and there is a way to do that, please let me know and I'll close this 😄 But if this isn't currently possible, I'd like to know if you consider that a non-goal for the project. If it is a non-goal, I'm happy to close this and explore other options. But if you're open to that, I'm happy to help.
The text was updated successfully, but these errors were encountered: