Skip to content

Commit

Permalink
Don't produce invalid HTML warning for CDATA
Browse files Browse the repository at this point in the history
If a field contains a CDATA section, don't produce a warning saying that
it contains invalid HTML tags.

See kerrickstaley#108
  • Loading branch information
kerrickstaley committed May 22, 2022
1 parent 1b43c75 commit 2f22b94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion genanki/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def insert(self, i, tag):


class Note:
_INVALID_HTML_TAG_RE = re.compile(r'<(?!/?[a-zA-Z0-9]+(?: .*|/?)>|!--)(?:.|\n)*?>')
_INVALID_HTML_TAG_RE = re.compile(r'<(?!/?[a-zA-Z0-9]+(?: .*|/?)>|!--|!\[CDATA\[)(?:.|\n)*?>')

def __init__(self, model=None, fields=None, sort_field=None, tags=None, guid=None, due=0):
self.model = model
Expand Down
4 changes: 4 additions & 0 deletions tests/test_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def test_ok_html_comment(self):
# see https://github.com/kerrickstaley/genanki/issues/108
assert genanki.Note._find_invalid_html_tags_in_field('<!-- here is a comment -->') == []

def test_ok_cdata(self):
# see https://github.com/kerrickstaley/genanki/issues/108
assert genanki.Note._find_invalid_html_tags_in_field('<![CDATA[ here is some cdata ]]>') == []


def test_warns_on_invalid_html_tags():
my_model = genanki.Model(
Expand Down

0 comments on commit 2f22b94

Please sign in to comment.