Anki is automatically removing custom HTML tags in my cards in version 25.02.1. Is this an intentional change or a bug?
Could you provide instructions on how to replicate this? Is this some add-on you’re using? We can’t help you unless you give us enough information.
@SuhasK Try writing something like <foo>test</foo>
in a field and notice the foo
tag is removed when you re-open the editor.
This appears to be the default behavior of the dompurify package. I tested with this change, which should fix the issue according to the docs, but it didn’t work for me:
diff --git a/ts/lib/domlib/sanitize.ts b/ts/lib/domlib/sanitize.ts
index d6ae4f049..9b3469292 100644
--- a/ts/lib/domlib/sanitize.ts
+++ b/ts/lib/domlib/sanitize.ts
@@ -6,5 +6,12 @@ import DOMPurify from "dompurify";
export function sanitize(html: string): string {
// We need to treat the text as a document fragment, or a style tag
// at the start of input will be discarded.
- return DOMPurify.sanitize(html, { FORCE_BODY: true });
+ return DOMPurify.sanitize(html, {
+ FORCE_BODY: true,
+ CUSTOM_ELEMENT_HANDLING: {
+ tagNameCheck: () => true,
+ attributeNameCheck: () => true,
+ allowCustomizedBuiltInElements: true,
+ },
+ });
}
That change does in fact work. It’s just that custom elements must contain a hyphen, e.g <foo-bar>
, so <foo>
isn’t considered to be one
I typed some custom HTML tags like <foo>
and <foo-bar>
. Next, I closed the “Edit Current” window. Finally, I reopened the window and found that the custom HTML tags had disappeared.
I had disabled all the add-ons. Therefore, I think this problem is not caused by the add-ons.
Here is the debug info:
Anki 25.02.1 (234fa0c2)
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1
Platform: Windows-10-10.0.19041
https://youtu.be/6DH3EjAQVXc