

Syntax Highlighting for Code
0.82MB. Updated 2018-10-07.
The author has shared 65 other
item(s).
Description
Download
As add-ons are programs downloaded from the internet, they are potentially malicious. You should only download add-ons you trust.
Supported Anki versions:
- 2.1.0 (Updated 2018-10-07)
To download this add-on, please copy and paste the following code into Anki 2.1:
1463041493
If you were linked to this page from the internet, please open Anki on your computer, go to the Tools->Add-ons menu item, then click on Get Add-ons and paste in the code.
Reviews

The thing added junk code to 30+ of my card types. When I deleted the addon, it left the junk code behind. How rude. I had to go through all my card types and delete the code by hand like some shmuck. But maybe I am a shmuck: if it was user error then I'll delete this review.
Code that was added:
<link rel="stylesheet" href="_ch-pygments-solarized.css" class="anki-code-highlighter">
<link rel="stylesheet" href="_ch-hljs-solarized.css" class="anki-code-highlighter">
<script src="_ch-my-highlight.js" class="anki-code-highlighter"></script>
Code that was added:
<link rel="stylesheet" href="_ch-pygments-solarized.css" class="anki-code-highlighter">
<link rel="stylesheet" href="_ch-hljs-solarized.css" class="anki-code-highlighter">
<script src="_ch-my-highlight.js" class="anki-code-highlighter"></script>

Works as expected

How to fix all your problems with this !!
If using dark mode go to Tools -> Add-ons -> Click Syntax Highlighting for Code -> Click Config -> Change style from "default" to "monokai"
Then restart Anki to update it.
Go into style settings of note your using and add the following] .nightMode .highlight {background: transparent !important;}
To fix the white numbers, you have to turn them off. Go to Tools -> Syntax Highlighting for Code
When here, disable Line Numbers and Center code fragments.
If using cloze, use syntax code highlighting first then use the Add Cloze Deletion button on the code you want.
The answer won't change color though but you can change the background color,
to do this use this code] .nightMode .cloze {background: black;}
In this code you can do whatever you want to the answer part except change text color.
If using dark mode go to Tools -> Add-ons -> Click Syntax Highlighting for Code -> Click Config -> Change style from "default" to "monokai"
Then restart Anki to update it.
Go into style settings of note your using and add the following] .nightMode .highlight {background: transparent !important;}
To fix the white numbers, you have to turn them off. Go to Tools -> Syntax Highlighting for Code
When here, disable Line Numbers and Center code fragments.
If using cloze, use syntax code highlighting first then use the Add Cloze Deletion button on the code you want.
The answer won't change color though but you can change the background color,
to do this use this code] .nightMode .cloze {background: black;}
In this code you can do whatever you want to the answer part except change text color.

The indentation, the theme, the font colors, the line numbers - nothing is retained on pasting using this add-on.
The generated color of text can be same as background, making parts of the code invisible.
The generated color of text can be same as background, making parts of the code invisible.

Not working for me! Gives the following error
One or more errors occurred:
1463041493: Please check your internet connection. HTTPSConnectionPool(host='ankiweb.net', port=443): Max retries exceeded with url: /shared/download/1463041493?v=2.1&p=61 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))
One or more errors occurred:
1463041493: Please check your internet connection. HTTPSConnectionPool(host='ankiweb.net', port=443): Max retries exceeded with url: /shared/download/1463041493?v=2.1&p=61 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))

Es lo que estaba buscando, si tuviera dinero te donaba, gracias

For dark mode on mac .../Library/Aplication Support/Anki2/.../config.json and set style to Monokai

It works but Apex Language is not supported yet

Good

Works

Terrific tool especially since mem.dev shut down. Has a very robut list of different languages to choose from.

Awesome and easy tool

Annoying that the line numbers don't respect the theme, but other than that works well.

Great, although I use dark mode, so fixing that was a pain to figure out. I had to set `style` to `"monokai"` in the configure screen for this add-on. This didn't fix the line numbers being all white though, so I had to turn those off under Tools > Syntax Highlighting Options ...

I love it it works pretty well

Line numbering is somewhat broken: numbers appear in the middle of code lines. Also the code block is always aligned to center of the screen.

To make it work for dark mode, add the following code to your card note template styling:
.nightMode .highlight {
background: #222222 !important;
}
.nightMode .highlight {
background: #222222 !important;
}

Have been using it for a couple of months and works well.

good addition, but we need the ability to change the font size. Greetings to the creators

Works great, for dark mode use a dark mode style in the config, e.g monokai

Useful

Just installed. Rating in advance.

great job! but i cannot use it : code is not readable when you past it because of colors: https://ibb.co/WVD5MQP

Works amazing! Configure the JSON file in Preferences to "monokai" for dark mode.

Amazing Tools. works for me.

Very nice for programming studies

Not working for me
- macOS Monterrey (M1)
Is there a way I can check the logs to debug? I really want this plugin and would gladly pay for it as well.
- macOS Monterrey (M1)
Is there a way I can check the logs to debug? I really want this plugin and would gladly pay for it as well.

Does not work for me: pressing button does nothing except some invisible changes in formatting

works amazingly! Kudos to the author!

Actually works.

Unfortunately this add-on caused a noticeable delay in loading the WYSIWYG editor when using the browser or adding/editing a new card, perhaps because it's loading a big python library on the initialization of the editor. Not sure of course, just a theory.
Have resorted to pasting highlighted HTML in from an external source, which is less convenient but does the job for now.
Have resorted to pasting highlighted HTML in from an external source, which is less convenient but does the job for now.

Worked great for python. Didn't see options for other code though.

Good job, thx!

Great!!!!If it has the dark mode it would be amazing!!!!!

Anki 2.1.54 (88e539aa) Python 3.10.5 Qt 6.3.1 PyQt 6.3.1
Platform: Linux
Flags: frz=False ao=True sv=2
Add-ons, last update check: 2022-08-11 11:30:25
Syntax Highlighting for Code
Caught exception:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/anki/config.py", line 43, in get_immutable
return from_json_bytes(self.col._backend.get_config_json(key))
File "/usr/lib/python3.10/site-packages/anki/_backend/generated.py", line 1004, in get_config_json
raw_bytes = self._run_command(5, 0, message.SerializeToString())
File "/usr/lib/python3.10/site-packages/anki/_backend/__init__.py", line 146, in _run_command
raise backend_exception_to_pylib(err)
anki.errors.NotFoundError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/aqt/webview.py", line 42, in cmd
return json.dumps(self.onCmd(str))
File "/usr/lib/python3.10/site-packages/aqt/webview.py", line 149, in _onCmd
return self._onBridgeCmd(str)
File "/usr/lib/python3.10/site-packages/aqt/webview.py", line 624, in _onBridgeCmd
return self.onBridgeCmd(cmd)
File "/usr/lib/python3.10/site-packages/aqt/toolbar.py", line 168, in _linkHandler
self.link_handlers[link]()
File "/usr/lib/python3.10/site-packages/aqt/toolbar.py", line 183, in _addLinkHandler
self.mw.onAddCard()
File "/usr/lib/python3.10/site-packages/aqt/main.py", line 1135, in onAddCard
aqt.dialogs.open("AddCards", self)
File "/usr/lib/python3.10/site-packages/aqt/__init__.py", line 129, in open
instance = creator(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/aqt/addcards.py", line 49, in __init__
self.setupEditor()
File "/usr/lib/python3.10/site-packages/aqt/addcards.py", line 74, in setupEditor
self.editor = aqt.editor.Editor(
File "/usr/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/usr/lib/python3.10/site-packages/anki/hooks.py", line 89, in decorator_wrapper
return repl(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/anki/hooks.py", line 80, in repl
old(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/aqt/editor.py", line 128, in __init__
self.setupWeb()
File "/usr/lib/python3.10/site-packages/aqt/editor.py", line 179, in setupWeb
righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)
File "/usr/lib/python3.10/site-packages/anki/hooks.py", line 45, in runFilter
arg = func(arg, *args)
File "/home/pluveto/.local/share/Anki2/addons21/1463041493/main.py", line 319, in onSetupButtons21
previous_lang = get_default_lang(mw)
File "/home/pluveto/.local/share/Anki2/addons21/1463041493/main.py", line 84, in get_default_lang
addon_conf = mw.col.conf['syntax_highlighting_conf']
File "/usr/lib/python3.10/site-packages/anki/config.py", line 62, in __getitem__
val = self.get_immutable(key)
File "/usr/lib/python3.10/site-packages/anki/config.py", line 45, in get_immutable
raise KeyError from exc
KeyError
Platform: Linux
Flags: frz=False ao=True sv=2
Add-ons, last update check: 2022-08-11 11:30:25
Syntax Highlighting for Code
Caught exception:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/anki/config.py", line 43, in get_immutable
return from_json_bytes(self.col._backend.get_config_json(key))
File "/usr/lib/python3.10/site-packages/anki/_backend/generated.py", line 1004, in get_config_json
raw_bytes = self._run_command(5, 0, message.SerializeToString())
File "/usr/lib/python3.10/site-packages/anki/_backend/__init__.py", line 146, in _run_command
raise backend_exception_to_pylib(err)
anki.errors.NotFoundError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/aqt/webview.py", line 42, in cmd
return json.dumps(self.onCmd(str))
File "/usr/lib/python3.10/site-packages/aqt/webview.py", line 149, in _onCmd
return self._onBridgeCmd(str)
File "/usr/lib/python3.10/site-packages/aqt/webview.py", line 624, in _onBridgeCmd
return self.onBridgeCmd(cmd)
File "/usr/lib/python3.10/site-packages/aqt/toolbar.py", line 168, in _linkHandler
self.link_handlers[link]()
File "/usr/lib/python3.10/site-packages/aqt/toolbar.py", line 183, in _addLinkHandler
self.mw.onAddCard()
File "/usr/lib/python3.10/site-packages/aqt/main.py", line 1135, in onAddCard
aqt.dialogs.open("AddCards", self)
File "/usr/lib/python3.10/site-packages/aqt/__init__.py", line 129, in open
instance = creator(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/aqt/addcards.py", line 49, in __init__
self.setupEditor()
File "/usr/lib/python3.10/site-packages/aqt/addcards.py", line 74, in setupEditor
self.editor = aqt.editor.Editor(
File "/usr/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/usr/lib/python3.10/site-packages/anki/hooks.py", line 89, in decorator_wrapper
return repl(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/anki/hooks.py", line 80, in repl
old(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/aqt/editor.py", line 128, in __init__
self.setupWeb()
File "/usr/lib/python3.10/site-packages/aqt/editor.py", line 179, in setupWeb
righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)
File "/usr/lib/python3.10/site-packages/anki/hooks.py", line 45, in runFilter
arg = func(arg, *args)
File "/home/pluveto/.local/share/Anki2/addons21/1463041493/main.py", line 319, in onSetupButtons21
previous_lang = get_default_lang(mw)
File "/home/pluveto/.local/share/Anki2/addons21/1463041493/main.py", line 84, in get_default_lang
addon_conf = mw.col.conf['syntax_highlighting_conf']
File "/usr/lib/python3.10/site-packages/anki/config.py", line 62, in __getitem__
val = self.get_immutable(key)
File "/usr/lib/python3.10/site-packages/anki/config.py", line 45, in get_immutable
raise KeyError from exc
KeyError

good

I love using this add on on my cards so I can see the code on my decks. It helps when you're a software engineer and need to remember a lot of syntax for different languages.

Very useful since it allows one to use code like syntax in an Anki card. Recommended!

Great for self-taught programmers!

Works pretty well.

Works

Really great. Makes it easy to format code on copy/paste. Should be part of Anki by default imo.

Does what it should do :)

The Add-On requires an update since 2018. Anki now has a Dark Mode.

works well so far

useful

works well, not quite as expected, but functioning, still.

Beautiful

It's awesome

This is pretty convenient for adding occasional snippets of code.
R is not included among that otherwise extensive list of languages, but S is a very similar language so it works well enough for snippets.
R is not included among that otherwise extensive list of languages, but S is a very similar language so it works well enough for snippets.

It makes my code cleaner in the cards!!!!

Great add on

It saves my days... Writing a lot of code notes I need the right tool for formatting code in different languages

Great add-on. Does anyone know how to limit the width of the code block that it formats it properly so that it prevents horizontal scrolling and keeps code more compact?
I tried using max-width in styles and it won't override its default properties.
I tried using max-width in styles and it won't override its default properties.

I really love this add on.

Obrigado, bro. Que a força esteja sempre com você.

it works!

This solution was posted earlier, I provide a bit more details and fix foreground color too.
Fix for the line colors in a dark theme (assuming the monokai theme was applied):
1. Tools -> "Syntax Highlighting for Code" -> View Files:
2. Then open: libs/pygments/formatters/html.py, and search for the occurence of `linenodiv`, that has a `background-color` property.
3, Replace that color and also add a foreground color:
background-color: #272822; color: #616063;
Your full style property must be (at least on August 2021):
style="background-color: #272822; color: #616063; padding-right: 10px"
4. Restart Anki!
Fix for the line colors in a dark theme (assuming the monokai theme was applied):
1. Tools -> "Syntax Highlighting for Code" -> View Files:
2. Then open: libs/pygments/formatters/html.py, and search for the occurence of `linenodiv`, that has a `background-color` property.
3, Replace that color and also add a foreground color:
background-color: #272822; color: #616063;
Your full style property must be (at least on August 2021):
style="background-color: #272822; color: #616063; padding-right: 10px"
4. Restart Anki!

Good, but let use edit the font size, or add more syntax colors.

DUDE. I've been looking for this for so long. Can't figure out why quizlet or any of the other big players don't support simple syntax highlighting! Vielen Dank!

Godsend!! 😋😋
It makes Computer Science cards creation way easier and nicer on the eye, if you want to include a code block.
It makes Computer Science cards creation way easier and nicer on the eye, if you want to include a code block.

thanks, i needed this

I fixed the following problem by unchecking "Copy with syntax highlighting" in my vs code, now it works all good.
Previous problem:
Do not indent at all after pasting C++ code(already formatted and indented in vs code). Very annoying. Using macOS Big Sur version 11.2.1 and Anki 2.1.4.
Previous problem:
Do not indent at all after pasting C++ code(already formatted and indented in vs code). Very annoying. Using macOS Big Sur version 11.2.1 and Anki 2.1.4.

Great app

The best way to write code on our flashcards

not working well for R
No matter selecting Rd or Rconsole nearly no syntax highlighting
No matter selecting Rd or Rconsole nearly no syntax highlighting

Good

I use it all the time. Thanks!

Great, thank you!

Thank you for the addon!
Perfect to add code examples to your cards.
Perfect to add code examples to your cards.

useful

The perfect way to get code to display just as in a common editor.
A little fiddly in that you can't edit it too easily; and can't copy and paste it properly. But as long you're sure you've typed in the code exactly as you want it before you hit Alt-S to format it, it does exactly what you'd want it to: the right layout, the right font, the right colours, bold emphasis where valuable, etc.
I might prefer it if it *didn't* include the line numbers. Sometimes I want to include bits that aren't necessarily part of the same program, etc; or just a single line to learn the syntax for a particular function; etc; and the numbering is a little distracting. And I suspect it's the line number element that makes it so you can't edit it, copy-paste, etc. But it's such a minor thing overall.
(nb. I'm only just learning to code, so experienced programmers might think differently, but for the little Python and C++ that I'm familiar with, the formatting seems just right.)
A little fiddly in that you can't edit it too easily; and can't copy and paste it properly. But as long you're sure you've typed in the code exactly as you want it before you hit Alt-S to format it, it does exactly what you'd want it to: the right layout, the right font, the right colours, bold emphasis where valuable, etc.
I might prefer it if it *didn't* include the line numbers. Sometimes I want to include bits that aren't necessarily part of the same program, etc; or just a single line to learn the syntax for a particular function; etc; and the numbering is a little distracting. And I suspect it's the line number element that makes it so you can't edit it, copy-paste, etc. But it's such a minor thing overall.
(nb. I'm only just learning to code, so experienced programmers might think differently, but for the little Python and C++ that I'm familiar with, the formatting seems just right.)

Automatically detects highlighted code!

Thanks

I have used it for 3 years,very nice

I was looking for something like this.

Great Add On!
For Anki Night Mode User who has problems with the line number and the color:
In the Add-On Files go to libs\pygments\formatters\html.py:
Search for: class="linenodiv" there shoud be an entry 'style="background-color: #32399c ...." --> I changed the default value to #32399c. Voila with that you changed the background of the line numbers :)
Hope it helped, cheers guys
For Anki Night Mode User who has problems with the line number and the color:
In the Add-On Files go to libs\pygments\formatters\html.py:
Search for: class="linenodiv" there shoud be an entry 'style="background-color: #32399c ...." --> I changed the default value to #32399c. Voila with that you changed the background of the line numbers :)
Hope it helped, cheers guys

Broken again as of today. Didnt install anything new though.

Awesome!

Good,but not perfect
It depend on another plugin,so it's not perfect.but good enough,
It depend on another plugin,so it's not perfect.but good enough,

Love that this works on anki 2.1.

Great, exactly what I needed with the flexibility to configure how I want. Thank you! Now, how about some inline highlighting?

Very cool! Makes formatting code effortless.

To people having troubles with dark mode there's a workaround. See this document's Advanced section and follow the instructions to set the style to monokai. This gives you a dark background color, though the line numbers are still white on off-white (for the Mac app at least).

Great language support, does exactly what it advertises.

Thanks. I frequently add codeblocks and this add-on has been very helpful in creating those cards.

very nice, thank you!

Awesome! However, the theme of the line numbers (light theme) doesn't change when the theme is changed to a dark theme.

Conflict with Hierarchial Tag !!!!!!!!!!!!! Please update

Excellent plugin !!

Love this addon. I definitely prefer using the css template and being able to change the appearance of all my cards just by tweaking the code under styling, so thanks a lot for including that option!

Pretty good, but I wish there were support for inline formatted code within a larger block of non-code text, which is useful for writing explanations clearly.

Thank you!

Highlighting for what seems like every language you could think of representing various domains, even obscure languages like brainfuck.

Thanks for the super useful addon. I really appreciate it.
EDIT: Is there a way to prevent the plugin from center aligning the code in the card? It looks perfect right now, I like the syntax highlighting very much, but sometimes I want the code to be at the left side of the card.
EDIT: Is there a way to prevent the plugin from center aligning the code in the card? It looks perfect right now, I like the syntax highlighting very much, but sometimes I want the code to be at the left side of the card.

Thanks!!

Nice!

Excellent - I have been looking for something like this. really helpful. Thank you so much

Great add-on.
Aside: if it helps anyone else, I've finally figured out how to get hotkeys working on a mac.
You need to insert the symbol version of the keys, rather than the text version.
So instead of typing Shift+Command+E, you need to type ⇧⌘E. This drove me crazy for a wee while!
Aside: if it helps anyone else, I've finally figured out how to get hotkeys working on a mac.
You need to insert the symbol version of the keys, rather than the text version.
So instead of typing Shift+Command+E, you need to type ⇧⌘E. This drove me crazy for a wee while!

I had to take screenshots from my code snippets in order to insert highlighted code in my cards, which takes time. Liked this addon. Thanks to the author

It's great, the only problem is with night mode.

Code color not working for Swift

Perfect for helping to remember Python one-liners I want to stop Googling. Great work!

It works great!

Really helpful.

Noice!

Works great, love it.

Amazing!

Color doesnt work.

Works as described

Works perfect w/ Anki 2.1.8 on Ubuntu

works on the lastest version for the current time.

it works!!

"Updated 2018-10-07" but works fine in Anki 2.1.15

Great addon. Any chance that we get a different colour scheme for dark mode?

It's a great addon.
For those looking for a way to add just plain text and have it easily aligned, select "Text only" from the drop down menu. It took me ages to find that, because I didn't know what it would come under lol.
For those looking for a way to add just plain text and have it easily aligned, select "Text only" from the drop down menu. It took me ages to find that, because I didn't know what it would come under lol.

Perfect!

works perfectly.

Just worked out of the box!

Excellent add-on to study code. Works for me with Anki 2.1 on Linux.

i really needed sth like this.

now code looks like it should and it work even with cloze in it

nice!It's very useful.
By the way,how can I do to change the font to 'Consolas'?
By the way,how can I do to change the font to 'Consolas'?

It's a good add-on. Only thing when I import decks from Quizlet indentation is ugly. It's not an issue of this add-on but rather Quizlet it removes them(indentation is a paid privilege I guess). I have to paste to vscode then format and then paste again, time consuming. Maybe there's a better aproach.

A must for flashcards with code. I was struggling to get left alignment working for code in my answers then discovered this addon. Not only did it solve my alignment problem but it makes the code look like code.

Excellent

Me ajuda muito para aprender uma linguagem nova.

great add-on.
It works well with the add-on "Night Node" for me if you use the option "Use CSS classes" and follow the description in the section "Configuration".
It works well with the add-on "Night Node" for me if you use the option "Use CSS classes" and follow the description in the section "Configuration".

I like the addon, have been using it for quite some time. I'm not a power user of the addon, the only thing I have done to it is turned off line numbers. Other than that I use default. It is easy to use but there are some minor inconveniences.
For example if I want to activate the plugin and then type my code in, I can't really do that because on activation it pastes in whatever I have in my clipboard. I have to errase it and only then start typing the code. It's ok, it never meant to be used like that anyway, I should always type the code in my text editor first with proper indentation and then paste it in Anki.
If I want to highlight assembly it might be difficult to find the language I need. There is some kind of assembly langauge but it doesn't seem to be x86_64 (AT&T or Intel). Actually choosing any kind of language is difficult because you have a giant select list. A search would be better, but I don't know if Anki would allow to do something like that.
Overall it does what I need, my cards with code look pretty and readable.
For example if I want to activate the plugin and then type my code in, I can't really do that because on activation it pastes in whatever I have in my clipboard. I have to errase it and only then start typing the code. It's ok, it never meant to be used like that anyway, I should always type the code in my text editor first with proper indentation and then paste it in Anki.
If I want to highlight assembly it might be difficult to find the language I need. There is some kind of assembly langauge but it doesn't seem to be x86_64 (AT&T or Intel). Actually choosing any kind of language is difficult because you have a giant select list. A search would be better, but I don't know if Anki would allow to do something like that.
Overall it does what I need, my cards with code look pretty and readable.

It is awesome! My anki version is 2.1.11. It works well. Highlight then click, it's done! Thank you very much.

Wonderful work here! I like the shortcuts so you can just style and move on quickly.
I do have one question: any support for dark mode color schemes?
I do have one question: any support for dark mode color schemes?

Great addition for those wanting to learn programming languages

this is great! works for my simple python highlighting. :D

Very cool!

this plug-in is awesome! thanks for the great tool guys!

Excellent

Love it! Does the job.

It actually works! Easy to install and supports Anki 2.1. Awesome work! Easy to setup and well explained unlike all the others. Up and running in minutes.

I can insert code snippets quite effectively, very useful.

Works great!

Awesome. Super useful

Very useful

Works pretty well, thanks!

Worked flawlessly with Python code

Works well.

Excelent addon for develops

Looks great and I appreciate the huge list of language options!

beautiful !
thank you
thank you

Everything works fine (Anki 2.1.x).
Except not compatible with Night Mode (some text is white on white in night mode, like line numbers).
Except not compatible with Night Mode (some text is white on white in night mode, like line numbers).

Exactly what I needed.

good idea

Simple and does what it means to do - thanks!

gets the job done!

এটা দারুন, প্রোগ্রামারদের জন্যে কাজের জিনিস। Its really usefull.

Cool

This is amazing...love how you can choose between which languages you want to highlight.

Works well

Provides good syntax highlighting for code within cards

Excellent stuff!
Thank you.
Thank you.

simple and perfect

Once I realised Alt-S is the way to apply the styling (not simply selecting your language in the drop down) and the centering can be removed in config this got the thumbs up!

Great !

Great!! Thanks for updating the Plugin so it works with Liquid Syntax. Once I updated the plugin and did another copy and paste it worked. No missing lines of text. I guess Liquid can be awkward because of it's particular syntax. I've removed the negative vote and criticism and gave it a thumbs up. I will be happy to make a small donation sometime in the future. It's a great plugin for those learning to code like me.
If I discover any other minor issues how do I contact you.. Via this method or do you have a website/email?
If I discover any other minor issues how do I contact you.. Via this method or do you have a website/email?
Comment from author
Happy to hear that things are working fine now. Thanks for the rating! GitHub would be best, as replying here is rather cumbersome: https://github.com/glutanimate/syntax-highlighting/issues

Unconditionally loved it.

awesome!

Love this add-on. Very useful and tons of languages supported. Thanks for the awesome work!!

This is great add-on. All you have to do is highlight your code, and press the lightning button to format it and add syntax highlighting. I made some flashcards for ES6+ features/syntax and my code snippets are now beautiful.
Personally, I disabled line numbers, disabled centering, and used CSS classes (copy and paste the CSS in the link and add it to your note template).
Personally, I disabled line numbers, disabled centering, and used CSS classes (copy and paste the CSS in the link and add it to your note template).

Fix this problem:
https://gist.github.com/ferstar/61dbec4e74bcc725172ec46e546c65e1
https://gist.github.com/ferstar/61dbec4e74bcc725172ec46e546c65e1
Comment from author
Hi there! Thanks for taking the time to link to the hotfix. For what it's worth, with the latest release of the add-on this is no longer required as all issues previously reported in the review section should be fixed.

Works great after applying ferstar's fix.

Работает после замены файла code_highlight_addon.py скачанного с https://gist.github.com/ferstar/61dbec4e74bcc725172ec46e546c65e1

worked after I added this code to line 125 of code_highlight_addon/code_highlight_addon.py
mw.col.conf.setdefault('syntax_highlighting_conf', default_conf)
mw.col.conf.setdefault('syntax_highlighting_conf', default_conf)

Working after applying ferstar's fix. Thanks!

great addon, little problem but easy to fix
here is my solution:
vist https://gist.github.com/ferstar/61dbec4e74bcc725172ec46e546c65e1
download it as "code_highlight_addon.py"
replace the stock one
enjoy!
here is my solution:
vist https://gist.github.com/ferstar/61dbec4e74bcc725172ec46e546c65e1
download it as "code_highlight_addon.py"
replace the stock one
enjoy!

Doesn't work anymore!
This addon was a great one,but it doesn't work anymore. Shows error when Anki starts! :(
This addon was a great one,but it doesn't work anymore. Shows error when Anki starts! :(


I applied two tips from the comments below and it works
1. Remove all add-ons
2. Add this add-on FIRST 162313389
This add-on can be referenced here: https://ankiweb.net/shared/info/162313389
3. Then I add this add-on: 1463041493
4. Select Tools/Add-ons/Open Add-ons Folder from the Anki menu and close Anki
5. go inside "code_highlight_addon" folder
6. edit code_highlight_addon.py in text editor
In code_highlight_addon.py, add right after the line (approx line 238):
def highlight_code(self):
this line:
mw.col.conf['syntax_highlighting_conf'] = default_conf
so it seems like:
def highlight_code(self):
mw.col.conf['syntax_highlighting_conf'] = default_conf
save, restart anki, enjoy
1. Remove all add-ons
2. Add this add-on FIRST 162313389
This add-on can be referenced here: https://ankiweb.net/shared/info/162313389
3. Then I add this add-on: 1463041493
4. Select Tools/Add-ons/Open Add-ons Folder from the Anki menu and close Anki
5. go inside "code_highlight_addon" folder
6. edit code_highlight_addon.py in text editor
In code_highlight_addon.py, add right after the line (approx line 238):
def highlight_code(self):
this line:
mw.col.conf['syntax_highlighting_conf'] = default_conf
so it seems like:
def highlight_code(self):
mw.col.conf['syntax_highlighting_conf'] = default_conf
save, restart anki, enjoy

Was good, but not any more
This was a useful add on until it stopped working. There are work around, but they seem to create more issues than they fix.
This was a useful add on until it stopped working. There are work around, but they seem to create more issues than they fix.
Comment from author
Hi there! Please feel free to give the latest version of Syntax Highlighting a try. I've recently taken over maintenance of the add-on and most if not all issues reported in the review section should be fixed now.

works like a charm after changing one line of code
Follow the "Fixing KeyError" review, simply add one line to its source python code. All work now for both ubuntu and mac.
Follow the "Fixing KeyError" review, simply add one line to its source python code. All work now for both ubuntu and mac.






Fixing KeyError
In code_highlight_addon.py, simply add this line right after
def highlight_code(self):
mw.col.conf['syntax_highlighting_conf'] = default_conf
This will still allow you to save your line number and centering options.
If you get a pygments error, follow the instructions of the previous reviews (either install the supplementary buttons addon first, or edit code_highlight_addon.py with the pygments path)
4 stars because it requires manual fixing.
In code_highlight_addon.py, simply add this line right after
def highlight_code(self):
mw.col.conf['syntax_highlighting_conf'] = default_conf
This will still allow you to save your line number and centering options.
If you get a pygments error, follow the instructions of the previous reviews (either install the supplementary buttons addon first, or edit code_highlight_addon.py with the pygments path)
4 stars because it requires manual fixing.

The add on don't work
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "C:\Users\rafael\Documents\Anki\addons\ankihabitica.py", line 621, in score_backlog
ah.habitica.grab_scorecounter('Anki Points')
File "C:\Users\rafael\Documents\Anki\addons\AnkiHabitica\habitica_class.py", line 332, in grab_scorecounter
if self.missing[habit]:
KeyError: 'Anki Points'
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "C:\Users\rafael\Documents\Anki\addons\ankihabitica.py", line 621, in score_backlog
ah.habitica.grab_scorecounter('Anki Points')
File "C:\Users\rafael\Documents\Anki\addons\AnkiHabitica\habitica_class.py", line 332, in grab_scorecounter
if self.missing[habit]:
KeyError: 'Anki Points'

Getting it to work
If you are are having trouble getting this code to work, here is what I did:
1. Removed all add-ons
2. Added this add-on FIRST 162313389
This add-on can be referenced here: https://ankiweb.net/shared/info/162313389
3. Then I added this add-on: 1463041493
If you are are having trouble getting this code to work, here is what I did:
1. Removed all add-ons
2. Added this add-on FIRST 162313389
This add-on can be referenced here: https://ankiweb.net/shared/info/162313389
3. Then I added this add-on: 1463041493

Help
I fixed the pygments error mentioned below, but still have this one...
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "/home/<user>/Documents/Anki/addons/code_highlight_addon/code_highlight_addon.py", line 125, in setupUi
if mw.col.conf['syntax_highlighting_conf']['linenos']:
KeyError: 'syntax_highlighting_conf'
I fixed the pygments error mentioned below, but still have this one...
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "/home/<user>/Documents/Anki/addons/code_highlight_addon/code_highlight_addon.py", line 125, in setupUi
if mw.col.conf['syntax_highlighting_conf']['linenos']:
KeyError: 'syntax_highlighting_conf'
Comment from author
Hi there! Thanks for the issue report. I know it's been a while, but please feel free to give the latest version of Syntax Highlighting a try. I've recently taken over maintenance of the add-on and most if not all issues reported in the review section should be fixed now.


Not working as others mentioned
Gives the following error message when started
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.addons", line 41, in loadAddons
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\prave_000\Documents\Anki\addons\Syntax Highlighting for Code.py", line 2, in <module>
import code_highlight_addon.code_highlight_addon
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\prave_000\Documents\Anki\addons\code_highlight_addon\code_highlight_addon.py", line 221, in <module>
from pygments import highlight
File "c:\pyi\iu.py", line 455, in importHook
ImportError: No module named pygments
Gives the following error message when started
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.addons", line 41, in loadAddons
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\prave_000\Documents\Anki\addons\Syntax Highlighting for Code.py", line 2, in <module>
import code_highlight_addon.code_highlight_addon
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\prave_000\Documents\Anki\addons\code_highlight_addon\code_highlight_addon.py", line 221, in <module>
from pygments import highlight
File "c:\pyi\iu.py", line 455, in importHook
ImportError: No module named pygments
Comment from author
Hi there! Thanks for the issue report. I know it's been a while, but please feel free to give the latest version of Syntax Highlighting a try. I've recently taken over maintenance of the add-on and most if not all issues reported in the review section should be fixed now.


Great add-on when it worked.
ANKI Version 2.0.33
Qt 4.8.4 PyQt 4.10
ERROR:
Traceback (most recent call last):
File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.addons", line 41, in loadAddons
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\jrodarte\Documents\Anki\addons\Syntax Highlighting for Code.py", line 2, in <module>
import code_highlight_addon.code_highlight_addon
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\jrodarte\Documents\Anki\addons\code_highlight_addon\code_highlight_addon.py", line 221, in <module>
from pygments import highlight
File "c:\pyi\iu.py", line 455, in importHook
ImportError: No module named pygments
ANKI Version 2.0.33
Qt 4.8.4 PyQt 4.10
ERROR:
Traceback (most recent call last):
File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.addons", line 41, in loadAddons
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\jrodarte\Documents\Anki\addons\Syntax Highlighting for Code.py", line 2, in <module>
import code_highlight_addon.code_highlight_addon
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\jrodarte\Documents\Anki\addons\code_highlight_addon\code_highlight_addon.py", line 221, in <module>
from pygments import highlight
File "c:\pyi\iu.py", line 455, in importHook
ImportError: No module named pygments
Comment from author
Hi there! Thanks for the issue report. I know it's been a while, but please feel free to give the latest version of Syntax Highlighting a try. I've recently taken over maintenance of the add-on and most if not all issues reported in the review section should be fixed now.

Alternative
You can use the Power format pack addon as an alternative, since it also allows you to highlight code using pygments.
You can use the Power format pack addon as an alternative, since it also allows you to highlight code using pygments.

Good News
I'm running Anki 2.0.20 on Ubuntu 14.04. I added this add-on to my installation and it's working perfectly, as advertised.
Here's a screenshot of it in action (the snippet is Python):
http://s21.postimg.org/xwy2yzo8n/Screenshot_from_2016_01_21_13_08_42.png
I'm running Anki 2.0.20 on Ubuntu 14.04. I added this add-on to my installation and it's working perfectly, as advertised.
Here's a screenshot of it in action (the snippet is Python):
http://s21.postimg.org/xwy2yzo8n/Screenshot_from_2016_01_21_13_08_42.png

Bad News
I used this addon for about a year and loved it. Then it broke.
I (and several other users) posted the errors. No help. No responses at all.
Then the addon disappeared from the Anki repository for about a month. No explanation. Nothing. Then it suddenly reappeared. It still doesn't work.
Don't waste your time.
For what it's worth, I write about one product review every ten years. That should tell you how annoyed I am right now.
UPDATE: 1/12/16 -- Used the advice of other reviewers, edited code_highlight_addon.py per the instructions. No help at all. Still doesn't work.
Using Linux Mint 17.2 with Cinnamon desktop.
I used this addon for about a year and loved it. Then it broke.
I (and several other users) posted the errors. No help. No responses at all.
Then the addon disappeared from the Anki repository for about a month. No explanation. Nothing. Then it suddenly reappeared. It still doesn't work.
Don't waste your time.
For what it's worth, I write about one product review every ten years. That should tell you how annoyed I am right now.
UPDATE: 1/12/16 -- Used the advice of other reviewers, edited code_highlight_addon.py per the instructions. No help at all. Still doesn't work.
Using Linux Mint 17.2 with Cinnamon desktop.
Comment from author
Hi there! I know it's been a while, but please feel free to give the latest version of Syntax Highlighting a try. I've recently taken over maintenance of the add-on and most if not all issues reported in the review section should be fixed now.

It used to work perfectly, but I'm having minor issues on Ubuntu 14.04
So as one of the other users mentioned, the
center = False
tweak prevented the error from being reported, but the behavior was the opposite as expected. Setting it to
center = True
doesn't center it so it's good to go again.
Thank you for your plugin!
So as one of the other users mentioned, the
center = False
tweak prevented the error from being reported, but the behavior was the opposite as expected. Setting it to
center = True
doesn't center it so it's good to go again.
Thank you for your plugin!


Two review answers fixed the problem
I also had the two mentioned problems but just fixed them like the people suggested. It works, thanks to author and the users. :)
I also had the two mentioned problems but just fixed them like the people suggested. It works, thanks to author and the users. :)

Fixes
If you get the pygments error, do what the review posted at 2015-11-15 says to do.
If you get the Keyerror: center error, then open code_highlight_addon.py in a text editor, and edit this line:
center = mw.col.conf['syntax_highlighting_conf']['center']
To this:
center = False
You can also set this to True if you prefer to have the code centered in your anki cards.
If you get the pygments error, do what the review posted at 2015-11-15 says to do.
If you get the Keyerror: center error, then open code_highlight_addon.py in a text editor, and edit this line:
center = mw.col.conf['syntax_highlighting_conf']['center']
To this:
center = False
You can also set this to True if you prefer to have the code centered in your anki cards.

I have used it before it is broken...
This is error in my Mac:
Traceback (most recent call last):
File "Documents/Anki/addons/code_highlight_addon/code_highlight_addon.py", line 244, in highlight_code
center = mw.col.conf['syntax_highlighting_conf']['center']
KeyError: 'center'
This is error in my Mac:
Traceback (most recent call last):
File "Documents/Anki/addons/code_highlight_addon/code_highlight_addon.py", line 244, in highlight_code
center = mw.col.conf['syntax_highlighting_conf']['center']
KeyError: 'center'

Here's a Fix
This is a great plugin, but currently broken for some folks.
To fix it:
1. Remove the add-on and restart Anki (if it's installed)
2. Install the add-on, but don't quit Anki yet
3. From menu, choose Tools -> Add-ons -> Open Add-ons Folder, then in that folder open up the "code_highlight_addon" folder and then open code_highlight_addon.py in a text editor. There's a line in there that says this:
sys.path.insert(0, os.path.join(addons_folder(), "code_highlight_addon/libs/pygments"))
add this line underneath it (with matching indendation):
sys.path.insert(0, os.path.join(addons_folder(), "code_highlight_addon/libs"))
4. Save the file and close it
5. Restart Anki
This worked for me on a Mac, hopefully it will fix the plugin for you until the author can donate some more time to fixing it :).
This is a great plugin, but currently broken for some folks.
To fix it:
1. Remove the add-on and restart Anki (if it's installed)
2. Install the add-on, but don't quit Anki yet
3. From menu, choose Tools -> Add-ons -> Open Add-ons Folder, then in that folder open up the "code_highlight_addon" folder and then open code_highlight_addon.py in a text editor. There's a line in there that says this:
sys.path.insert(0, os.path.join(addons_folder(), "code_highlight_addon/libs/pygments"))
add this line underneath it (with matching indendation):
sys.path.insert(0, os.path.join(addons_folder(), "code_highlight_addon/libs"))
4. Save the file and close it
5. Restart Anki
This worked for me on a Mac, hopefully it will fix the plugin for you until the author can donate some more time to fixing it :).

Looks good, but doesn't seem to work anymore
As of Nov 2015, it doesn't look like this works.
I get loading errors concerning 'pygments'. I tried with Python 3.5 and 2.7, and I tried forcing pygments to version 1.6, as one of the other reviewers suggested, but it makes no difference. Won't load.
As of Nov 2015, it doesn't look like this works.
I get loading errors concerning 'pygments'. I tried with Python 3.5 and 2.7, and I tried forcing pygments to version 1.6, as one of the other reviewers suggested, but it makes no difference. Won't load.
Comment from author
Hi there! I know it's been a while, but please feel free to give the latest version of Syntax Highlighting a try. I've recently taken over maintenance of the add-on and most if not all issues reported in the review section should be fixed now.

Great plugin
Make sure to keep pygments at version 1.6, other wise you might get some errors concerning bytes
https://stackoverflow.com/questions/27405405/i-get-an-importerror-cannot-import-name-bytes-with-pygments
Make sure to keep pygments at version 1.6, other wise you might get some errors concerning bytes
https://stackoverflow.com/questions/27405405/i-get-an-importerror-cannot-import-name-bytes-with-pygments