Created
January 25, 2026 10:29
-
-
Save olimorris/a025b1bbcdfdda5953a85bafdc6e5725 to your computer and use it in GitHub Desktop.
Anki Markdown Card Template - Syntax highlighting, KaTex support respects light/dark modes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- FRONT CARD --> | |
| <script type="module" src="https://cdn.jsdelivr.net/npm/zero-md@3?register"></script> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css"> | |
| <zero-md> | |
| <template data-append> | |
| <style> | |
| div { | |
| background-color: transparent !important; | |
| } | |
| </style> | |
| </template> | |
| <script type="text/markdown"> | |
| {{Front}} | |
| </script> | |
| </zero-md> | |
| <!-- BACK CARD --> | |
| <script type="module" src="https://cdn.jsdelivr.net/npm/zero-md@3?register"></script> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css"> | |
| <zero-md> | |
| <template data-append> | |
| <style> | |
| div { | |
| background-color: transparent !important; | |
| } | |
| </style> | |
| </template> | |
| <script type="text/markdown"> | |
| {{Front}} | |
| </script> | |
| </zero-md> | |
| <hr id=answer> | |
| <zero-md> | |
| <template data-append> | |
| <style> | |
| div { | |
| background-color: transparent !important; | |
| } | |
| </style> | |
| </template> | |
| <script type="text/markdown"> | |
| {{Back}} | |
| </script> | |
| </zero-md> | |
| <script> | |
| (function() { | |
| function unescapeEntities(text) { | |
| return text | |
| .replace(/&/g, '&') | |
| .replace(/</g, '<') | |
| .replace(/>/g, '>') | |
| .replace(/"/g, '"'); | |
| } | |
| function fixMarkdownScripts() { | |
| document.querySelectorAll('script[type="text/markdown"]').forEach(script => { | |
| const original = script.textContent; | |
| const fixed = unescapeEntities(original); | |
| if (original !== fixed) { | |
| script.textContent = fixed; | |
| } | |
| }); | |
| } | |
| fixMarkdownScripts(); | |
| // Watch for any DOM changes (like when Anki flips cards) | |
| const observer = new MutationObserver(() => { | |
| fixMarkdownScripts(); | |
| }); | |
| observer.observe(document.body, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| // Also fix on visibility change (when card is shown/hidden) | |
| document.addEventListener('visibilitychange', fixMarkdownScripts); | |
| })(); | |
| </script> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs: