From c8679f05715380ce253bb65e64763b68dd96ad35 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 14 Mar 2023 14:27:44 -0400 Subject: Utilities/Sphinx: Restore trailing parens on command cross-references Since commit cc21d0e478 (Utilities/Sphinx: Make signatures linkable, 2023-03-09) we always convert `cmake:command` domain cross-references to use the explicit `text ` form. This breaks the XRefRole's `fix_parens` setting that we use to render `cmd` as `cmd()`. Instead, transform `cmd(sub)` to `cmd(sub) ` to preserve the sub-command link destination, but leave `cmd` alone and let XRefRole convert it to `cmd()`. --- Utilities/Sphinx/cmake.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Utilities/Sphinx') diff --git a/Utilities/Sphinx/cmake.py b/Utilities/Sphinx/cmake.py index 38fd98a73b..ba1fa4a9f5 100644 --- a/Utilities/Sphinx/cmake.py +++ b/Utilities/Sphinx/cmake.py @@ -486,14 +486,19 @@ class CMakeXRefRole(XRefRole): # See sphinx.util.nodes.explicit_title_re; \x00 escapes '<'. _re = re.compile(r'^(.+?)(\s*)(?$', re.DOTALL) - _re_ref = re.compile(r'^.*\s<\w+([(][\w\s]+[)])?>$', re.DOTALL) + _re_sub = re.compile(r'^([^()\s]+)\s*\(([^()]*)\)$', re.DOTALL) _re_genex = re.compile(r'^\$<([^<>:]+)(:[^<>]+)?>$', re.DOTALL) _re_guide = re.compile(r'^([^<>/]+)/([^<>]*)$', re.DOTALL) def __call__(self, typ, rawtext, text, *args, **keys): if typ == 'cmake:command': - m = CMakeXRefRole._re_ref.match(text) - if m is None: + # Translate a CMake command cross-reference of the form: + # `command_name(SUB_COMMAND)` + # to be its own explicit target: + # `command_name(SUB_COMMAND) ` + # so the XRefRole `fix_parens` option does not add more `()`. + m = CMakeXRefRole._re_sub.match(text) + if m: text = f'{text} <{text}>' elif typ == 'cmake:genex': m = CMakeXRefRole._re_genex.match(text) -- cgit v1.2.1