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

ifconfig: Add a meta node to fix iteration #10502

Merged
merged 4 commits into from Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion sphinx/ext/ifconfig.py
Expand Up @@ -20,6 +20,7 @@
from docutils.nodes import Node

import sphinx
from sphinx import addnodes
from sphinx.application import Sphinx
from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import nested_parse_with_titles
Expand Down Expand Up @@ -64,7 +65,7 @@ def process_ifconfig_nodes(app: Sphinx, doctree: nodes.document, docname: str) -
node.replace_self(newnode)
else:
if not res:
node.replace_self([])
node.replace_self(addnodes.meta())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you insert a meta node? If my understanding is correct, it's better to convert the result of findall() to the list on the top of the loop, instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting to a list is the option of last resort as it is slower (double iteration) and takes more memory -- a meta node here has no effect on the output and in effect is a noop node. I could convert to a list if you'd prefer, but this is the reason I didn't.

A

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doctrees should follow the semantics. So -1 for using meaningful node for the noop purpose. If you'd like to insert a noop node, how about using Text('') instead? It's meaningless and noop node. I can accept it.

else:
node.replace_self(node.children)

Expand Down
1 change: 1 addition & 0 deletions tests/roots/test-ext-ifconfig/conf.py
Expand Up @@ -7,3 +7,4 @@
def setup(app):
app.add_config_value('confval1', False, None)
app.add_config_value('confval2', False, None)
app.add_config_value('false_config', False, None)
10 changes: 10 additions & 0 deletions tests/roots/test-ext-ifconfig/index.rst
Expand Up @@ -9,3 +9,13 @@ ifconfig

egg

Issue 10496 regression test
===========================

.. ifconfig:: false_config

`Link 1 <https://link1.example>`__

.. ifconfig:: false_config

`Link 2 <https://link2.example>`__