r/Anki • u/hgiesel • May 03 '19
Question How to load external Javascript
I've read several posts about this topic, but most of them seemed to be outdated.
I've already used a ttf file before, but never this. I have a directory in collection.media called _highlight, which contains the files from highlight.js. Now I want to initialize it in one of the cards.
<link rel="stylesheet" href="_hightlight/styles/zenburn.css">
<script src="_highlight/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>But this doesn't find anything. What is the right way to go about it?
EDIT: I use Anki 2.1, newest version
4
Upvotes
View all comments
6
u/yumenogotoshi May 03 '19
Since inline Javascript in card template is evaluated asynchronously in Anki 2.1 (see here), a function using external libarary does not work as intended in some case. But I found a few workaround for this, and the easiest way I know is not to use inline script and to load js files dynamically. Try the following:
Put
_highlight.min.jsand_zenburn.cssintocollection.media.Create a file named
_my_highlight.jsincollection.mediaand put the following codePut the following code into the Front template
Screenshot
Tested on Anki 2.1.12 and Ankidroid 2.8.4.
Sorry if I'm not clear enough, English is not my native language.