I'm writing a custom renderer, and I would like to modify my generated img tags to customize its url with a prefix.
That prefix depends on some extra data that depends on the current execution, but I'm unable to find a way to insert a context object in my custom render methods.
I know I could add an external prepopulated state object, but following the code, I can't find a way for that state to reach the rendering methods. The method's signature doesn't include a state. I've reviewed renderers/html.py render_token method, and it seems that the state is never used in the render functions.
How could I achieve that? The options that come to my mind are:
- Add a property to my custom renderer class that changes before each invocation, but this could cause problems in case of multithreaded use and feels kinda ugly. I colud recreate the mistune object and/or the renderer in each invocation with my custom data, but I was looking for a better option.
- Override the renderer core methods and call the render functions with the
state included, but it seems like a lot of work and prone to errors.
Any ideas?
I'm writing a custom renderer, and I would like to modify my generated
imgtags to customize its url with a prefix.That prefix depends on some extra data that depends on the current execution, but I'm unable to find a way to insert a context object in my custom render methods.
I know I could add an external prepopulated
stateobject, but following the code, I can't find a way for that state to reach the rendering methods. The method's signature doesn't include a state. I've reviewedrenderers/html.pyrender_tokenmethod, and it seems that thestateis never used in the render functions.How could I achieve that? The options that come to my mind are:
stateincluded, but it seems like a lot of work and prone to errors.Any ideas?