diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index d08c65668e6..65f95f1b896 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -244,6 +244,8 @@ def add_target_and_index(self, firstname: str, sig: str, signode: desc_signature else: descr = _('command line option') for option in sig.split(', '): + # remove trailing part followed by equal symbol + option = option.split('=')[0] entry = '; '.join([descr, option]) self.indexnode['entries'].append(('pair', entry, signode['ids'][0], '', None)) diff --git a/tests/test_domain_std.py b/tests/test_domain_std.py index c464ea00841..19f330dc887 100644 --- a/tests/test_domain_std.py +++ b/tests/test_domain_std.py @@ -341,6 +341,18 @@ def test_cmdoption_for_None(app): assert domain.progoptions[(None, '-l')] == ('index', 'cmdoption-l') +def test_option_with_equal_sign(app): + text = (".. option:: -foo=bar|baz\n" + "\n" + ".. option:: -l=TYPE\n") + domain = app.env.get_domain('std') + doctree = restructuredtext.parse(app, text) + assert_node(doctree[0], addnodes.index, + entries=[('pair', 'command line option; -foo', 'cmdoption-foo', '', None)]) + assert_node(doctree[2], addnodes.index, + entries=[('pair', 'command line option; -l', 'cmdoption-l', '', None)]) + + def test_multiple_cmdoptions(app): text = (".. program:: cmd\n" "\n"