diff --git a/ankihub/main/utils.py b/ankihub/main/utils.py index 8bc4d69c1..338de1f6e 100644 --- a/ankihub/main/utils.py +++ b/ankihub/main/utils.py @@ -36,6 +36,7 @@ # The following constants are used to identify AnkiHub modifications in note types. ANKIHUB_SNIPPET_MARKER = "ANKIHUB MODFICATIONS" ANKIHUB_SNIPPET_RE = ( + r"\n{0,2}" f"" r"[\w\W]*" f"" @@ -705,8 +706,13 @@ def note_type_without_template_and_style_modifications( note_type["css"] = ANKIHUB_CSS_COMMENT_RE.sub("", note_type["css"]).strip() for template in note_type["tmpls"]: template["qfmt"] = ANKIHUB_HTML_END_COMMENT_RE.sub("", template["qfmt"]).strip() + template["qfmt"] = re.sub( + ANKIHUB_SNIPPET_RE, + "", + template["qfmt"], + ) template["afmt"] = re.sub( - r"\n{0,2}" + ANKIHUB_SNIPPET_RE, + ANKIHUB_SNIPPET_RE, "", template["afmt"], ) diff --git a/tests/addon/test_integration.py b/tests/addon/test_integration.py index 408267a4a..b86ad810d 100644 --- a/tests/addon/test_integration.py +++ b/tests/addon/test_integration.py @@ -2456,6 +2456,7 @@ def test_note_type_templates_and_css_are_updated( else: assert new_qfmt not in updated_qfmt assert ANKIHUB_HTML_END_COMMENT in updated_qfmt + assert ANKIHUB_SNIPPET_MARKER in updated_qfmt updated_afmt = updated_note_type["tmpls"][0]["afmt"] if expected_template_and_css_updated: @@ -2465,7 +2466,6 @@ def test_note_type_templates_and_css_are_updated( assert new_afmt not in updated_afmt assert new_css not in updated_note_type["css"] assert ANKIHUB_HTML_END_COMMENT in updated_afmt - # This is only on the back template (afmt) assert ANKIHUB_SNIPPET_MARKER in updated_afmt # Check that there were no unwanted changes