From 2cd359e8a442a36960875f155b8f1be277e1de56 Mon Sep 17 00:00:00 2001 From: Stefan Jeremic Date: Mon, 23 Nov 2020 03:58:49 +0100 Subject: [PATCH] Ignore unsuported style attributes --- delta/html.py | 10 +++++++--- tests/test_html.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/delta/html.py b/delta/html.py index d34fed8..7dd0582 100644 --- a/delta/html.py +++ b/delta/html.py @@ -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): diff --git a/tests/test_html.py b/tests/test_html.py index 614d05c..e1a69af 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -59,6 +59,21 @@ def test_colors(): source = '

quill

' assert html.render(ops) == source +def test_unsupported_style_attribute(): + ops = [ + {"insert": "quill", "attributes": {"color": "var(--some-color)", "background": "#000000"}} + ] + + source = '

quill

' + assert html.render(ops) == source + + ops = [ + {"insert": "quill", "attributes": {"background": "#000000", "color": "#FFFFFF"}} + ] + + source = '

quill

' + assert html.render(ops) == source + def test_classes(): ops = [ {"insert":"Quill", "attributes": {"font": "monospace", "size": "huge"}}