Skip to content
Merged
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
8 changes: 7 additions & 1 deletion ankihub/main/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<!-- BEGIN {ANKIHUB_SNIPPET_MARKER} -->"
r"[\w\W]*"
f"<!-- END {ANKIHUB_SNIPPET_MARKER} -->"
Expand Down Expand Up @@ -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"],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/addon/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Loading