Giter VIP home page Giter VIP logo

anki-code-highlighter's People

Contributors

dependabot[bot] avatar gregorias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

anki-code-highlighter's Issues

Adding additional highlighting/styling with highlight.js

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?.

Extras configuration clarification

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

Error when running generate-pygments-css

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.

Error message

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

I can't set the default highlighter.

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...

Reproduction steps
image

  1. Add this line of code in the config window.
    "default-highlighter": "pygments"

When saving changes and returning to the config page, the code is automatically reordered:
image

  1. Refresh the assets.

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
ezgif-5-cd1801d17a

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

  • OS version: Windows 10
  • Anki Version ⁨2.1.66 (70506aeb)⁩
  • Python 3.9.15 Qt 6.5.2 PyQt 6.5.2

How to build from source?

according to the README page, to install the plugin from source:

  1. Run package.
  2. Import codehighlighter.ankiaddon in Anki.

Where am I supposed to run these commands?

No colors in the default styles

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:

  1. Install the plugin
  2. Format a code snippet
  3. Only the font changes, no colors are applied.

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.

Screenshots
obraz

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

  • OS version: Windows 11
  • Anki version:
    Version 23.10.1 (fac9e0ee)⁩
    Python 3.9.15 Qt 6.6.0 PyQt 6.6.0

Additional context
I tried

  • using both renderers
  • different programming languages
  • refreshing code highlighter assets from the menu
  • even copying the css around inside the %APPDATA%\Anki directory

Pressing the shortcut doesn’t trigger anything

Hi, 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!

Code-Highlighter not working. (https://github.com/RisingOrange/anki-enhanced-cloze got updated )

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:

  1. Create a highligh-code using 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>&gt;<span class="w"> </span>/dev/null
</code></pre>
</div>
</pre>

Expected behavior
The code isn't highlighted at all. Previously it was working fine.

Screenshots
Screenshot_20230828_111631

Additional information

  • OS version: [e.g. macOS 13.2.1]
  • OS: Arch Linux x86_64
  • Kernel: 6.4.12-arch1-1
  • Anki 2.1.65 and Anki 2.1.66 ( Tested in both )

MarkupResemblesLocatorWarning

Repro

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.

Approach

I probably need to handle BS' warnings.

Change font family

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.

TypeError: 'type' object is not subscriptable after April 19th's Update

The error shows like this:
image

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

Anki error on startup with Anki theme

Bug description
Error on startup, sometimes crashes on startup

Reproduction steps

  1. Start Anki with notetype 'Anki themes: Simple (2.1.0)'

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

  • Windows 10

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

Help with Anki

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.

=D
image
image

Don't add a spurious newline

Bug description
The block highlighting mechanism adds a newline.

Reproduction steps
Steps to reproduce the behavior:

  1. Highlight 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.

Styling code was added to all my cards even the ones not related to coding at all

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 -->

Request for Instructions on Customizing Pygments Styles

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.

Block code displays centered instead of aligned to the left and well indented

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:

  1. Click on 'Add' in the main screen.
  2. Write or paste the code in the field (if I paste from VSCode, I have to clean the HTML tags in the editor).
  3. Select the text which I want to highlight.
  4. Click on the addon icon or Ctrl + '
  5. Select highlight.js and clock OK.
  6. Select HTML (in my case) and click OK.
  7. Click 'Add'.
  8. Preview or review the card.

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.

With highlight.js:
image

With pygments:
image

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">&lt;head&gt; &lt;meta&nbsp;charset="utf-8"&gt; &lt;title&gt;Styles Conference&lt;/title&gt; &lt;link&nbsp;rel="stylesheet"&nbsp;href="assets/stylesheets/main.css"&gt; &lt;/head&gt;</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

  • OS version: Windows 11

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).

Text alignment issue with Pygments Block formatting

Description:

When formatting code using Pygments > Block, the text is not properly aligned to the left.

Reproduction steps:

Download the addon
Add card
Choose Basic card type
Format code -> Pygments -> Block -> C

Expected behavior:

Text should be aligned to the left side of the block.

Screenshots:

image
image

How I manually fixed it:

Opened the _ch-pygments-solarized.css file and added text-align: left; under .pygments>pre

Affected field's HTML code:

<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">&lt;stdio.h&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;string.h&gt;</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">&lt;</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>

Card template

Front Template:

{{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 -->

Back Template

{{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 -->

Styling:

.card {
    font-family: arial;
    font-size: 20px;
    text-align: center;
    color: black;
    background-color: white;
}

OS Version:

Windows 10

Anki version:

Version ⁨2.1.63 (f356f177)⁩
Python 3.9.15 Qt 6.4.3 PyQt 6.4.0

Update Broke compatibility with `Addon-anki-enhanced-cloze`

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

  1. Use code Highlighter to highlight the code Ctrl+'
  2. Select the code and create a cloze
  3. Create the Note
  4. Review the note and try pressing 'J' , the cloze won't ber revealed.

If applicable, provide the offending field's HTML code. For instructions how to get that code, see this Anki help page.

The below highlighted &amp; 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 &lt;iostream&gt;

int main()
{
    std:­:cout &lt;&lt; 8 / 5 &lt;&lt; '\n';
    return 0;
}­}}</code></pre></pre>

Expected behavior
Using 'J' to reveal the clozed card.

Screenshots
image

Additional information

  • OS - Arch Linux x86_64, Kernel: 6.1.39-3-lts

line brakes disappear while pasting codes

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?

p1

Pygments highlighting doesn't escape HTML entities

Bug description
Pygments highlighting doesn't escape HTML entities

Reproduction steps

  1. Copy paste the following code into as a field's HTML:
$ 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 &gt; int >.

image

Expected behavior
image

Additional context
Seems like the bug from #45 (comment) wasn't fixed.

Block code not indented

Hello dear developer! First of all, thanks a lot for your work on this addon.
The issue is that the code looks like this:

image

I expected to see a proper indentation but it centers everything. If I try to use Pygments, it looks like this:

image

Perhaps I'm doing something wrong?

Bug on startup

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.

The addon crashes on multiprofile setups

Reproduction

  1. Have multiple profiles set up in Anki.
  2. Start Anki (with the addon installed).

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'

highlight.js for cloze cards?

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)
{
&nbsp;&nbsp;&nbsp; [&amp;]{};&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // {{c1::OK: by-reference capture default}}
}</code></pre><br>

image
image

Update Pygments

The current Pygments version is 2.16.0, but this plugin still uses 2.13.0.

Error on decks

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.

image

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!

Error on startup after install

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.

Changing syntax highlighting themes for the dark and light mode versions.

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?)

Pygments highlighter loses a <meta> tag

Bug description
Pygments highlighter loses a tag.

Reproduction steps

  1. Copy paste the following code into a field:
<head><meta></meta></head>
  1. Highlight the pasted code with Pygments (HTML language).

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).

CardTypeError: Card template ⁨2⁩ in notetype '⁨jtest⁩' has a problem.

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⁩.

C++ code shown in a single line (AnkiDroid)

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).

  • I used highlight.js.
  • My code block already had <pre> and <code> pairs. Removing them and leaving only what the add-on had added, didn't solve the issue either.

C++ code block issue with new line in web editor in Desktop version (Pygments)

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.
0-RichEdit
Applying Pygments C++ code block seems to be unable to replace <br> tags with new line.
2

Using HTML editor to type the code in would be inconvenient; for example because of < and > characters, that must be &lt; and `> respectively.

Anki freezes when highlighting code in cards using MathJax

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:

  1. Open the Anki browse window
  2. Important: choose a card that is using MathJax (HTML outputs to <anki-mathjax>text</anki-mathjax>.
  3. Highlight some additional plain text that is not MathJax.
  4. Use the shortcut or click the button in the UI
  5. After choosing highlight.js or pygments & the programming language, the edit portion of the Anki browse window becomes unresponsive & the window cannot be closed without force quitting.
  6. Cancelling instead of applying the highlight also results in an unresponsive window.
  7. Additional detail: Upon reopening, the addon no longer remembers what the previously used language was.

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

  • OS version: macOS Ventura 13.2.1
  • Apple M2 chip
  • Anki version:
    • Version ⁨2.1.60 (76d88073)⁩
    • Python 3.9.15 Qt 6.3.2 PyQt 6.3.1

Improve adding/removing import statement on note types

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)

return re.sub(f'^<[^>]*class="{class_name}"[^>]*>[^\n]*\n',

e.g.

[...]

<!-- 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>

Failed to load Addon uppon Starting Anki

This is the error message:

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

My Anki

Version ⁨2.1.65 (aa9a734f)⁩
Python 3.9.15 Qt 5.15.2 PyQt 5.15.5

My System

Windows 11

If you need more info just ask :)

Would really appreciate some help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.