Issue with uploading new add-on, issue with manifest

  1. 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.

  2. 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

  1. 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!

manifest.json should contain a package property. This works:

{
    "name": "Clean Image Fields (Ankoma)",
    "package": "clean_image_fields",
    "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": {}
}
1 Like