gregorias / anki-code-highlighter

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

bug: Code Block - Selection Highlight Error #72

Closed ht-l1 closed 6 months ago

ht-l1 commented 6 months ago

Bug description A clear and concise description of what the bug is. When I click on the add-on button trying to highlight the code block, it gives me the error below. "The selection splits an HTML node, which prevents the highlighting plugin from proceeding"

Reproduction steps Steps to reproduce the behavior:

  1. Go to 'card'
  2. highlight the code block
  3. Click on 'code highlight button'
  4. See error

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

Expected behavior A clear and concise description of what you expected to happen.

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.

anki - code highlight error

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.

Additional information

Additional context Add any other context about the problem here.

gregorias commented 6 months ago

Hi @ht-l1, thank you for raising this issue.

It's an unfortunate limitation of the way I managed to implement the main functionality of this plugin. I will not have the time to make the process more robust any time soon, but here are the steps needed to make it work for you:

  1. Check the HTML of the node. The code you select is probably wrapped with HTML elements and your selection is then probably selecting a partial HTML element.
  2. Copy your code snippet into the HTML editor directly. This way you'll get rid of the offending HTML tags. Don't worry that the WYSWIG editor shows the code snippet without any markup.
  3. Select the code snippet in the WYSWIG editor and click highlight.

The above procedure should enable you to highlight your code snippets. In the future, I recommend either writing code snippets manually, pasting without markup (cmd+shift+v, I think) or pasting into the HTML editor to avoid running into this issue.

ht-l1 commented 6 months ago

gotcha that makes perfect sense, thank you so much for providing the workarounds. Awesome plugin :) appreciate it @gregorias !