-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
addRenderer and addExtension inconsistency #1023
Comments
Thank you for the detailed report! The only way to guarantee the execution order is to set explicitly set the
You'll want to add your custom renderer with a
Yeah, the documentation doesn't do a good job of explaining of why or when you'd want to set a custom commonmark/docs/2.4/customization/environment.md Lines 84 to 90 in 9a2195d
Anyone who would like to revise the documentation is welcome to submit a PR! (Note that
This behavior you're seeing occurs because the extension's
I'll keep this open to remind me to revisit that again when I have the bandwidth.
Thank you so much, I really appreciate that! 😊 |
Thanks for your quick reply! I struggle with parser and extensions... It's not what I'm best at 😅 Thanks again for the great job! |
Version(s) affected
2.4.2
Description
When adding an additional custom renderer, it is not executed if no priority is set when added via an extension.
Renderer added with:
$environment->addRenderer($class, $renderer)
will be actually run on the appropriate node class, whereas renderer added via the register method of an extension will not be run at all.Dump of
$environment->getRenderersForClass($class)
shows that the order of the renderers for the class if not the same when added viaaddRenderer()
or via an extension.When renderer is added via an extension, if it is added with a priority > 0, it will take precedence on the default renderer and be executed. It's ok, but adding a renderer via both methods should produce the same result, especially as renderer is added with the same priority in both cases by default.
If this behavior is not bogus, then maybe it should be explained in the documentation: I've spent about 2 hours trying to figure out why my extension was not working while in my previous tests with addRenderer the renderer was working fine...
How to reproduce
Create a custom renderer. For example:
Register the renderer:
Output:
Now, register the renderer via an extension:
and:
Output:
Possible solution
No response
Additional context
Dump of
$environment->getRenderersForClass()
when added via$environment->addRenderer()
:Dump of
$environment->getRenderersForClass()
when added via extension:Did this project help you today? Did it make you happy in any way?
Thanks a lot for this great package. It's incredibly powerful and customizable: it helps make everything become possible.
The text was updated successfully, but these errors were encountered: