-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
Add support for events #399
Comments
I really like the idea of leveraging events like this! While I mull this over and try out a few different implementations, I'd love to hear any additional ideas or specific use cases that you or other members of the community have in mind (to ensure what we create best meets everyone's needs) |
An example: create a table of content. To create a ToC, you need to get some or all of the headings in a document. To build a ToC, currently, we need:
Currently, to achieve this, we have to add a renderer for headings, then parse the AST to get the headings list. With events, it would be much easier and would not require any additional renderer:
The
The
The listeners may receive other data depending on what you think is relevant: maybe the environment. The "block parsing listener" may alter the block element, or the environment (add a block parser or a renderer, maybe?). I don't know if it should return something. The "renderering listener" should return the modified HTML. I'm really not sure about what listeners should receive and return, I'm not familiar enough with the library. Maybe a block should offer an easy possibility to modify the content (it seems that currently the html element can be created with content, but it's not easy to modify it?). |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
2.0 will have three key events dispatched at critical points during the parsing and rendering process. We've also added new features like ToC and Front Matter using both events and other built-in extension points. I don't see the need to add any more events at this time, but I am definitely open to adding more in the future, and it should be easy to do this without breaking BC :) I'm therefore going to mark this issue as resolved. I remain open to any requests to add specific new events, I only ask that they are accompanied by a specific use case to help us confirm that they're the best way to accomplish the needed task. Thank you very much for your suggestion! |
Extensions would really take advantage of an events system, instead of walking through the AST one more time after the document has been parsed.
Events could be triggered, for example, when:
Listening to events would allow to plug in the parsers and renderers directly while the document is beeing processed. In some cases, it prevents from going through the document multiple times.
The text was updated successfully, but these errors were encountered: