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
Document side-effects of renderers' initialisation #56
Comments
It seems that in fact it is not the use of a context manager that changes things, but the initialisation of the HTMLRenderer()
d = Document('a <b> c')
with HTMLRenderer() as r:
print(r.render(d)) # <p>a <b> c</p> |
Ok so as to why this is happening, if I'm not mistaken:
And if the renderers are always called inside a context manager, it's all good since the I suggest updating the Moreover, this means that the |
Hey there, thanks for this! I agree with your points, and yes it is a bit confusing to have side-effects in renderer initializations. I'm actually considering getting rid of this behavior, and thus removing the necessity of using context managers entirely. Would that be a better solution? I'll also allow I'll see if I can do so fast enough, but if not I'll add a note to the Thanks again! |
I guess so. For what it's worth, here is what I was expecting when I first encountered missletoe last week:
So something like this: md = 'Hello, *world*!'
tokens = Document(md, extra_tokens=[GithubWiki])
print(ASTRenderer().render(tokens))
print(HTMLRenderer().render(tokens)) In other words, I would expect the parsing and the rendering phases to be independent. Since the types of tokens has to be specified in the parsing phase, it seems odds to me to specify it in the rendering phase instead. Just my two cents. Obviously, you do what you want with the project, and what I mentioned above is likely to change the API and break backward compatibility.
I don't really have an opinion on the matter, except that it should probably be documented if that's not the case. That make me think of the following: it may be a good thing to be able to specify some tokens not to be generated. For example, if I want to do CommonMark and nothing more, how would I disable tables and footnotes? I'm not sure if that's really an important feature though. |
The interesting thing about this is that But separating parsing and rendering phases is a very good suggestion. I'll see what I can do with that.
There's a nuclear option: class MyRenderer(HTMLRenderer):
def __init__(self):
# ...
block_token._token_types = []
span_token._token_types = []
# ... ... although manipulating an underscored variable is undocumented, and will probably change based on our discussion in this issue. |
Thanks for your suggestions. :) So I've tried to document the side effects as originally requested. See f5ea6d6. I hope this will suffice for now. Regarding separating parsing and rendering phases, I hope we will get to this one day, but let's do this in a separate ticket. |
Hello, this is possibly an issue concerning the doc and not the code.
Not sure where the difference in output comes from. CommonMark asks for the second output though, which seems to be what is performed in
mistletoe.markdown
and by themistletoe
command line.The text was updated successfully, but these errors were encountered: