fix: preserve list context and nested CSS decoration behavior
This commit is contained in:
+36
-1
@@ -11,6 +11,7 @@ import re
|
||||
|
||||
import tinycss2 as css
|
||||
from tinycss2.color3 import parse_color
|
||||
from tinycss2.color4 import parse_color as parse_modern_color
|
||||
|
||||
from .document_style import (STYLE_TARGETS, normalize_rule, css_declarations,
|
||||
build_document_style_css, fmt, font_points, resolved_rules)
|
||||
@@ -253,13 +254,39 @@ def _invalid_core_value(prop, tokens):
|
||||
if prop in ('color','background-color','border-color') and len(tokens) == 1:
|
||||
token=tokens[0]
|
||||
if token.type != 'function': return parse_color(token) is None
|
||||
if token.lower_name in ('rgb','rgba','hsl','hsla','hwb','lab','lch','oklab','oklch','color'):
|
||||
# Relative colors and math are valid browser expressions that the
|
||||
# scalar color parser cannot evaluate. Preserve those as CSS.
|
||||
if not any(t.type=='function' or t.type=='ident' and t.lower_value=='from' for t in token.arguments):
|
||||
try: return parse_modern_color(token) is None
|
||||
except (ValueError, TypeError): return True
|
||||
if prop == 'font-style' and len(tokens) > 1:
|
||||
return not (len(tokens)==2 and tokens[0].type=='ident' and tokens[0].lower_value=='oblique'
|
||||
and tokens[1].type=='dimension' and tokens[1].lower_unit in ('deg','grad','rad','turn'))
|
||||
if prop == 'font':
|
||||
if len(tokens)==1:
|
||||
return not (tokens[0].type=='ident' and tokens[0].lower_value in ('caption','icon','menu','message-box','small-caption','status-bar'))
|
||||
# Valid but unsupported shorthands still reset the core font fields.
|
||||
size_index = next((i for i,t in enumerate(tokens)
|
||||
if t.type in ('dimension','percentage','function') and not (t.type=='dimension' and t.lower_unit in ('deg','grad','rad','turn'))
|
||||
or t.type=='number' and t.value==0
|
||||
or t.type=='ident' and t.lower_value in ('xx-small','x-small','small','medium','large','x-large','xx-large','xxx-large','smaller','larger')), None)
|
||||
if size_index is None or _invalid_core_value('font-size', [tokens[size_index]]): return True
|
||||
prefix_names = {'normal','italic','oblique','small-caps','bold','bolder','lighter',
|
||||
'ultra-condensed','extra-condensed','condensed','semi-condensed',
|
||||
'semi-expanded','expanded','extra-expanded','ultra-expanded'}
|
||||
for token in tokens[:size_index]:
|
||||
if token.type=='ident' and token.lower_value in prefix_names: continue
|
||||
if token.type=='number' and 1 <= token.value <= 1000: continue
|
||||
if token.type=='dimension' and token.lower_unit in ('deg','grad','rad','turn'): continue
|
||||
return True
|
||||
end = size_index + 1
|
||||
if end < len(tokens) and tokens[end].type=='literal' and tokens[end].value=='/':
|
||||
end += 2
|
||||
if end > len(tokens) or _invalid_core_value('line-height', [tokens[end-1]]): return True
|
||||
if end >= len(tokens): return True
|
||||
try: _font_names(_text(tokens[end:]))
|
||||
except ValueError: return True
|
||||
# Retain valid, unsupported prefixes and relative sizes as CSS.
|
||||
return False
|
||||
scalar = {'font-size','line-height','letter-spacing','text-indent','font-weight','color','background-color','text-align',
|
||||
'margin-top','margin-bottom','margin-left','margin-right'}
|
||||
@@ -270,6 +297,14 @@ def _invalid_core_value(prop, tokens):
|
||||
selected = [name for name in names if name in lines]
|
||||
if 'none' in selected and len(selected)>1 or len(selected)!=len(set(selected)): return True
|
||||
if prop == 'text-decoration-line': return any(t.type!='ident' or t.lower_value not in lines for t in tokens)
|
||||
for token in tokens:
|
||||
if token.type=='ident' and token.lower_value in lines | {'solid','double','dotted','dashed','wavy','auto','from-font'}: continue
|
||||
if token.type=='function':
|
||||
if _invalid_core_value('color', [token]): return True
|
||||
continue # Includes variable colors/thickness.
|
||||
if parse_color(token) is not None: continue
|
||||
if token.type in ('dimension','percentage','number') and not _invalid_core_value('font-size',[token]): continue
|
||||
return True
|
||||
if len(tokens) != 1: return False
|
||||
token = tokens[0]
|
||||
if token.type == 'string' and prop != 'font-family' and not prop.startswith('--'): return True
|
||||
|
||||
Reference in New Issue
Block a user