SynHi

AnkiWeb addon 70388912

Highlights program code syntax in the note editor with Pygments colors, inserting language-specific HTML at the cursor, with options for line numbers, CSS classes and per-deck language memory.
AI-generated summary; may contain mistakes.

card-creationformattingfork-or-reupload

Open on AnkiWeb Ask about alternatives

AnkiWeb

Votes
0 (👍 0 · 👎 0)
Updated
2026-10-30
Anki versions
26.09.2~
Languages
Python, JavaScript, JSON
Description language
en

Maintenance

active

  • Last update or commit: 2026-10-30 (2 days before the snapshot).

GitHub

No GitHub repository linked.

Will it work on my Anki?

Version branches
Min AnkiMax AnkiUpdated
26.09.2+2026-10-30
History across monthly snapshots

Loading…

Similar addons

Code Highlight

Adds non-invasive automatic syntax highlighting to code blocks in Anki's editor preview and reviewer, auto-detecting languages or accepting manual class specifications, with configurable font size and color scheme.

formattingappearance

18 votes 55% approval 👍 14 · 👎 4 ⭐ 2 Anki 23.12.1~ Updated 2024-02-20

Description

SynHi

SynHi highlights the syntax of program code in the note editor. It turns code into HTML with colors (generated by Pygments 2.17.2) and inserts the HTML into the field at the cursor position.

How to use it

  1. In the editor toolbar, choose the language of the code in the language list (for example Java, Python, or SQL).
  2. Select code in a field, or copy code to the clipboard.
  3. Click the SynHi editor button, or press Alt+S. SynHi highlights the selected text, or the clipboard text when nothing is selected, and inserts the result at the cursor position.

SynHi remembers the last used language, and by default the last used language of each deck.

Tools > SynHi Options ... opens the options:

  • Line numbers
  • Center code fragments
  • Use CSS classes (instead of inline colors)
  • Default to last language used per deck

These options are stored in the collection.

The add-on configuration (config.json, which Anki's add-on manager shows with the help text of config.md) has these advanced options; a change takes effect after Anki is restarted:

  • hotkey: the shortcut of the editor button. Default: Alt+s.
  • limitToLangs: the languages in the language list. Every entry must be a Pygments lexer name. Default: ["Bash", "Go", "HTML", "Java", "JavaScript", "Python", "SQL"]. An empty list [] lists every language that Pygments knows.
  • style: the Pygments style of the colors. Default: monokai.

Relation to Syntax Highlighting (NG)

SynHi is a modified version of the add-on "Syntax Highlighting (NG)" (566351439). In current Anki editors the language list of Syntax Highlighting (NG) has no effect: the editor page has a Content Security Policy that blocks inline event handlers, so every code block is highlighted as Python. In SynHi the language list works again under that Content Security Policy, and the chosen language and the options are saved.

Installing SynHi switches off Syntax Highlighting (NG) automatically (the SynHi manifest lists it as a conflicting add-on). On first use, SynHi copies the settings of Syntax Highlighting (NG) that are stored in the collection, without changing them.

Tested on Anki 26.9.2. The SynHi manifest sets the minimum Anki version to 26.9.2 (min_point_version 260902). SynHi adds its button and language list to the editor aqt.editor.Editor (in Anki 26.9.2 this is aqt.editor_legacy.Editor), not to aqt.editor.NewEditor.

Credits

SynHi is based on the work of the authors of Syntax Highlighting (NG) and its earlier versions:

  • Tiago Barroso
  • Tim Rae
  • Glutanimate
  • A. Cavallo

License

SynHi is licensed under the GNU Affero General Public License version 3 (GNU AGPLv3) with the Additional Terms in LICENSE.txt. The add-on package contains its complete source code. The notices of changes are in CHANGES-FORK.md and in the header of each changed file.

SynHi includes Pygments 2.17.2, which is licensed under the BSD 2-Clause license.