-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Discussion] Plug-ins #163
Comments
Other abilities I would expect from plugins:
|
That is definitely something I would like too! And I have thought about it already. If you have any idea on how we could make this work, I am open for suggestions. Also, I think it would be nice if plugins could be developed by third-parties. But since Rusts ABI is not stable that would probably require going through a C api.. Many open questions about this design |
LLVM compilers should...
So, yeah, to me, this list sounds a lot like basic compiler design. And with basic compiler design comes this workflow: Tokenise inputs, generate some sort of IR, modify IR, spit code out. Now, translated to MdBook, this means:
Now, about supporting multiple targets, like generating PDF, HTML, Markdown, or PNG,... Plugins should be able to check the current targets and should notify MdBook about what to do if a target is not supported. Should the plugin fail or should it ignore unsupported targets? Should a failed plugin be ignored and skipped or should MdBook fail as well? Those are questions one has to answer. Or just make the exact behaviour configurable and pick a sensible default behaviour (e.g. fail, ignore). Now, why multiple targets? If one wants to generate PDF and HTML at the same time, you can actually share the Markdown IR with all its extensions, saving parsing and modification time. Now, to share extensions, plugins are either required to not fail the target check, or |
Thanks for that great reply! 😊
Not mdBook, but I use pulldown-cmark to parse the markdown and it generates an iterator over events. Parsing before sending to the plugin makes some kind of plugins more difficult though. For example a MathJax plugin would allow you to insert math into your book like this: # Some chapter
A paragraph with some text
$$\int x \; dx$$
Another paragraph If we parse this to markdown first, backslashes disappear,
Yes, I was thinking along the same line. I thought I would give every plugin and renderer a unique identifier so that plugins could tell what renderers they support. |
Hmm... you don't actually need plugins to be able to read the raw markdown text to support stuff like MathJax. Just by looking at your example code, I'd guess that In addition to plugins modifying Markdown IR or pulldown-cmark events, plugins could specify those three special things:
I'm not sure, however, how this would be done using pulldown-cmark. How do you handle MathJax over there? I guess you don't, which might be the reason you suggested source code access for plugins. How would it work... Okay, so a MathJax plugin would just catch everything delimited by A TOC plugin might use the caught substring Both approaches don't need to know the whole source code, which is a good thing. However, as soon as a plugin needs information about the whole document, things get rather complicated, quickly. Nothing impossible, though. Thus, the most difficult thing about implementing MdBook plugins would be to implement a decent MdBook pre-processor. Sadly, pre-processing will break source location information, unless you think of clever tricks to map source positions generated by pulldown-cmark to source positions in the non-pre-processed document. And don't forget that a pre-processor has to know about code blocks and inline code. An AST would definitely be easier, as a second pass would't be required anymore. However, an AST wouldn't solve the backslash and other escapes issues, unless you can somehow pre-process the document or define custom tokens. |
Has the plugin system been resolve? |
Not yet :) In the mean time, I'm open to discussion and ideas. It would be interesting to figure out what people need access to to write useful plugins. |
The plugin I need might be a markdown specific plugin, the google/pulldown-cmark project issue about this is still open. The last activity of pulldown-cmark is 4 months. |
Following on from https://github.com/azerupi/mdBook/issues/268#issuecomment-301700191, it sounds like you want to be able to define a very explicit pipelining process and allow your users to insert plugins along the way. Somewhat copying @Evrey's idea in https://github.com/azerupi/mdBook/issues/163#issuecomment-243076345 and relating it to a compiler you'd probably want a pipeline somewhat like this:
An idea I had was that a plugin can any executable on your Then as far as configuration goes, there can be keys for each pluggable step of the pipeline in your config file and you just add the name of your plugin's executable to that. |
@azerupi, I would be keen to help out with a plugin system. Let me know if there's anything I can do or how you want to implement it, and I'd be more than happy to get a start on this. |
Just adding a potential use-case: I added some functionality where I wanted to inject some dynamic HTML into the page, so I ended up created a pre-processor which injected a This script waits for the page to be loaded, and then injects some custom behaviour and registers some event listeners. So, I guess what would have been really nice is a "post-processor" of some sort? |
@acheronfail, could you use the
Edit: ignore my comment. It looks like |
That's probably a better option. Although, the benefit I have right now is that my preprocessor checks if the renderer is I guess I'd need both a pre-processor, and an entry in the additional-js file:
|
[
{
"template": "__HOST__",
"fallback": "10.10.14.1"
},
{
"template": "__PORT__",
"fallback": "1234"
}
]
EDIT: I've created a repository for this here: https://github.com/acheronfail/mdbook-dynamic-templates if anyone is interested. |
Would be nice to have the option to run tests on code snippets that are not in Rust. |
@acheronfail, did you know you can tell your preprocessor to only run against certain renderers? See the |
@XVilka, what did you have in mind? I feel like you could create your own renderer for this though. It's just like mdbook-linkcheck in that the "rendered" product isn't a document on disk, but a set of diagnostics that are shown to the screen and an exit code that's passed to |
hi. I'm new to Rust. let me know if there's any better place to ask this question. I'd like to debug, say, katex plugin in an Intellij IDE. How should I run the Also, does Rust provide symbol information enough to trace back to |
I believe plugins should be more tightly integrated with I want to have a command Most I believe
|
Non-core functionality should be isolated into plug-ins. Plug-ins can then be enabled / disabled depending on the users need. e.g. syntax highlighting could be a plug-in
Plug-ins should:
How could we design this?
The text was updated successfully, but these errors were encountered: