@@ -355,11 +355,18 @@ class DocCLI(CLI, RoleMixin):
355355 _URL = re .compile (r"\bU\(([^)]+)\)" )
356356 _REF = re .compile (r"\bR\(([^)]+), *([^)]+)\)" )
357357 _CONST = re .compile (r"\bC\(([^)]+)\)" )
358- _SEM_OPTION_NAME = re .compile (r"\bO\(([^)]+)\)" )
359- _SEM_OPTION_VALUE = re .compile (r"\bV\(([^)]+)\)" )
360- _SEM_ENV_VARIABLE = re .compile (r"\bE\(([^)]+)\)" )
358+ _SEM_PARAMETER_STRING = r"\(((?:[^\\)]+|\\.)+)\)"
359+ _SEM_OPTION_NAME = re .compile (r"\bO" + _SEM_PARAMETER_STRING )
360+ _SEM_OPTION_VALUE = re .compile (r"\bV" + _SEM_PARAMETER_STRING )
361+ _SEM_ENV_VARIABLE = re .compile (r"\bE" + _SEM_PARAMETER_STRING )
362+ _SEM_RET_VALUE = re .compile (r"\bRV" + _SEM_PARAMETER_STRING )
361363 _RULER = re .compile (r"\bHORIZONTALLINE\b" )
362364
365+ # helper for unescaping
366+ _UNESCAPE = re .compile (r"\\(.)" )
367+ _FQCN_TYPE_PREFIX_RE = re .compile (r'^([^.]+\.[^.]+\.[^#]+)#([a-z]+):(.*)$' )
368+ _IGNORE_MARKER = 'ignore:'
369+
363370 # rst specific
364371 _RST_NOTE = re .compile (r".. note::" )
365372 _RST_SEEALSO = re .compile (r".. seealso::" )
@@ -371,6 +378,33 @@ def __init__(self, args):
371378 super (DocCLI , self ).__init__ (args )
372379 self .plugin_list = set ()
373380
381+ @staticmethod
382+ def _tty_ify_sem_simle (matcher ):
383+ text = DocCLI ._UNESCAPE .sub (r'\1' , matcher .group (1 ))
384+ return f"`{ text } '"
385+
386+ @staticmethod
387+ def _tty_ify_sem_complex (matcher ):
388+ text = DocCLI ._UNESCAPE .sub (r'\1' , matcher .group (1 ))
389+ value = None
390+ if '=' in text :
391+ text , value = text .split ('=' , 1 )
392+ m = DocCLI ._FQCN_TYPE_PREFIX_RE .match (text )
393+ if m :
394+ plugin_fqcn = m .group (1 )
395+ plugin_type = m .group (2 )
396+ text = m .group (3 )
397+ elif text .startswith (DocCLI ._IGNORE_MARKER ):
398+ text = text [len (DocCLI ._IGNORE_MARKER ):]
399+ plugin_fqcn = plugin_type = ''
400+ else :
401+ plugin_fqcn = plugin_type = ''
402+ if value is not None :
403+ text = f"{ text } ={ value } "
404+ if plugin_fqcn and plugin_type :
405+ return f"`{ text } ' (of { plugin_type } { plugin_fqcn } )"
406+ return f"`{ text } '"
407+
374408 @classmethod
375409 def tty_ify (cls , text ):
376410
@@ -383,9 +417,10 @@ def tty_ify(cls, text):
383417 t = cls ._PLUGIN .sub ("[" + r"\1" + "]" , t ) # P(word#type) => [word]
384418 t = cls ._REF .sub (r"\1" , t ) # R(word, sphinx-ref) => word
385419 t = cls ._CONST .sub (r"`\1'" , t ) # C(word) => `word'
386- t = cls ._SEM_OPTION_NAME .sub (r"`\1'" , t ) # O(word) => `word'
387- t = cls ._SEM_OPTION_VALUE .sub (r"`\1'" , t ) # V(word) => `word'
388- t = cls ._SEM_ENV_VARIABLE .sub (r"`\1'" , t ) # E(word) => `word'
420+ t = cls ._SEM_OPTION_NAME .sub (cls ._tty_ify_sem_complex , t ) # O(expr)
421+ t = cls ._SEM_OPTION_VALUE .sub (cls ._tty_ify_sem_simle , t ) # V(expr)
422+ t = cls ._SEM_ENV_VARIABLE .sub (cls ._tty_ify_sem_simle , t ) # E(expr)
423+ t = cls ._SEM_RET_VALUE .sub (cls ._tty_ify_sem_complex , t ) # RV(expr)
389424 t = cls ._RULER .sub ("\n {0}\n " .format ("-" * 13 ), t ) # HORIZONTALLINE => -------
390425
391426 # remove rst
0 commit comments