mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
More tests for cascade
This commit is contained in:
parent
0d77ec1451
commit
91c85b351c
@ -108,6 +108,7 @@ class Values(tuple):
|
||||
|
||||
@property
|
||||
def cssText(self):
|
||||
' This will return either a string or a tuple of strings '
|
||||
if len(self) == 1:
|
||||
return self[0].cssText
|
||||
return tuple(x.cssText for x in self)
|
||||
@ -136,7 +137,7 @@ def resolve_declarations(decls):
|
||||
ans[name] = first_val
|
||||
return ans
|
||||
|
||||
def resolve_styles(container, name, select=None):
|
||||
def resolve_styles(container, name, select=None, sheet_callback=None):
|
||||
root = container.parsed(name)
|
||||
select = select or Select(root, ignore_inappropriate_pseudo_classes=True)
|
||||
style_map = defaultdict(list)
|
||||
@ -145,6 +146,8 @@ def resolve_styles(container, name, select=None):
|
||||
pseudo_pat = re.compile(ur':{1,2}(%s)' % ('|'.join(INAPPROPRIATE_PSEUDO_CLASSES)), re.I)
|
||||
|
||||
def process_sheet(sheet, sheet_name):
|
||||
if sheet_callback is not None:
|
||||
sheet_callback(sheet, sheet_name)
|
||||
for rule, sheet_name, rule_index in iterrules(container, sheet_name, rules=sheet, rule_index_counter=rule_index_counter, rule_type='STYLE_RULE'):
|
||||
for selector in rule.selectorList:
|
||||
text = selector.selectorText
|
||||
|
@ -74,7 +74,7 @@ class CascadeTest(BaseTest):
|
||||
|
||||
def get_maps(html, styles=None):
|
||||
html = '<html><head><link href="styles.css"></head><body>{}</body></html>'.format(html)
|
||||
c = VirtualContainer({'index.html':html, 'styles.css':styles or 'body { color: red }'})
|
||||
c = VirtualContainer({'index.html':html, 'styles.css':styles or 'body { color: red; font-family: "Kovid Goyal", sans-serif }'})
|
||||
style_map, pseudo_style_map, select = resolve_styles(c, 'index.html')
|
||||
tp = partial(test_property, select, style_map)
|
||||
return tp
|
||||
@ -87,6 +87,20 @@ class CascadeTest(BaseTest):
|
||||
t('b', 'margin-top')
|
||||
t('body', 'display', 'block')
|
||||
t('b', 'display', 'inline')
|
||||
t('body', 'font-family', ('"Kovid Goyal"', 'sans-serif'))
|
||||
for e in ('body', 'p', 'b'):
|
||||
for prop in 'background-color text-indent'.split():
|
||||
t(e, prop)
|
||||
|
||||
t = get_maps('<p>xxx</p><style>p {color: blue}</style>', 'p {color: red}')
|
||||
t('p', 'color', 'blue')
|
||||
t = get_maps('<p style="color: blue">xxx</p>', 'p {color: red}')
|
||||
t('p', 'color', 'blue')
|
||||
t = get_maps('<p style="color: blue">xxx</p>', 'p {color: red !important}')
|
||||
t('p', 'color', 'red')
|
||||
t = get_maps('<p id="p">xxx</p>', '#p { color: blue } p {color: red}')
|
||||
t('p', 'color', 'blue')
|
||||
t = get_maps('<p>xxx</p>', 'p {color: red; color: blue}')
|
||||
t('p', 'color', 'blue')
|
||||
t = get_maps('<p>xxx</p><style>p {color: blue}</style>', 'p {color: red; margin:11pt}')
|
||||
t('p', 'margin-top', '11pt')
|
||||
|
Loading…
x
Reference in New Issue
Block a user