Inline CSS Cleanup

AnkiWeb addon 465508076

Extracts and deduplicates inline CSS from selected note fields, moves it to a shared media file, then inserts import links—optionally handling repeated inline styles, base64 images and Yomitan media references—to shrink collections.
AI-generated summary; may contain mistakes.

sync-integrationnote-managementformattingbackup-maintenance

Open on AnkiWeb GitHub Find alternatives

AnkiWeb

Votes
2 (👍 2 · 👎 0)
Updated
2026-09-14
Anki versions
23.12~
License
AGPL-3.0 (from the headers of the Python files)
Virus scan
No ClamAV match A match does not prove malware. No match does not prove that the code is safe.
Languages
Python, JSON
Description language
en

Maintenance

active

  • Last update or commit: 2026-09-14 (48 days before the snapshot).
  • GitHub Actions workflows: 1.
  • Commits in the last year: 25.
  • Issues: 0 open, 0 closed.
  • Pull requests: 1 open, 1 merged.

Will it work on my Anki?

Version branches
Min AnkiMax AnkiUpdated
23.12+2026-09-14
History across monthly snapshots

Loading…

Similar addons

Inline media

Inserts and plays audio/video from URLs or local files inline in the reviewer, converting formats via FFmpeg, with clipboard shortcuts, per-element playback settings, and orphaned-media cleanup.

card-creationformattingmobile-compatible

7 votes 36% approval 👍 5 · 👎 2 Anki 2.1.66~ Updated 2022-07-24

Description

Inline CSS Cleanup

Remove inline <style>…</style> blocks from selected note fields and move the CSS into collection.media/_extracted_css.css, with selector-level deduplication.

This is useful when large HTML fields (e.g., Yomitan/JP mining glossaries) embed repeated CSS, bloating collection.anki2 and pushing you over AnkiWeb size limits.

What It Does

  • Strips inline <style>…</style> blocks from configured fields
  • Extracts CSS and deduplicates by selector (first occurrence wins)
  • Writes the CSS to collection.media/_extracted_css.css
  • Inserts a small <style>@import ...</style> into the field to load the CSS

Usage

  1. Tools → Inline CSS Cleanup
  2. Confirm the prompt
  3. Review the summary dialog
  4. Run Check Database to shrink the collection file after cleanup

Example Screenshot

Configuration

See config.md for detailed configuration.

Quick defaults (from config.json):

{
  "note_types": ["Lapis"],
  "fields": ["Glossary", "MainDefinition"],
  "confirm_before_run": true,
  "extract_inline_styles": false,
  "inline_style_min_length": 80,
  "inline_style_min_ratio": 0.05
}

Notes & Safety

  • The add-on does not modify template Styling (useful if your Styling is auto-generated).
  • Re-running is safe and idempotent: it will not duplicate imports or rules.
  • Consider backing up your collection before the first run.
  • Inline style extraction thresholds are based on the number of notes containing inline styles.
  • Extracted CSS is stored in collection.media/_extracted_css.css and also mirrored to user_files/extracted_css.css (easier to find).

README

Inline CSS Cleanup

Remove inline <style>…</style> blocks from selected note fields and move the CSS into collection.media/_extracted_css.css, with selector-level deduplication.

This is useful when large HTML fields (e.g., Yomitan/JP mining glossaries) embed repeated CSS, bloating collection.anki2 and pushing you over AnkiWeb size limits.

What It Does

  • Strips inline <style>…</style> blocks from configured fields
  • Extracts CSS and deduplicates by selector (first occurrence wins)
  • Writes the CSS to collection.media/_extracted_css.css
  • Inserts a small <style>@import ...</style> into the field to load the CSS
  • Optionally extracts repeated style="..." attributes into CSS classes
  • Optionally extracts embedded data:image/...;base64,... image sources to media files
  • Optionally rewrites old Yomitan media references to existing same-content media files

Install

Option A — AnkiWeb code:

  1. In Anki: Tools → Add-ons → Get Add-ons…
  2. Enter the code 465508076
  3. Restart Anki

Option B — GitHub Release:

  1. Download inline-css-cleanup.ankiaddon from the latest GitHub Release
  2. In Anki: Tools → Add-ons → Install from file…
  3. Select the downloaded .ankiaddon file and restart Anki

Option C — Build from source:

  1. Download the source code
  2. Run ./package.sh to build inline-css-cleanup.ankiaddon
  3. In Anki: Tools → Add-ons → Install from file…
  4. Select the .ankiaddon file and restart Anki

Release

GitHub Actions builds the add-on on pull requests, pushes to main, manual runs, and tags matching v*.

To publish a release:

  1. Create and push a tag such as v0.2.0
  2. The workflow builds dist/inline-css-cleanup.ankiaddon
  3. The tag run creates or updates the GitHub Release asset automatically

Usage

  1. Tools → Inline CSS Cleanup
  2. Choose whether to process all decks or select specific decks
  3. Add the target note types in Target note types
  4. Pick a note type in Fields for and select the fields to clean
  5. Adjust inline-style extraction options if needed
  6. Click Run Cleanup
  7. Review the summary in the window
  8. Run Check Database to shrink the collection file after cleanup

To fix duplicate media references created by old Yomitan versions, use the same deck, note type, and field selectors, then click Fix Yomitan Media Refs. This uses Anki's media database checksums to point yomitan_dictionary_media_* and yomitan_audio_* references at an existing same-content file. It does not create, delete, move, or scan media files.

Use Save Defaults to persist the current deck, note type, field, and cleanup options to the add-on config.

Example Screenshot

Example

Configuration

See config.md for detailed configuration.

Quick defaults (from config.json):

{
  "decks": [],
  "note_types": ["Lapis"],
  "fields": ["Glossary", "MainDefinition"],
  "fields_by_note_type": {
    "Lapis": ["Glossary", "MainDefinition"]
  },
  "confirm_before_run": true,
  "extract_inline_styles": false,
  "extract_data_image_sources": false,
  "inline_style_min_length": 80,
  "inline_style_min_ratio": 0.05
}

Notes & Safety

  • The add-on does not modify template Styling (useful if your Styling is auto-generated).
  • Re-running is safe and idempotent: it will not duplicate imports or rules.
  • Consider backing up your collection before the first run.
  • Extracted inline styles are emitted with !important to better preserve appearance.
  • Inline style extraction thresholds are based on the number of notes containing inline styles.
  • Extracted data images are stored as hoshi_dict_<sha1>.<ext> media files, matching Hoshi Reader's AnkiConnect dictionary media naming.
  • Extracted CSS is stored in collection.media/_extracted_css.css and also mirrored to user_files/extracted_css.css (easier to find).
  • Yomitan media repair only rewrites note field references. Use Anki's Check Media if you want to review unreferenced duplicate files afterward.

License

AGPL-3.0-or-later