diff --git a/sphinxarg/ext.py b/sphinxarg/ext.py index ed2a3897..89a08281 100644 --- a/sphinxarg/ext.py +++ b/sphinxarg/ext.py @@ -113,7 +113,9 @@ def print_action_groups( # Every action group is composed of a section, holding # a title, the description, and the option group (members) title_as_id = action_group['title'].replace(' ', '-').lower() - section = nodes.section(ids=[f'{id_prefix}-{title_as_id}']) + if id_prefix: + title_as_id = f'{id_prefix}-{title_as_id}' + section = nodes.section(ids=[title_as_id]) section += nodes.title(action_group['title'], action_group['title']) desc = [] @@ -575,7 +577,7 @@ def run(self): nested_content, markdown_help, settings=self.state.document.settings, - id_prefix=(f'{module_name}-' if module_name else '') + attr_name, + id_prefix=f'{module_name}-{attr_name}' if module_name else attr_name, ) ) if 'nosubcommands' not in self.options: diff --git a/test/test_default_html.py b/test/test_default_html.py index e5acd7f7..9ff62b6f 100644 --- a/test/test_default_html.py +++ b/test/test_default_html.py @@ -56,12 +56,12 @@ def get_text(node): ('.//h1', 'blah-blah', False), (".//div[@class='highlight']//span", 'usage'), ('.//h2', 'Positional Arguments'), - (".//section[@id='positional-arguments']", ''), - (".//section[@id='positional-arguments']/dl/dt[1]/kbd", 'foo2 metavar'), - (".//section[@id='named-arguments']", ''), - (".//section[@id='named-arguments']/dl/dt[1]/kbd", '--foo'), - (".//section[@id='bar-options']", ''), - (".//section[@id='bar-options']/dl/dt[1]/kbd", '--bar'), + (".//section[@id='get_parser-positional-arguments']", ''), + (".//section[@id='get_parser-positional-arguments']/dl/dt[1]/kbd", 'foo2 metavar'), + (".//section[@id='get_parser-named-arguments']", ''), + (".//section[@id='get_parser-named-arguments']/dl/dt[1]/kbd", '--foo'), + (".//section[@id='get_parser-bar-options']", ''), + (".//section[@id='get_parser-bar-options']/dl/dt[1]/kbd", '--bar'), ], ), ( @@ -71,8 +71,8 @@ def get_text(node): ('.//h1', 'Command A'), (".//div[@class='highlight']//span", 'usage'), ('.//h2', 'Positional Arguments'), - (".//section[@id='positional-arguments']", ''), - (".//section[@id='positional-arguments']/dl/dt[1]/kbd", 'baz'), + (".//section[@id='get_parser-positional-arguments']", ''), + (".//section[@id='get_parser-positional-arguments']/dl/dt[1]/kbd", 'baz'), ], ), (