badlydrawnrob / anki

Learn to code with Anki — flashcards and themes for all learning levels. Master your programming language of choice!
MIT License
747 stars 62 forks source link

Experimental: highlight.js for Anki and AnkiMobile #6

Closed badlydrawnrob closed 8 years ago

badlydrawnrob commented 9 years ago

Currently using highlight.js shim and copy and paste html via Marked App viewer (right-click, copy and paste in Anki html view). Also see Marked App html exporting):

badlydrawnrob commented 9 years ago

Default hljs.initHighlightingOnLoad(); doesn't work on iOS app. I have no idea why! Luckily, thanks to this thread, the below seems to work :+1: ... for now at least.

hljs.initHighlighting.called = false;
hljs.initHighlighting();

When opening cards in the Mac app, it takes a while to close down. Hopefully this won't impact performance of the app.

badlydrawnrob commented 9 years ago

Also refer to this issue for an alternative method suggested by the plugin's creator:

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

Changed the above code also to reflect this edit

badlydrawnrob commented 9 years ago

Minified script doesn't work

badlydrawnrob commented 9 years ago

Correct code snippet below, requires hljs.

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

This seems to only affect the front card, not the reverse. Seems to work fine on iOS, works on browse mode on Mac OS (if a little buggy) but doesn't seem to work in drill mode on Mac OS.

badlydrawnrob commented 9 years ago

Ok so progress so far using unminified highlights shim, with script and calling script on only the front card:

hljs.initHighlightingOnLoad();
var blocks = document.querySelectorAll('pre code:not(.hljs)');
Array.prototype.forEach.call(blocks, hljs.highlightBlock);
hljs.initHighlighting.called = false;
hljs.initHighlighting();
badlydrawnrob commented 9 years ago

Mac app console log, not particularly helpful

Anki[9545]: JS error on line 7567: SyntaxError: Parse error
Anki[9545]: JS error on line 0: ReferenceError: Can't find variable: hljs
Anki[9545]: JS error on line 7567: SyntaxError: Parse error
Anki[9545]: JS error on line 0: ReferenceError: Can't find variable: hljs
badlydrawnrob commented 8 years ago

Closing this as #21 is infinitely easier to mantain. Too many bugs.