gregorias / anki-code-highlighter

Anki plugin for code syntax highlighting.
GNU Affero General Public License v3.0
54 stars 3 forks source link

Is there a way to have unhighlighted <pre><code> blocks? #76

Closed revsuine closed 3 months ago

revsuine commented 5 months ago

Hiya,

Firstly thanks a ton for making this plugin; I've found it super useful for my Anki workflow.

I have a card with some pseudocode on it and I've put it in <pre><code> blocks. I think the plugin has automatically added highlighting that doesn't really make sense to the pseudocode. When I looked through the list of languages I didn't see a plaintext option.

Is it possible to add a plaintext/unhighlighted option for code blocks for pseudocode or anything else users might not want highlighted but still want to display in a code block? Or if this is something that is already possible I would appreciate being told how to do this :) Thanks!

gregorias commented 5 months ago

Thank you for your kind words and raising this to my attention.

highlight.js has plain text:

grafik

Does that work for you?

I think the plugin has automatically added highlighting that doesn't really make sense to the pseudocode.

That’s not good, I’ll take a look when I find some time.

revsuine commented 5 months ago

Thank you, I must have missed that! If it helps with the bug hunting, here is the exact html of the card in question:

<h1>
  Stack-based ISA
</h1><pre style="display:flex; justify-content:center;"><code>Push A
Push B
Add
Pop C</code></pre><h1>
  Accumulator-based ISA
</h1><pre style="display:flex; justify-content:center;"><code>Load A
Add B
Store C</code></pre><h1>
  Register-memory-based ISA</h1><pre style="display:flex; justify-content:center;"><code>Load R1, A
Add R3, R1, B
Store R3, C</code></pre><h1>Load-store-based ISA</h1><pre style="display:flex; justify-content:center;"><code>Load R1, A
Load R2, B
Add R3, R1, R2
Store R3, C</code></pre>

And the appearance: 2024-01-17-113534_714x811_Screenshot

I know I've added style="display:flex; justify-content:center;" to the pre blocks but that's just to make it display in a box; the code highlighting still appears without the pre style.

gregorias commented 3 months ago

I found the culprint. I’m calling highlightAll, which highlights all <pre><code> tags. Will need to figure out a more targeted applications of hljs.