Skip to content

Commit

Permalink
Add support for the anki-reviewer-file-hyperlinks add-on
Browse files Browse the repository at this point in the history
  • Loading branch information
glutanimate committed Jun 3, 2017
1 parent 3dced4f commit 9e63a33
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions advanced_previewer/previewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
except ImportError:
preview_jsbooster = False

# support for anki-reviewer-file-hyperlinks add-on
try:
fHyperlinks = __import__("anki-reviewer-file-hyperlinks")
preview_arfh = True
except ImportError:
preview_arfh = False

def onTogglePreview(self):
"""only used to set the link handler after loading the preview window
(required in order to be compatible with "Replay Buttons on Card")"""
Expand Down Expand Up @@ -266,10 +273,20 @@ def previewLinkHandler(self, url):
# support for 'Replay Buttons on Card' add-on
clearAudioQueue() # stop current playback
play(url[8:])
elif url.startswith("open") and preview_arfh:
# support for anki-reviewer-file-hyperlinks
(cmd, arg) = url.split(":", 1)
fHyperlinks.openFileHandler(arg)
else:
# handle regular links with the default link handler
openLink(url)

def insertFileLinks(html):
"""Support for anki-reviewer-file-hyperlinks"""
if not preview_arfh:
return html
return fHyperlinks.linkInserter(html)

def scrollToPreview(self, cid):
"""Adjusts preview window scrolling position to show supplied card"""
self._previewWeb.eval("""
Expand Down Expand Up @@ -341,6 +358,9 @@ def renderPreview(self, cardChanged=False):
ctxt = scriptre.sub("", ctxt)
txt += html.format(cid, c.ord+1, ctxt)
txt = re.sub("\[\[type:[^]]+\]\]", "", txt)
if preview_arfh:
# support for anki-reviewer-file-hyperlinks add-on
txt = insertFileLinks(txt)
ti = lambda x: x
base = getBase(self.mw.col)
if preview_jsbooster:
Expand Down

0 comments on commit 9e63a33

Please sign in to comment.