diff options
Diffstat (limited to 'asciidoc/asciidoc.py')
-rw-r--r-- | asciidoc/asciidoc.py | 61 |
1 files changed, 2 insertions, 59 deletions
diff --git a/asciidoc/asciidoc.py b/asciidoc/asciidoc.py index b158e44..f9607a6 100644 --- a/asciidoc/asciidoc.py +++ b/asciidoc/asciidoc.py @@ -32,6 +32,7 @@ import unicodedata from collections import OrderedDict +from .attrs import parse_attributes from .blocks.table import parse_table_span_spec, Cell, Column from .collections import AttrDict, InsensitiveDict from .exceptions import EAsciiDoc @@ -146,59 +147,6 @@ def safe_filename(fname, parentdir): return fname -def parse_attributes(attrs, dict): - """Update a dictionary with name/value attributes from the attrs string. - The attrs string is a comma separated list of values and keyword name=value - pairs. Values must precede keywords and are named '1','2'... The entire - attributes list is named '0'. If keywords are specified string values must - be quoted. Examples: - - attrs: '' - dict: {} - - attrs: 'hello,world' - dict: {'2': 'world', '0': 'hello,world', '1': 'hello'} - - attrs: '"hello", planet="earth"' - dict: {'planet': 'earth', '0': '"hello",planet="earth"', '1': 'hello'} - """ - def f(*args, **keywords): - # Name and add arguments '1','2'... to keywords. - for i in range(len(args)): - if not str(i + 1) in keywords: - keywords[str(i + 1)] = args[i] - return keywords - - if not attrs: - return - dict['0'] = attrs - # Replace line separators with spaces so line spanning works. - s = re.sub(r'\s', ' ', attrs) - d = {} - try: - d.update(utils.get_args(s)) - d.update(utils.get_kwargs(s)) - for v in list(d.values()): - if not (isinstance(v, str) or isinstance(v, int) or isinstance(v, float) or v is None): - raise Exception - except Exception: - s = s.replace('"', '\\"') - s = s.split(',') - s = ['"' + x.strip() + '"' for x in s] - s = ','.join(s) - try: - d = {} - d.update(utils.get_args(s)) - d.update(utils.get_kwargs(s)) - except Exception: - return # If there's a syntax error leave with {0}=attrs. - for k in list(d.keys()): # Drop any empty positional arguments. - if d[k] == '': - del d[k] - dict.update(d) - assert len(d) > 0 - - def parse_named_attributes(s, attrs): """Update a attrs dictionary with name="value" attributes from the s string. Returns False if invalid syntax. @@ -218,7 +166,7 @@ def parse_named_attributes(s, attrs): return False -def parse_list(s): +def parse_list(s) -> typing.Tuple: """Parse comma separated string of Python literals. Return a tuple of of parsed values.""" try: @@ -242,11 +190,6 @@ def parse_options(options, allowed, errmsg): return tuple(result) -def symbolize(s): - """Drop non-symbol characters and convert to lowercase.""" - return re.sub(r'[^\w\-_]', '', s).lower() - - def is_name(s): """Return True if s is valid attribute, macro or tag name (starts with alpha containing alphanumeric and dashes only).""" |