Make add_marker easier to use with combine

This commit is contained in:
Kovid Goyal 2020-01-13 09:56:39 +05:30
parent 624dd78460
commit 072cd29e3c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -243,22 +243,18 @@ def disable_ligatures_in(func, rest):
@func_with_args('add_marker') @func_with_args('add_marker')
def add_marker(func, rest): def add_marker(func, rest):
parts = rest.split(maxsplit=1) parts = rest.split(maxsplit=2)
if len(parts) != 2: if len(parts) != 3:
raise ValueError('{} if not a valid marker specification'.format(rest)) raise ValueError('{} if not a valid marker specification'.format(rest))
name = parts[0] name, ftype, spec = parts
parts = parts[1].split(':', maxsplit=1)
if len(parts) != 2:
raise ValueError('{} if not a valid marker specification'.format(rest))
ftype, spec = parts
color = None color = None
if ftype in ('text', 'itext', 'regex'): if ftype in ('text', 'itext', 'regex'):
flags = re.UNICODE flags = re.UNICODE
parts = spec.split(':', maxsplit=1) parts = spec.split(maxsplit=1)
if len(parts) != 2: if len(parts) != 2:
raise ValueError('No color specified in marker: {}'.format(spec)) raise ValueError('No color specified in marker: {}'.format(spec))
try: try:
color = int(parts[0]) color = max(1, min(int(parts[0]), 3))
except Exception: except Exception:
raise ValueError('color {} in marker specification is not an integer'.format(parts[0])) raise ValueError('color {} in marker specification is not an integer'.format(parts[0]))
spec = parts[1] spec = parts[1]