Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Did You Solve iOS Highlight.js? #19

Closed
adeluccar opened this issue Jul 10, 2016 · 2 comments
Closed

How Did You Solve iOS Highlight.js? #19

adeluccar opened this issue Jul 10, 2016 · 2 comments

Comments

@adeluccar
Copy link

Hey @badlydrawnrob,

I have the following code in a template (Front Side):

<link rel="stylesheet" href="_highlight.css">
<script src="_highlight.js"></script>

<div class="question">
{{Question}}
</div>

<pre><code class="language-{{Code Snippet Language}}">
{{Code Snippet}}
</code></pre>

<script>
hljs.initHighlighting.called = false;
hljs.initHighlighting();
</script>

Do you know why this works in Anki OS X and not in IOS?

screen shot 2016-07-09 at 23 42 43

How did you fix it?

Would really appreciate if you could help me out.
I downloaded your deck but couldn't figure it out myself.
Thanks! :

—Alberto

@adeluccar
Copy link
Author

🆘

@badlydrawnrob
Copy link
Owner

@adeluccar Hi Alberto, I've been testing the Highlight.js script for a while now and honestly, I don't think Anki handles javascript well at all. I'm a complete novice with js, so perhaps someone else has a better method of handling Highlight.js (I've been looking for lighter examples, or different libraries, but no success yet) ...

The current method I'm using is the shim repository via Bower, with the following code:

var blocks = document.querySelectorAll('pre code:not(.hljs)');
Array.prototype.forEach.call(blocks, hljs.highlightBlock);

This works well on iOS, and partially in OSX (on the front card, but not on the reverse). The caveats are:

  1. Javascript must be inline, src= isn't supported (unless using an addon)
  2. iOS is really laggy at times, and it seems to crash AnkiDroid
  3. It really increases overall deck size and performance, as you can see in the below screenshot comparison (no media or scheduling have been included in the export):

screen shot 2016-08-15 at 17 28 39

So, until Anki fully supports src= js on all devices, I'm beginning to think using something like pygments is a far more practical solution, as there's backwards compatibility (albeit maintaining css for the code it outputs) and it can be safely swapped out for a js version if Anki eventually allows imports.

I've been using Power format pack quite a bit, which really speeds up card creation. So I'll open another issue and see what people think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants