Skip to content

Context data needed in custom renderer #391

Description

@juanitocalero

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions