Skip to content

Instantly share code, notes, and snippets.

@olimorris
Created January 25, 2026 10:29
Show Gist options
  • Select an option

  • Save olimorris/a025b1bbcdfdda5953a85bafdc6e5725 to your computer and use it in GitHub Desktop.

Select an option

Save olimorris/a025b1bbcdfdda5953a85bafdc6e5725 to your computer and use it in GitHub Desktop.
Anki Markdown Card Template - Syntax highlighting, KaTex support respects light/dark modes
<!-- 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(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/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>
@olimorris
Copy link
Author

Outputs:

2026-01-25 10_30_11 - Ghostty@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment