Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions delta/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ def styled(element, styles):
if element.tag != 'span':
element = sub_element(element, 'span')
declare = parseStyle(element.attrib.get('style', ''))
for k, v in styles.items():
declare.setProperty(k, v)
element.attrib['style'] = declare.getCssText(' ')
try:
for k, v in styles.items():
declare.setProperty(k, v)
element.attrib['style'] = declare.getCssText(' ')
except:
# Ignore invalid css attributes
pass
return element

def classed(element, *classes):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ def test_colors():
source = '<p><span style="background-color: #000; color: #FFF">quill</span></p>'
assert html.render(ops) == source

def test_unsupported_style_attribute():
ops = [
{"insert": "quill", "attributes": {"color": "var(--some-color)", "background": "#000000"}}
]

source = '<p><span style="background-color: #000">quill</span></p>'
assert html.render(ops) == source

ops = [
{"insert": "quill", "attributes": {"background": "#000000", "color": "#FFFFFF"}}
]

source = '<p><span style="background-color: #000; color: #FFF">quill</span></p>'
assert html.render(ops) == source

def test_classes():
ops = [
{"insert":"Quill", "attributes": {"font": "monospace", "size": "huge"}}
Expand Down