Skip to content

Commit

Permalink
Add retro-compatibility with older Anki versions
Browse files Browse the repository at this point in the history
  • Loading branch information
obynio committed Sep 28, 2022
1 parent 14a83ce commit 2d8f58b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ def setupGuiMenu():
mw.form.menuTools.addAction(useRubyTags)
mw.form.menuTools.addAction(ignoreNumbers)

def addButtons(buttons: list[str], editor: Editor) -> list[str]:
def addButtons(buttons, editor):
editor._links["generateFurigana"] = lambda ed=editor: doIt(ed, generateFurigana)
editor._links["deleteFurigana"] = lambda ed=editor: doIt(ed, deleteFurigana)
return buttons + [
editor._addButton(os.path.join(os.path.dirname(__file__), "icons", "add_furigana.svg"), "generateFurigana", tip=u"Automatically generate furigana"),
editor._addButton(os.path.join(os.path.dirname(__file__), "icons", "del_furigana.svg"), "deleteFurigana", tip=u"Mass delete furigana")
]

def doIt(editor: Editor, action: Callable[[Editor, Selection], None]):
def doIt(editor, action):
Selection(editor, lambda s: action(editor, s))

def generateFurigana(editor: Editor, s: Selection) -> None:
def generateFurigana(editor, s):
html = s.selected
html = re.sub('\[[^\]]*\]', '', html)
html = mecab.reading(html, config.getIgnoreNumbers(), config.getUseRubyTags())
Expand All @@ -64,7 +64,7 @@ def generateFurigana(editor: Editor, s: Selection) -> None:
else:
s.modify(html)

def deleteFurigana(editor: Editor, s: Selection) -> None:
def deleteFurigana(editor, s):
html = s.selected
if config.getUseRubyTags():
betweens = list(map(lambda x: "<ruby>"+x+"</ruby>", re.findall(r"<ruby>(.*?)<\/ruby>", html)))
Expand Down
10 changes: 5 additions & 5 deletions icons/add_furigana.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2d8f58b

Please sign in to comment.