Join GitHub today
Provide context for renderer #4
Great work on this; it is indeed fast!
Would you consider a change something like the prototype in this pull request? It provides the inline_lexer to the renderer method and sets a couple extra values that can be used for more advanced rendering.
Of course, a full implementation would change all the renderer methods to accept the lexer as an argument and would be breaking backwards compatibility, but it is a very new project so maybe it is in time? If so, I'm willing to make the change and submit it.
In the exact example usage I'm thinking of, I detect if an image is all alone or surrounded by other elements. Depending on its surroundings or lack thereof, I change the rendered CSS class. So for example, an image followed by text all in one paragraph might float the image left and flow the text around it.
Maybe an image would better explain:
It's a good idea for providing a context to renderer. But I am not with the solution. How about pass the whole markdown parser to renderer:
# Markdown self.renderer = Renderer(self, **kwargs) # Renderer init def __init__(self, parser, **kwargs): self.parser = parser
I considered that, but the code looks a little strange:
renderer = MyOwnRenderer() parser = Markdown(renderer=renderer) renderer.parser = parser output_text = parser.render(input_text)
However, I can completely work with that; I would just need the code that sets first_item and has_more_items (or whichever names are preferred).