mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 08:27:22 +03:00
Use parentheses at the end of functions keywords
This commit is contained in:
parent
85a65d76c8
commit
cb4fa7ef06
@ -413,8 +413,8 @@ def content(computer, name, values):
|
||||
|
||||
def parse_target_type(type_, values):
|
||||
# values = ['string', <anchorname>, ...]
|
||||
# or ['attr', <attrname>, ... ]
|
||||
if values[0] == 'attr':
|
||||
# or ['attr()', <attrname>, ... ]
|
||||
if values[0] == 'attr()':
|
||||
attrname = values[1][0]
|
||||
href = computer.element.get(attrname, '')
|
||||
else:
|
||||
@ -441,7 +441,7 @@ def content(computer, name, values):
|
||||
|
||||
result = []
|
||||
for type_, value in values:
|
||||
if type_ == 'attr':
|
||||
if type_ == 'attr()':
|
||||
attr_name, type_or_unit, fallback = value
|
||||
if type_or_unit != 'string':
|
||||
# TODO: could be attr()
|
||||
@ -552,7 +552,7 @@ def link(computer, name, values):
|
||||
return None
|
||||
else:
|
||||
type_, value = values
|
||||
if type_ == 'attr':
|
||||
if type_ == 'attr()':
|
||||
return get_link_attribute(
|
||||
computer.element, value, computer.base_url)
|
||||
else:
|
||||
@ -566,7 +566,7 @@ def lang(computer, name, values):
|
||||
return None
|
||||
else:
|
||||
type_, key = values
|
||||
if type_ == 'attr':
|
||||
if type_ == 'attr()':
|
||||
return computer.element.get(key) or None
|
||||
elif type_ == 'string':
|
||||
return key
|
||||
|
@ -1143,7 +1143,7 @@ def anchor(token):
|
||||
prototype = (name, [a.type for a in args])
|
||||
args = [getattr(a, 'value', a) for a in args]
|
||||
if prototype == ('attr', ['ident']):
|
||||
return (name, args[0])
|
||||
return ('attr()', args[0])
|
||||
|
||||
|
||||
@property(proprietary=True, wants_base_url=True)
|
||||
@ -1161,7 +1161,7 @@ def link(token, base_url):
|
||||
prototype = (name, [a.type for a in args])
|
||||
args = [getattr(a, 'value', a) for a in args]
|
||||
if prototype == ('attr', ['ident']):
|
||||
return (name, args[0])
|
||||
return ('attr()', args[0])
|
||||
|
||||
|
||||
@property()
|
||||
@ -1258,7 +1258,7 @@ def lang(token):
|
||||
prototype = (name, [a.type for a in args])
|
||||
args = [getattr(a, 'value', a) for a in args]
|
||||
if prototype == ('attr', ['ident']):
|
||||
return (name, args[0])
|
||||
return ('attr()', args[0])
|
||||
elif token.type == 'string':
|
||||
return ('string', token.value)
|
||||
|
||||
|
@ -402,7 +402,7 @@ def check_attr_function(token, allowed_type=None):
|
||||
else:
|
||||
pass
|
||||
if allowed_type in (None, type_or_unit):
|
||||
return ('attr', (attr_name, type_or_unit, fallback))
|
||||
return ('attr()', (attr_name, type_or_unit, fallback))
|
||||
|
||||
|
||||
def check_counter_function(token, allowed_type=None):
|
||||
@ -432,7 +432,7 @@ def check_counter_function(token, allowed_type=None):
|
||||
else:
|
||||
arguments.append('decimal')
|
||||
|
||||
return (name, tuple(arguments))
|
||||
return ('%s()' % name, tuple(arguments))
|
||||
|
||||
|
||||
def check_content_function(token):
|
||||
@ -442,12 +442,12 @@ def check_content_function(token):
|
||||
name, args = function
|
||||
if name == 'content':
|
||||
if len(args) == 0:
|
||||
return ('content', 'text')
|
||||
return ('content()', 'text')
|
||||
elif len(args) == 1:
|
||||
ident = args.pop(0)
|
||||
if ident.type == 'ident' and ident.lower_value in (
|
||||
'text', 'before', 'after', 'first-letter', 'marker'):
|
||||
return ('content', ident.lower_value)
|
||||
return ('content()', ident.lower_value)
|
||||
|
||||
|
||||
def check_string_function(token):
|
||||
@ -470,7 +470,7 @@ def check_string_function(token):
|
||||
else:
|
||||
ident = 'first'
|
||||
|
||||
return ('string-set', (custom_ident, ident))
|
||||
return ('string()', (custom_ident, ident))
|
||||
|
||||
|
||||
def get_string(token):
|
||||
|
@ -256,26 +256,26 @@ def compute_content_list(content_list, parent_box, counter_values, parse_again,
|
||||
texts = []
|
||||
boxlist.append(
|
||||
boxes.InlineReplacedBox.anonymous_from(parent_box, image))
|
||||
elif type_ == 'content':
|
||||
elif type_ == 'content()':
|
||||
added_text = TEXT_CONTENT_EXTRACTORS[value](parent_box)
|
||||
# Simulate the step of white space processing
|
||||
# (normally done during the layout)
|
||||
added_text = added_text.strip()
|
||||
texts.append(added_text)
|
||||
elif type_ == 'counter':
|
||||
elif type_ == 'counter()':
|
||||
counter_name, counter_style = value
|
||||
counter_value = counter_values.get(counter_name, [0])[-1]
|
||||
texts.append(counters.format(counter_value, counter_style))
|
||||
elif type_ == 'counters':
|
||||
elif type_ == 'counters()':
|
||||
counter_name, separator, counter_style = value
|
||||
texts.append(separator.join(
|
||||
counters.format(counter_value, counter_style)
|
||||
for counter_value in counter_values.get(counter_name, [0])))
|
||||
elif type_ == 'string-set' and (
|
||||
elif type_ == 'string()' and (
|
||||
context is not None and page is not None):
|
||||
# string() is only valid in @page context
|
||||
texts.append(context.get_string_set_for(page, *value))
|
||||
elif type_ == 'attr' and element is not None:
|
||||
elif type_ == 'attr()' and element is not None:
|
||||
attr_name, type_or_unit, fallback = value
|
||||
assert type_or_unit == 'string'
|
||||
texts.append(element.get(attr_name, fallback))
|
||||
|
@ -629,9 +629,9 @@ def test_line_height():
|
||||
def test_string_set():
|
||||
"""Test the ``string-set`` property."""
|
||||
assert expand_to_dict('string-set: test content(text)') == {
|
||||
'string_set': (('test', (('content', 'text'),)),)}
|
||||
'string_set': (('test', (('content()', 'text'),)),)}
|
||||
assert expand_to_dict('string-set: test content(before)') == {
|
||||
'string_set': (('test', (('content', 'before'),)),)}
|
||||
'string_set': (('test', (('content()', 'before'),)),)}
|
||||
assert expand_to_dict('string-set: test "string"') == {
|
||||
'string_set': (('test', (('string', 'string'),)),)}
|
||||
assert expand_to_dict(
|
||||
@ -640,27 +640,28 @@ def test_string_set():
|
||||
('test1', (('string', 'string'),)),
|
||||
('test2', (('string', 'string'),)))}
|
||||
assert expand_to_dict('string-set: test attr(class)') == {
|
||||
'string_set': (('test', (('attr', ('class', 'string', '')),)),)}
|
||||
'string_set': (('test', (('attr()', ('class', 'string', '')),)),)}
|
||||
assert expand_to_dict('string-set: test counter(count)') == {
|
||||
'string_set': (('test', (('counter', ('count', 'decimal')),)),)}
|
||||
'string_set': (('test', (('counter()', ('count', 'decimal')),)),)}
|
||||
assert expand_to_dict(
|
||||
'string-set: test counter(count, upper-roman)') == {
|
||||
'string_set': (
|
||||
('test', (('counter', ('count', 'upper-roman')),)),)}
|
||||
('test', (('counter()', ('count', 'upper-roman')),)),)}
|
||||
assert expand_to_dict('string-set: test counters(count, ".")') == {
|
||||
'string_set': (('test', (('counters', ('count', '.', 'decimal')),)),)}
|
||||
'string_set': (
|
||||
('test', (('counters()', ('count', '.', 'decimal')),)),)}
|
||||
assert expand_to_dict(
|
||||
'string-set: test counters(count, ".", upper-roman)') == {
|
||||
'string_set': (
|
||||
('test', (('counters', ('count', '.', 'upper-roman')),)),)}
|
||||
('test', (('counters()', ('count', '.', 'upper-roman')),)),)}
|
||||
assert expand_to_dict(
|
||||
'string-set: test content(text) "string" '
|
||||
'attr(title) attr(title) counter(count)') == {
|
||||
'string_set': (('test', (
|
||||
('content', 'text'), ('string', 'string'),
|
||||
('attr', ('title', 'string', '')),
|
||||
('attr', ('title', 'string', '')),
|
||||
('counter', ('count', 'decimal')))),)}
|
||||
('content()', 'text'), ('string', 'string'),
|
||||
('attr()', ('title', 'string', '')),
|
||||
('attr()', ('title', 'string', '')),
|
||||
('counter()', ('count', 'decimal')))),)}
|
||||
|
||||
assert_invalid('string-set: test')
|
||||
assert_invalid('string-set: test test1')
|
||||
|
Loading…
Reference in New Issue
Block a user