-
I built an add-on to clean hyperlink text for images due to an issue with modified front/back templates not recognizing media with
in interactive fields, and these fields can only identify FILE.png to show the image. However when I share the deck with only the file name FILE.png, the media is not there. To overcome this, I want to share both a deck (sent with the native file with
so that the media is included) and and an addon to remove everything except FILE.png after downloading the deck. A personal add-on is successful at with this, but Iâd like to share it. This way the media is transported with .apkg and then cleaned up to be compatible with the modified front/back templates for interactive fields. The template isnât really what Iâm having issue with, the interactive fields work well with this hyperlink modification both manually and with the local add-on.
-
The problem is when in ~Anki2/addons21 folder, I have a folder for âMy Add-onâ with the init.py and manifest.json (I tried manifest.py too that doesnât work either). I compress âMy Add-onâ folder into a .zip, then change it to .ankiaddon. The icon changes to Anki. I double click, give it permission to download, then I get a message
Error installing â¨clean_image_fields.ankiaddonâŠ: â¨Invalid add-on manifest.âŠ
Please report this to the respective add-on author(s).
This is my manifest.json:
manifest.py
addon = {
ânameâ: âClean Image Fields (Ankoma)â,
âversionâ: â1.0.0â,
âdescriptionâ: âAllows users to clean image fields and simplify interactive content.â,
âauthorâ: âAnkomaTeamâ,
âconfigâ: {},
âplatformsâ: [âwindowsâ, âosxâ, âlinuxâ],
âaddon_idâ: âclean_image_fields_ankomaâ,
âdependenciesâ:
}
Return the dictionary for Anki to read
return addon
- Additionally, I try to upload the compressed file as either as .zip or .ankiaddon and neither works.
Here is the init.py
import re
from aqt import mw
from aqt.qt import QAction, qconnect
from anki.notes import Note
from anki.utils import ids2str
from aqt.utils import showInfo
def extract_filename_from_img_tag(html):
match = re.search(râ<img\s+src=â([^â]+)"', html)
return match.group(1) if match else html.strip()
def clean_image_src(note: Note):
fields_to_clean = [
âImage 2xâ, âImage 10xâ, âImage 20xâ, âTextbookâ,
âGross Imageâ, âStain Image 1â, âStain Image 2â, âStain Image 3â,
âGross Defaultâ, âStain Defaultâ
]
changed = False
for field in fields_to_clean:
if field in note:
original = note[field]
cleaned = extract_filename_from_img_tag(original)
if original != cleaned:
note[field] = cleaned
changed = True
if changed:
note.flush()
def run_cleaner():
note_type = âCloze Case Reviewâ
# Get all notes of this type
note_ids = mw.col.find_notes(fânote:â{note_type}â')
count = 0
for nid in note_ids:
note = mw.col.get_note(nid)
clean_image_src(note)
count += 1
showInfo(f"â
Cleaned {count} notes.")
Add menu item to Tools menu
action = QAction(âClean Image Fields (Ankoma)â, mw)
qconnect(action.triggered, run_cleaner)
mw.form.menuTools.addAction(action)
Can someone please help me share this addon?
Thanks so much!