Syntax Highlighting FORK (night mode fix, gui config, etc.)
As add-ons are programs downloaded from the internet, they are potentially malicious. You should only download add-ons you trust.
- 2.1.20-2.1.31 (updated 2020-09-13)
- 2.1.32-2.1.35+ (updated 2020-11-14)
To download this add-on, please copy and paste the following code into Anki 2.1:
If you were linked to this page from the internet, please open Anki on your computer, go to the Tools menu and then Add-ons>Browse & Install to paste in the code.
All Anki 2.1.x Add-Ons Contact Author
But if you use css to apply the syntax highlighting you need to add just one line into the file "_styles_for_syntax_highlighting.css" in your media folder. Add "line-height: 150%;" (without the quotes) to the class highlight so that the first three lines of the file look like this:
If you ever change the style you use in the add-on config you'll have to re-apply this change.
I also just uploaded a new version of this add-on. If you have "use css" checked now there's a button "Edit css file in media folder" that gives you the full file location. Future versions will extend the function of this button to actually open the file ...
So far I haven't added a dedicated shortcut for the default formatting because I can use everything with my left hand from the default position: I can quickly insert the default language with "Alt+S, Space" (because default is preselected and in my menu "space" means "accept/Enter") or "Alt+S, d". "Alt+S" opens the menu and inside the menu you can use single letters to trigger an action from the main window (the relevant letters are underlined). In the menu you can also go up and down with "g" and "b" so that the menu can be used with just the left hand.
Does this also suffice for you?
It works,bug has disappeared.thx
My work is heavy,I will learn how to discuss on reddit when I am in leisure.
Sorry for disturbing you for long time,it just because I don‘t know how to begin a topic on reddit and how to play with the website reddit,you kown that my English is poor. I have followed you,you are a friend whom is so enthusiasm！
if I insert the word "bold" before the color string #66d9ef",it works.
another bug is after update after 2019.11.19
if I select a block of code,and click the icon,it can highlight code,but a copy of initial code appears under the highlight code.
I am busy these days,sorry for replying you late.
,you are an awesome and productive author
if you know some add-on which can keep full format when copy from word(color and background color )?
or does a idea of combine tomato clock and anki attract you?
here is some references:add-on "Pomodore (Tomato Clock Port)"
I have updated,and find if I toggle disable the add-on "Syntax Highlighting for Code"
then I can use style "solarized",it may be a problem of overload, his package may override yours.
However, key words in others styles are still normal instead of bold.
Does it work on your computer?
you can test with style "monokai"
thx for update，it may works better.
1 The question is that if I choose style“monokai”，key words is normal instead of bold while style "default" bold key wordsis.I know this add-on is a fork,but original add-on Syntax Highlighting for Code has this problem as well.
2 when I use GUI window to search style "solarized-dark" or "solarized-light",it doesn't appear,do you mean only if use CSS，can I use this style？
I shouldn't have missed that bug. That's fixed. Could you update and try again? Could you try other parts of the code to check if I missed other bugs in the code. You helped to make the add-on much better.
> some add-on which can keep full format when copy from word(color and background color )?
that's a deliberate choice by the anki creator to remove them. When you copy and paste content from MS Word it contains a lot of garbage formatting that usually means the text looks off/slightly broken/change in an html editor like Anki. So a lot of html editors actually process pasted word content a lot and remove parts that can cause problems. Sometimes too much is removed ... You could have a look at my fork of glutanimate's html-cleaner which was for processing word snippets (among other things), https://github.com/ijgnd/html-cleaner. That's hard to setup. Maybe also have a look at my "extended (table) editor", https://ankiweb.net/shared/info/805891399 - when you paste into it the html is not processed by anki if i remember correctly.
> or does a idea of combine tomato clock and anki attract you? here is some references:add-on "Pomodore (Tomato Clock Port)"
What do you mean exactly. The add-on already exists? It's probably easier to discuss this in a different place. I prefer reddit because other people can also contribute their ideas. or maybe the anki forum?
Thanks for your help. Could you update again. Now it should work as expected. Does it?
Actually Monokai is a bad example for getting bold keywords. The goal of this add-on is to insert code into Anki that is generated by the python package "pygments" and pygments doesn't bold keywords when you use the style "monokai", see e.g. https://stylishthemes.github.io/Syntax-Themes/pygments/ . Other software might behave differently.
You could adjust the source code of my add-on. But all changes will be lost when you update so that you have to reapply them.
It seems to be just one change. Try it at your own risk. From the folder of this add-on go to libs/pygments/styles/monokai.py and change line 39 to
Keyword: "bold #66d9ef", # class: 'k'
(Insert the word "bold" before the color string #66d9ef".)
I uploaded another version. Could you test it and report if it works.
"Solarized" works for me even if I don't use the css option.
Thanks for the upvote and the feedback.
Compatibility with the add-on AutoMarkdown:
I agree that it would be nice if my add-on worked better with AutoMarkdown.
1. a workaround seems to be to surround the output of my add-on with ``` (three backticks before the code and three backticks after the code). Make sure that my add-on does NOT include line numbers (because these will be added by "Auto markdown".
2. the original syntax highlighting is also incompatible with AutoMarkdown.
3. There's no real solution. AutoMarkdown doesn't work with styling related add-ons and also ignores built-in styling options like different text colors. Adjusting Anki itself and all add-ons to AutoMarkdown can't be the solution. The solution must be in AutoMarkdown. AutoMarkdown is a very nice add-on but it tries something virtually impossible: Even with the add-on installed the anki editor is still a html editor ...