Skip to content
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

Investigate why parsed-code-block doesn't work with caption by default #1

Open
RastislavTuranyi opened this issue Dec 31, 2024 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@RastislavTuranyi
Copy link
Owner

In the default sphinx code-block directive, when the caption option is passed in, the default literal_block node is wrapped inside a container node. When this is replicated in this extension (for compatibility with the caption option), all the children of the parsed_code_block node get deleted/removed by sphinx somewhere between the return from the directive run method and the doctree-read event being emitted by sphinx.

This has been successfully circumvented by creating a deepcopy and keeping a reference to it inside the parsed_code_block node. The reference to the deepcopy is not used anywhere, but its mere existence prevents the children from being removed. Setting the children to the deepcopy:

        custom_node.extend(deepcopy(text_nodes))

does not help and neither does setting the children after the wrapping in container:

        if caption:
            custom_node = container_wrapper(self, custom_node, caption)
            custom_node.children[1].children = []
            custom_node.children[1].extend(text_nodes)

I am mystified why the children keep getting deleted/removed and completely baffled why the hack used works, but it does work and the sphinx/docutils engine is too complex to spend time trying to untagle the causes of this issue at this thime. Nevertheless, it would be good to do so and create a proper solution, or at least understand why the solution works.

@RastislavTuranyi RastislavTuranyi added the help wanted Extra attention is needed label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant