MyST-Parser icon indicating copy to clipboard operation
MyST-Parser copied to clipboard

Unintended side effects of modifying visit container

Open kai687 opened this issue 2 years ago • 1 comments

Describe the bug

context

As a theme/extension author, I implement customizations for parsing code blocks. Specifically, I implement custom behavior for visit_container in a custom HTMLTranslator instance.

expectation

I expected to be able to modify the behavior of visit_container like I was before MystParser 0.19 (or before PR #713).

bug

With MyST parser 0.19, my custom visit_container function is never called.

problem

From the comments in the visit_container_html function, it looks like you introduced this change to avoid CSS clashes with bootstrap themes. Is this really a concern that should be handled at the parser level?

On one hand, if bootstrap themes have an issue with the container class being present, isn't that the responsibility of bootstrap themes to handle? On the other hand, if you do think that this must be handled at the parser level, it should be implemented as a custom HTML translator, not overriding visit_container of the base HTML translator.

workaround

When I set up the HTML translator, I add this line to undo the MyST parser change:

from docutils.writers.html5_polyglot import HTMLTranslator

app.add_node(nodes.container, override=True, html=(CustomHTMLTranslator.visit_container, HTMLTranslator.depart_container))

Reproduce the bug

I don't know, how best to reproduce it. I guess, one could implement a custom HTMLTranslator with your own implementation of visit_container?

I'm using my own theme sphinxawesome_theme, and adding a code block with a caption.

List your environment

No response

kai687 avatar Mar 05 '23 10:03 kai687

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar Mar 05 '23 10:03 welcome[bot]