lervag / apy

CLI script for interacting with local Anki collection
MIT License
227 stars 17 forks source link

Code shows with white background on Anki #83

Closed vinoff closed 5 months ago

vinoff commented 5 months ago

I am using Apy to create some anki cards that have code in them (python). The code shows with a white background. I would like it to have a dark background, according to some dark-mode color scheme, such as monokai or gruvbox or whatever. Anything dark, really..

Is this something done on apy or anki itself? How?

lervag commented 5 months ago

I am using Apy to create some anki cards that have code in them (python). The code shows with a white background. I would like it to have a dark background, according to some dark-mode color scheme, such as monokai or gruvbox or whatever. Anything dark, really..

This is supported, yes. I did not add support to change the theme, but it should already by Monokai, I think.

Is this something done on apy or anki itself? How?

It is done by apy while converting from Markdown to HTML, here: https://github.com/lervag/apy/blob/50ee12a09004c38bec7e895dd7e3fb7229a387e6/src/apyanki/fields.py#L238-L254

I'm not sure how much Python you know, so it's hard to know at which level of detail I should explain things.

It may be easier to answer your question if you are somewhat more specific. For instance, you could give some concrete example of the card content you want.

vinoff commented 5 months ago

On input.md, I have the following:

apy3

Then I import using apy (apy add-from-file input.md) and I see the following on Anki desktop:

apy2

I am using Anki desktop:

Version ⁨24.04 (429bc9e1)⁩
Python 3.11.8 Qt 6.7.0 PyQt 6.7.0.dev2404081550

You see that white background in the code? I would like that to be using some dark color scheme, dark background. Does this not happen on your apy/anki? Any idea what I am doing wrong?

lervag commented 5 months ago

You see that white background in the code? I would like that to be using some dark color scheme, dark background. Does this not happen on your apy/anki? Any idea what I am doing wrong?

Good question. I believe it may be using a light colorscheme to contrast it from your already dark scheme of Anki. Can you check how it looks in Anki if you force light scheme in Anki desktop?

lervag commented 5 months ago

Ok, so: this is the part that specifies the colorscheme used for the highlighting:

https://github.com/lervag/apy/blob/50ee12a09004c38bec7e895dd7e3fb7229a387e6/src/apyanki/fields.py#L246

Perhaps I should let this be configurable.

lervag commented 5 months ago

After you did apy add-from-file ..., you can do apy review tag:tag1. It will give you a note browser where you can edit and update change/update/delete your notes. The menu keys are listed at the top. Continue until you reach the note in your example. From there:

  1. How does it look like in your terminal (screenshot)?
  2. What does the resulting html code look like (you can inspect it with the p action)?
vinoff commented 5 months ago

You see that white background in the code? I would like that to be using some dark color scheme, dark background. Does this not happen on your apy/anki? Any idea what I am doing wrong?

Good question. I believe it may be using a light colorscheme to contrast it from your already dark scheme of Anki. Can you check how it looks in Anki if you force light scheme in Anki desktop?

This is with light mode:

apy4

vinoff commented 5 months ago

apy review tag:tag1

Here is a screenshot:

apy5

And here is the html:

apy6html

lervag commented 5 months ago

Thanks!

I think there are two important points here:

I believe your issue can be resolved if I added a new option to the config file.

vinoff commented 5 months ago

Thanks!

I think there are two important points here:

* We can specify the colorscheme to use for the code blocks.

* The colorscheme will not be dynamic, it will look the same in both light and dark mode.

I believe your issue can be resolved if I added a new option to the config file.

That would be great! And btw, thanks for Apy! Other than this hiccup, it really is everything I was looking for!

lervag commented 5 months ago

That would be great! And btw, thanks for Apy! Other than this hiccup, it really is everything I was looking for!

Thanks, I'm glad to hear that! It has been a huge improvement to my own workflow for creating and managing my Anki notes, and I'm glad to hear it can be useful to others as well!

lervag commented 5 months ago

I believe my latest commit should provide the desired feature. Please test it. Let me know if you need guidance.

vinoff commented 5 months ago

I was just testing but no changes, though I just reinstalled using pip.. I suppose pip pulls from the releases though, right?

lervag commented 5 months ago

Ah, yes, sorry; I only pushed to the repo - I didn't make a new release. I'll push to pypi tomorrow or Sunday. If you want to test from the repo, you can do:

git clone https://github.com/lervag/apy
cd apy
pipx install -f .
vinoff commented 4 months ago

Hey @lervag.

I tested it and it seems to be working correctly.

There was just one issue that may or may not have something to do with apy: https://github.com/ankidroid/Anki-Android/issues/16227, but it seems to have been fixed by Anki-Droid and also is fixable with css as I commented in that issue.

Would it be possible for you to do a release of apy, so I can properly install this?

lervag commented 4 months ago

Would it be possible for you to do a release of apy, so I can properly install this?

Yes, sorry - I've bumped to v0.15.3 and published. I'm new to the pypi thing; feel free to remind me again in the future if you should notice I forget it again!

I tested it and it seems to be working correctly.

Great, glad to hear it!

There was just one issue that may or may not have something to do with apy: ankidroid/Anki-Android#16227, but it seems to have been fixed by Anki-Droid and also is fixable with css as I commented in that issue.

Yes and no - this is not really due to apy, it's more about how the code blocks are converted from markdown to html. The markdown library uses pygments and will give a code block the .codehilite class. My own settings for .codehilite are as follows:

.codehilite, .codehilitetable {
  margin: auto;
  display: inline-block;
  text-align: left;
}

.codehilite pre, .codehilitetable pre {
  margin: 0;
  font-size: 14px;
  background-color: #eee;
}

.mobile .night_mode .codehilite pre {
  background-color: #303030;
}