gregorias / anki-code-highlighter

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

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

Closed MigueLesPaul closed 1 year ago

MigueLesPaul commented 1 year ago

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 -->
gregorias commented 1 year ago

Hi,

There is an option in the menu bar to remove all co assets and changes made by the plugin.

I'll consider adding an option to select cards that the plugin changes.

On Mon, Jan 16, 2023, 19:56 MigueLesPaul @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/gregorias/anki-code-highlighter/issues/33, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFQLULCDV2YYHLP6U6P4T3WSWKU7ANCNFSM6AAAAAAT5BU4D4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

gregorias commented 1 year ago

I've been coding on this a bit, but may I ask you why you care?

The 4 lines of unused code in a card template shouldn't be a bother, because people don't interact with them often.

As for not-asking to choose which card template to instrument at startup. I think most people wouldn't want to be bothered with this (including me). It would be an anti-feature to make people work.

It would be quite an expensive configuration option to maintain for no apparent gain. I'm leaning towards rejecting this feature request.

MigueLesPaul commented 1 year ago

It seems like when modifying other cards' styles having extra code that will not be used is not very clean in my opinion. Not that I touch my cards style everyday, but as a user, one would like to have some control. Thanks for taking some time to review this.

gregorias commented 1 year ago

I see, thank you.

The extra control is not worth the complexity, i.e., me having to implement and maintain this feature.

I'm leaving the patch of the WIP in case I have to revisit this.

diff --git a/README.md b/README.md
index ef212b0..3a9448d 100644
--- a/README.md
+++ b/README.md
@@ -62,6 +62,48 @@ The plugin accepts the following configuration options:
   plugin.
 * `default-highlighter` (`highlight.js`, `pygments`, ``) — this sets the
   default highlighting mechanism.
+* `card-template-instrumentation-mode` (`all`, `pretagged`; default: `all`) —
+  this variable sets how the plugin instruments card templates.
+
+#### Card template instrumentation mode
+
+By default, this plugin instruments all card templates with JS and CSS imports.
+It adds a snippet like this:
+
+```
+<!-- 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 -->
+```
+
+If you want to manually select card templates that get instrumented with this
+plugin's code, run the following steps:
+
+1. If you have only a few card templates that you want to use this plugin with,
+   remove existing snippets from all card templates (run `Tools > Delete Code
+   Highlighter Assets`). The default plugin configuration adds the snippet to
+   all card templates.
+2. Set `card-template-instrumentation-mode` to `pretagged`.
+3. Restart Anki for the config changes to apply.
+4. For each card template that you want to use this plugin with, add the
+   following guards:
+
+   ```
+   <!-- Anki Code Highlighter (Addon 112228974) BEGIN -->
+   <!-- Anki Code Highlighter (Addon 112228974) END -->
+   ```
+
+5. If you haven't run the the first step where you deleted existing snippets,
+   then for each card template that you do not want to use this plugin with,
+   remove the above guards together with the code they contain.
+6. Refresh Anki Code Highlighter Assets (run `Tools > Refresh Code Highlighter
+   Assets`). This action fills the space between the guard comments you've set
+   with this plugin's instrumentation.
+
+If you ever want to change which card templates get instrumented, rerun steps
+4-6.

 ### Custom styles

diff --git a/codehighlighter/config.json b/codehighlighter/config.json
index 06e8922..6871966 100644
--- a/codehighlighter/config.json
+++ b/codehighlighter/config.json
@@ -4,5 +4,6 @@
     "_ch-pygments-solarized.css",
     "_ch-hljs-solarized.css"
   ],
-  "shortcut": "ctrl+'"
+  "shortcut": "ctrl+'",
+  "card-template-instrumentation-mode": "all"
 }