gregorias / anki-code-highlighter Goto Github PK
View Code? Open in Web Editor NEWAnki plugin for code syntax highlighting.
License: GNU Affero General Public License v3.0
Anki plugin for code syntax highlighting.
License: GNU Affero General Public License v3.0
I'm using highlight.js
for most of the code examples in my cards and have been quite impressed with it. Is it possible to add additional styling to parts of the code beyond what the current highlighting scheme provides? There are some cards where I'd like to underline a function, put something in italics or draw a box around a line of code to emphasize it, but haven't had any luck. I saw this stackoverflow post where they seem to achieve something similar with highlight.js, but when I tried something similar, it seems to be overridden in the final rendering. Below is a card field where I attempted to achieve this effect.
<pre style="display:flex;"><code class="language-python">def <mark>myfunc</mark>(x)
print('Hello!')
</code></pre>
Is using pygments my only option here? or is there something else I can try?.
So, after installing this add-on I'm stuck at this step:
After fetching, run Extras > Configure Code Highlighter. This is necessary until Anki adds addon lifecycle hooks.
Can you clarify where the above command should be run? I don't have any "Extras" menu in my Anki application.
app info:
Version 2.1.49 (dc80804a)
Python 3.8.6 Qt 5.14.2 PyQt 5.14.2
No other add-ons installed.
Thank you
Hello dear developer. I followed your guide to add a different style for Pygments, but when I ran generate-pygments-css
it throwed an error at the beggining:
ERROR No content to parse.
ERROR PropertyValue: Unknown syntax or no value:
ERROR CSSStyleDeclaration: Syntax Error in Property: color:
I assumed that the next lines that followed the error were the generated style, so I copy them to a file, which I placed in the addon directory ~/.local/share/Anki2/addons21/112228974/assets
. Then, I changed the settings in Anki to point to that style, but it's still using the default Solarized. Maybe I messed up at some point. Could you please help me?
Thanks in advance.
Hello,
I'm getting the error message below when I highlight a code snippet and then click the icon. When I click the icon without anything highlighted, I get the expected dialog boxes to choose the highlighter and language.
Debug info:
Anki 2.1.56 (07fd88dd) Python 3.9.15 Qt 6.3.2 PyQt 6.3.1
Platform: macOS-13.1-arm64-arm-64bit
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2023-01-21 06:48:20
Add-ons possibly involved: Highlight Code
Caught exception:
Traceback (most recent call last):
File "aqt.webview", line 562, in handler
File "/Users/username/Library/Application Support/Anki2/addons21/112228974/ankieditorextra.py", line 76, in transform_field
field = extract_field_from_web_editor(web_editor_html)
File "/Users/username/Library/Application Support/Anki2/addons21/112228974/ankieditorextra.py", line 39, in extract_field_from_web_editor
result = re.search('<anki-editable[^>]>(.)',
File "re", line 201, in search
TypeError: expected string or bytes-like object
Motivated by #16.
I can't set the default highlighter
Setting a default highlighter causes the highlighter not to work at all.
I wonder if I'm doing anything wrong...
"default-highlighter": "pygments"
When saving changes and returning to the config page, the code is automatically reordered:
Expected behavior
I expected the default highlighter's choice to appear as default. However, when attempting to highlight code by using the shortcut or by clicking on the icon, the addon doesn't respond
Card Template
Front:
{{Front}}
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<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-highlight.js" class="anki-code-highlighter"></script>
<script src="_ch-my-highlight.js" class="anki-code-highlighter"></script>
<!-- Anki Code Highlighter (Addon 112228974) END -->
Back:
{{FrontSide}}
<hr id=answer>
{{Back}}
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<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-highlight.js" class="anki-code-highlighter"></script>
<script src="_ch-my-highlight.js" class="anki-code-highlighter"></script>
<!-- Anki Code Highlighter (Addon 112228974) END -->
Styling:
.card {
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}
Additional information
according to the README page, to install the plugin from source:
Where am I supposed to run these commands?
Bug description
Using the plugin with default styles or any other styles results in no style being applied.
Reproduction steps
Steps to reproduce the behavior:
The HTML of the test card:
<div class="pygments" style="display:flex; justify-content:center;">
<pre><code class="nohighlight"><span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
<span class="k">pass</span>
</code></pre>
</div>
Expected behavior
Styling should be applied.
Card template
Back template
{{FrontSide}}
<hr id=answer>
{{Tył}}
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<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-highlight.js" class="anki-code-highlighter"></script>
<script src="_ch-my-highlight.js" class="anki-code-highlighter"></script>
<!-- Anki Code Highlighter (Addon 112228974) END -->
Additional information
Additional context
I tried
%APPDATA%\Anki
directoryHi, thank you for this plugin Grzegorz.
On macOS 12.5.1 and Anki Version 2.1.54 (b6a7760c) Python 3.9.7 Qt 6.3.1 PyQt 6.3.1, pressing the shortcut on selected code does nothing. I tried various other shortcuts without success. Any ideas? Thanks!
Bug description
https://github.com/RisingOrange/anki-enhanced-cloze got an update and now code-highlighter is not displaying highlighted code.
Reproduction steps
Steps to reproduce the behavior:
ctrl-'
, pygments
, block
, bash
.If applicable, provide the offending field's HTML code.
Sometimes “silence is golden,” and we don't want output from a command, we just want to throw it away. This applies particularly to error and status messages. The system provides a way to do this by {{c1::redirecting output to a special file called “/dev/null”. This file is a system device often referred to as a <i>bit bucket</i>, which accepts input and does nothing with it}}. To suppress error messages from a command, we do this:<br><pre style="display:flex; justify-content:center;"><div class="pygments" style="display:flex; justify-content:center;">
<pre><code class="nohighlight"><span class="o">[</span>me@linuxbox<span class="w"> </span>~<span class="o">]</span>$<span class="w"> </span>ls<span class="w"> </span>-l<span class="w"> </span>/bin/usr<span class="w"> </span><span class="m">2</span>><span class="w"> </span>/dev/null
</code></pre>
</div>
</pre>
Expected behavior
The code isn't highlighted at all. Previously it was working fine.
Additional information
Try to highlight the code in
void main() {
vector v;
const vector cv;
f(v); // 1
f(cv); // 2
f(std::move(v)); // 3
}
I got:
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.56 (07fd88dd) Python 3.9.15 Qt 6.3.2 PyQt 6.3.1
Platform: macOS-13.2-arm64-arm-64bit
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2023-02-07 10:07:00
bs4:435: MarkupResemblesLocatorWarning: The input looks more like a filename than markup. You may want to open this file and pass the filehandle into Beautiful Soup.
I probably need to handle BS' warnings.
Hello!
I was wondering if there is a way to change the font family of the code generated by the highlighter.
Also, thank you so much for creating this add-on.
An add-on you installed failed to load. If problems persist, please go to the Tools>Add-ons menu, and disable or delete the add-on.
When loading 'Highlight Code':
Traceback (most recent call last):
File "aqt\addons.py", line 230, in loadAddons
File "C:\Users\xxxx\AppData\Roaming\Anki2\addons21\112228974_init_.py", line 3, in
from . import main
File "C:\Users\xxxx\AppData\Roaming\Anki2\addons21\112228974\main.py", line 17, in
from .assets import AnkiAssetManager, sync_assets
File "C:\Users\xxxx\AppData\Roaming\Anki2\addons21\112228974\assets.py", line 70, in
def list_my_assets(dir: pathlib.Path) -> list[str]:
TypeError: 'type' object is not subscriptable
Bug description
Error on startup, sometimes crashes on startup
Reproduction steps
Expected behavior
Anki to startup
Screenshots
If applicable, add screenshots to help explain your problem. You may mesh screenshots with reproduction steps instead of providing them in this separate section.
Card template
https://github.com/badlydrawnrob/anki
Additional information
Additional context
Although this theme may be outdated, probably not expected behavior for the add-on should throw an error just due to its existence
Hello mr. milka
Good morning/afternoon/evening. (depending on what time you read)
Im not very good at programing.
I would like to use a shortcut for the "highlight text" button on anki (image below), since that on version 2.1.60 no feature as such exists.
I tried to use your add-on for that purpose (image below), but due to my lack of knowledge in programming i failed.
Is there a way to create a shortcut for it? Thanks for your time.
Bug description
The block highlighting mechanism adds a newline.
Reproduction steps
Steps to reproduce the behavior:
echo
with Highlight.js.You'll see that the pre-block comes with an appended br-tag.
Expected behavior
No br-tag is appended.
These tags are annoying. Especially when I have a code-only field. I don't want a spurious empty line after the code block.
I intend to add new languages and changes. I want clients to benefit from those changes without having to perform an action.
I was modifying a few notetypes yesterday and discovered that all my cards from all the notetypes have this lines of html added to them. At first, when installing the addon I thought that this will add something to my cards on demand, not to all of them without even asking. I is there a way to revert this without breaking my cards ( other than doing it manually😅)
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<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>
<!-- Anki Code Highlighter (Addon 112228974) END -->
Hi Grzegorz,
Thank you so much for creating this fantastic addon. It's an excellent tool that has aided my programming study sessions. I really appreciate your work on this!
I noticed in the readme, there are instructions on how to install custom styles for highlight.js, but not for Pygments due to its more complicated setup. I was wondering if there were any plans to add instructions for this in the future?
I eagerly awaiting this as I've found Pygments to work better with cloze and without the flickering issues that I've encountered with highlight.js.
Thanks again for your great work and I look forward to any updates you might have on this topic.
Bug description
When formatting a block code with highlight.js, it displays centered instead of aligned to the left and well indented. If I use Pygments, the result is shown with symbols (see screenshots).
Reproduction steps
Steps to reproduce the behavior:
Ctrl
+ '
highlight.js
and clock OK
.HTML
(in my case) and click OK
.If applicable, provide the offending field's HTML code. For instructions how to get that code, see this Anki help page.
Expected behavior
I expect that the block of code displays well indented and not centered.
Screenshots
If applicable, add screenshots to help explain your problem. You may mesh screenshots with reproduction steps instead of providing them in this separate section.
Card template
If applicable, provide the card template code from the card that exhibits the unwanted behaviour. For instructions how to get that code, see this Anki help page.
Example Card HTML:
{{c1::Test}}<pre style="display:block; justify-content:center;"><code class="language-html"><head> <meta charset="utf-8"> <title>Styles Conference</title> <link rel="stylesheet" href="assets/stylesheets/main.css"> </head></code></pre>
Front Template:
{{cloze:Text}}
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<link rel="stylesheet" href="_ch-hljs-dracula.css" class="anki-code-highlighter">
<link rel="stylesheet" href="_ch-pygments-solarized.css" class="anki-code-highlighter">
<script src="_ch-my-highlight.js" class="anki-code-highlighter"></script>
<!-- Anki Code Highlighter (Addon 112228974) END -->
Back Template:
{{cloze:Text}}<br>
{{Back Extra}}
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<link rel="stylesheet" href="_ch-hljs-dracula.css" class="anki-code-highlighter">
<link rel="stylesheet" href="_ch-pygments-solarized.css" class="anki-code-highlighter">
<script src="_ch-my-highlight.js" class="anki-code-highlighter"></script>
<!-- Anki Code Highlighter (Addon 112228974) END -->
Styling:
.card {
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}
.cloze {
font-weight: bold;
color: blue;
}
.nightMode .cloze {
color: lightblue;
}
Additional information
Additional context
I haven't tuned the cards templates, but I'm using another addon that changes the interface a bit (Advanced Review Bottom Bar).
In instructions provide available lexers: https://pygments.org/docs/lexers/.
When formatting code using Pygments > Block, the text is not properly aligned to the left.
Download the addon
Add card
Choose Basic card type
Format code -> Pygments -> Block -> C
Text should be aligned to the left side of the block.
Opened the _ch-pygments-solarized.css file and added text-align: left;
under .pygments>pre
<div class="pygments" style="display:flex; justify-content:center;">
<pre><code class="nohighlight"><span class="cp">#include</span><span class="w"> </span><span class="cpf"><stdio.h></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><string.h></span><span class="cp"></span>
<span class="kt">void</span><span class="w"> </span><span class="nf">invertWord</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">word</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">length</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">strlen</span><span class="p">(</span><span class="n">word</span><span class="p">);</span>
<span class="w"> </span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">length</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">temp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">word</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="w"> </span><span class="n">word</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">word</span><span class="p">[</span><span class="n">length</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span>
<span class="w"> </span><span class="n">word</span><span class="p">[</span><span class="n">length</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">temp</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">word</span><span class="p">[</span><span class="mi">100</span><span class="p">];</span>
<span class="w"> </span>
<span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"Enter a word: "</span><span class="p">);</span>
<span class="w"> </span><span class="n">scanf</span><span class="p">(</span><span class="s">"%s"</span><span class="p">,</span><span class="w"> </span><span class="n">word</span><span class="p">);</span>
<span class="w"> </span>
<span class="w"> </span><span class="n">invertWord</span><span class="p">(</span><span class="n">word</span><span class="p">);</span>
<span class="w"> </span>
<span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"Inverted word: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">word</span><span class="p">);</span>
<span class="w"> </span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre>
</div>
{{Front}}
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<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>
<!-- Anki Code Highlighter (Addon 112228974) END -->
{{FrontSide}}
<hr id=answer>
{{Back}}
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<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>
<!-- Anki Code Highlighter (Addon 112228974) END -->
.card {
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}
Windows 10
Version 2.1.63 (f356f177)
Python 3.9.15 Qt 6.4.3 PyQt 6.4.0
Bug description
Previously Clozed Code won't get Highighted correctly. Now with new update to https://ankiweb.net/shared/info/112228974 , the code is getting prefectly SyntaxHighlighted. But it broke opening the cloze using keyboard shortuce 'J' and they can only be revealed after click show answer
- https://ankiweb.net/shared/info/1990296174
Reproduction steps
Steps to reproduce the behavior:
0. Select Note type - Enhanced Clozed
Ctrl+'
If applicable, provide the offending field's HTML code. For instructions how to get that code, see this Anki help page.
The below highlighted & clozed code won't get revealed using 'J'<br><pre><br></pre><pre><pre style="display:flex; justify-content:center;"><code class="language-cpp">{{c1::#include <iostream>
int main()
{
std::cout << 8 / 5 << '\n';
return 0;
}}}</code></pre></pre>
Expected behavior
Using 'J' to reveal the clozed card.
Additional information
when i copy multiple lines of code and paste it to existing code box, all the line merge into just one long line and i have to delete all breaks and replace it with shift+enter key (using shift+enter is not big deal while typing codes from scratch but after pastin codes it's a tedious process).
how to prevent this in the first place?
Bug description
Pygments highlighting doesn't escape HTML entities
Reproduction steps
$ for i in {{0..100..2}}
> do
> echo "Welcome $i times"
> done
Welcome 0 times
Welcome 2 times
Welcome 4 times
...
Welcome 100 times
The highlighter will not correctly translate >
int >
.
Additional context
Seems like the bug from #45 (comment) wasn't fixed.
I get this error message on start up. Disabling highlight code makes it go away.
Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools>Add-ons menu item to disable some add-ons and restart Anki, repeat until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-ons section of our support site.
Debug info:
Anki 2.1.58 (ab8b1465) Python 3.9.15 Qt 6.3.2 PyQt 6.3.1
Platform: macOS-13.1-arm64-arm-64bit
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2023-02-20 16:35:17
Add-ons possibly involved: Highlight Code
Caught exception:
Traceback (most recent call last):
File "aqt.progress", line 118, in handler
File "aqt.main", line 219, in on_window_init
File "aqt.main", line 317, in setupProfile
File "aqt.main", line 497, in loadProfile
File "_aqt.hooks", line 3808, in call
File "/Users/dom/Library/Application Support/Anki2/addons21/112228974/main.py", line 417, in load_mw_and_sync
sync_assets(
File "/Users/dom/Library/Application Support/Anki2/addons21/112228974/assets.py", line 210, in sync_assets
asset_manager.delete_assets()
File "/Users/dom/Library/Application Support/Anki2/addons21/112228974/assets.py", line 103, in delete_assets
self.modify_templates(lambda tmpl: delete_import_statements(
File "/Users/dom/Library/Application Support/Anki2/addons21/112228974/main.py", line 360, in transform_templates
models.save(model)
File "anki.models", line 559, in save
File "anki.models", line 542, in update
File "anki._backend_generated", line 872, in add_or_update_notetype
File "anki._backend", line 156, in _run_command
anki.errors.CardTypeError: Card template 1 in notetype 'Final 2. Picture Words' has a problem.
Expected to find a field replacement on the front of the card template.
Anki will throw the following error in profile selection:
Traceback (most recent call last):
File "aqt.progress", line 118, in handler
File "aqt.main", line 198, in on_window_init
File "aqt.hooks_gen", line 2801, in __call__
File "/Users/grzesiek/Library/Application Support/Anki2/addons21/112228974/main.py", line 142, in setup_menu
anki_asset_manager = create_anki_asset_manager(main_window.col)
File "/Users/grzesiek/Library/Application Support/Anki2/addons21/112228974/main.py", line 45, in create_anki_asset_manager
col.models), col.media, ASSET_PREFIX,
AttributeError: 'NoneType' object has no attribute 'models'
Is it impossible to support cloze cards with highlight.js, or it'd be a feature request?
To save time for possible further inquiries:
Lambda Capture:<br><pre style="display:flex;"><code class="language-cpp">struct S2 { void f(int i); };
void S2::f(int i)
{
[&]{}; // {{c1::OK: by-reference capture default}}
}</code></pre><br>
The current Pygments version is 2.16.0, but this plugin still uses 2.13.0.
I'm using a premade deck and whenever I try to highlight, I get this error :
The selected code contains partial HTML tags. Clean up your code snippet in the HTML editor (https://docs.ankiweb.net/editing.html#editing-features) before highlighting.
It's not very practical to edit every html card in a premade deck with 1000 cards. I am wondering if there is a solution. Thanks!
I got this error on Anki startup on MacOS after installing. The issue goes away after disabling the plugin. Any ideas? Thanks!
Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.56 (07fd88dd) Python 3.9.15 Qt 6.3.2 PyQt 6.3.1
Platform: macOS-13.1-arm64-arm-64bit
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2023-02-02 19:08:00
Add-ons possibly involved: Highlight Code
Caught exception:
Traceback (most recent call last):
File "aqt.progress", line 118, in handler
File "aqt.main", line 197, in on_window_init
File "aqt.main", line 293, in setupProfile
File "aqt.main", line 473, in loadProfile
File "_aqt.hooks", line 3627, in __call__
File "/Users/gdonovan/Library/Application Support/Anki2/addons21/112228974/main.py", line 417, in load_mw_and_sync
sync_assets(
File "/Users/gdonovan/Library/Application Support/Anki2/addons21/112228974/assets.py", line 210, in sync_assets
asset_manager.delete_assets()
File "/Users/gdonovan/Library/Application Support/Anki2/addons21/112228974/assets.py", line 103, in delete_assets
self.modify_templates(lambda tmpl: delete_import_statements(
File "/Users/gdonovan/Library/Application Support/Anki2/addons21/112228974/main.py", line 360, in transform_templates
models.save(model)
File "anki.models", line 559, in save
File "anki.models", line 542, in update
File "anki._backend_generated", line 883, in add_or_update_notetype
File "anki._backend", line 151, in _run_command
anki.errors.CardTypeError: Card template 1 in notetype '2. Mnemonics' has a problem.<br>See the preview for more information.
Would it be possible to add an option (maybe in the config) to select the theme hljs uses for syntax highlighting?
My current understanding (forgive me if this is incorrect. I'm very much new to working with JS and webdev stuff) is that the colours for the highlighting as well as the background for the code blocks are takeng from _ch-hljs-solarized.css
and _ch-pygments-solarized.css
.
If this isn't a feature that'll be considered, is there someway I can manually change the theme that's being used myself? (I'm assuming I can just edit the .css files to use the correct colours or I can some how add a different .css file and direct the plugin to use that instead?)
Bug description
Pygments highlighter loses a tag.
Reproduction steps
<head><meta></meta></head>
You'll see that a highlighting for <head><meta></head>
gets produced.
Expected behavior
The highlighter should not try to sanitize the HTML.
Additional context
Seems like related to the bug from #45 (comment).
Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.52 (9fe3588e) Python 3.10.4 Qt 5.15.2 PyQt 5.15.6
Platform: Linux
Flags: frz=False ao=True sv=2
Add-ons, last update check: 2022-05-16 15:38:35
Add-ons possibly involved: Highlight Code
Caught exception:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/aqt/main.py", line 349, in onOpenProfile
self.loadProfile(on_done)
File "/usr/lib/python3.10/site-packages/aqt/main.py", line 469, in loadProfile
gui_hooks.profile_did_open()
File "/usr/lib/python3.10/site-packages/aqt/hooks_gen.py", line 3176, in call
hook()
File "/home/grim/.local/share/Anki2/addons21/112228974/main.py", line 192, in load_mw_and_sync
sync_assets(anki_asset_manager)
File "/home/grim/.local/share/Anki2/addons21/112228974/assets.py", line 123, in sync_assets
asset_manager.delete_assets()
File "/home/grim/.local/share/Anki2/addons21/112228974/assets.py", line 48, in delete_assets
clear_cards(self.modify_templates)
File "/home/grim/.local/share/Anki2/addons21/112228974/assets.py", line 116, in clear_cards
modify_templates(lambda tmpl: delete_import_statements(tmpl).strip())
File "/home/grim/.local/share/Anki2/addons21/112228974/main.py", line 142, in modify_templates
mw.col.models.save(model)
File "/usr/lib/python3.10/site-packages/anki/models.py", line 559, in save
self.update(notetype, preserve_usn=False)
File "/usr/lib/python3.10/site-packages/anki/models.py", line 542, in update
notetype["id"] = self.col._backend.add_or_update_notetype(
File "/usr/lib/python3.10/site-packages/anki/_backend/generated.py", line 861, in add_or_update_notetype
raw_bytes = self._run_command(4, 4, 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.CardTypeError: Card template 2 in notetype 'jtest' has a problem.
The front side is identical to card template 1.
A multi-line C++ code block (with <pre>
) which was fine in the desktop version, was shown in a single line in AnkiDroid (previewing in Card Browser).
highlight.js
.<pre>
and <code>
pairs. Removing them and leaving only what the add-on had added, didn't solve the issue either.As seen in the below image, when typing code in the web editor, hitting Enter
or Shift+Enter
would generate a <br>
tag in the HTML source.
Applying Pygments C++ code block seems to be unable to replace <br>
tags with new line.
Using HTML editor to type the code in would be inconvenient; for example because of <
and >
characters, that must be <
and `> respectively.
Hi! First off, just want to say thank you for an awesome Anki plugin. This is super helpful for a lot of CS-related studying.
Bug description
When syntax highlighting code, on some notes it causes Anki's browse window to become unresponsive. The main Anki window still works, but I am unable to close the browse window without force quitting Anki.
After reopening the card I was trying to add code highlighting to, I can see the selected text generated this code (which is incomplete compared to working code blocks I have in other Anki notes).
<span id="5115">text to highlight</span>
rather than:
<pre style="display:flex; justify-content:center;"><code class="language-typescript">text to highlight</code></pre>
Reproduction steps
Steps to reproduce the behavior:
<anki-mathjax>text</anki-mathjax>
.Card template
Not sure if this is relevant, but supplying in case it helps.
Expected behavior
Edit window should still be responsive and the correct HTML should be applied to the selected text.
Card template
My card template is pretty simple.
Front:
{{Front}}
Back:
{{FrontSide}}
<hr id=answer>
{{Back}}
Styling is also simple, so likely unrelated:
.card {
font-family: arial;
font-size: 20px;
}
Additional information
Dear developer, I was wondering if a style for HTML could be added to the list of supported languages.
Thanks in advance.
It would be helpful if the previous highlighter and language selection could be remembered in the input prompt.
To not clutter note types I'd like to have them sectioned with a static comment (with which the section can be deleted as well instead by the regexp)
[...]
<!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
<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>
<!-- Anki Code Highlighter (Addon 112228974) END -->
instead of adding it directly after the card definition
[...]
<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>
An add-on you installed failed to load. If problems persist, please go to the Tools>Add-ons menu, and disable or delete the add-on.
When loading 'Syntax Highlighting for Code':
Traceback (most recent call last):
File "aqt.addons", line 246, in loadAddons
File "C:\Users\maxkr\AppData\Roaming\Anki2\addons21\1463041493_init_.py", line 15, in
from . import main
File "C:\Users\maxkr\AppData\Roaming\Anki2\addons21\1463041493\main.py", line 54, in
LANGUAGES_MAP = {lex[0]: lex[1][0] for lex in get_all_lexers()}
File "C:\Users\maxkr\AppData\Roaming\Anki2\addons21\1463041493\main.py", line 54, in
LANGUAGES_MAP = {lex[0]: lex[1][0] for lex in get_all_lexers()}
IndexError: tuple index out of range
Version 2.1.65 (aa9a734f)
Python 3.9.15 Qt 5.15.2 PyQt 5.15.5
Windows 11
If you need more info just ask :)
Would really appreciate some help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.