- Home
- 💡 Simple card
- 🔎 Missing! card
- 🖍️ Draw! card
- 🧑🎨 Add color to your code
- 🧑🎓 The professional way
First
npm installto install dependencies.1npm lsshould listlessandprint-first-css.npm run buildto compile the css and demo.
You should know how to clone or fork a Github repository. You should also have npm and pandoc installed. Once you've done that, run the commands above, and you can continue reading.
npm run dataand you're done. So simple!
The /data/* files are a helpful way to quickly write your Anki cards. You can compile them into HTML and add the sections to a card's fields. They're well <!-- commented --> so you'll know what to do with each field. Make sure you've read each card's documentation before you use these data- files. They'll make more sense then.
Each data-* file will be updated when you run this command. There's also a special data-code.md and data-code.html file that's helpful to compile code blocks. This can convert from .md -> .html and back again.
The /data/*html files are for viewing in your code editor only.1
I'm keeping this dead simple, for beginners to intermediates. We're only interested in colours and typography for customisations. Apologies if this is slightly convoluted right now. It'll take a little playing around to find the right match of colours.
🧑🎨 Have fun, and please do share your themes! 🎨
source
│
└───style
│ main.less
│
└───base
│ │
│ └───variables
│ breezedark.less
| custom-theme.less -- create this file!
│ typography.less
│
└───globals
│ breezedark.less
| custom-theme.less -- and this one!
│
└───themes
│
└───custom
custom-theme.md -- then compile this :)
template.html
|
build
|
└───custom -- and preview your changes here!
You'll find a
/customfolder with a helpful.mdfile that allows you to preview yourcustom-theme.lesschanges. You can see what each language looks like with your custom theme.
We're using CSS variables (e.g: var(--color-code-dark-*)) and compiling them with Less CSS. You can find the current theme colours in /style/base/variables/breezedark.less. Have a play with them and see what you can create!
- You'll mostly be editing your
variables/custom-theme.lesscolours ...- You can reference the
--color-code-*variables inbreezedark.less
- You can reference the
- You can also view Pandoc's Skylighting theme colours (see below)
- They're fine, but there's much better themes in the wild!
If you'd like to make finer-grain changes to the flashcard styles (e.g: --font-* variables), you'll find them in base/variables/typography.less and (for basic changes) the /base/html folder. I wouldn't go too crazy with changes, or else you may as well fork this repo and build your own.
It's best to create your own custom-*.less files (adding them to a .gitignore file), rather than risk losing any changes when this repo updates.
Once you've chosen the colours you want within the
custom-*.lessfiles, you'll need to// commentout the defaults to override them inmain.less.
- Go to the
main.lessfile - Create and
@importthebase/files:variables/custom-theme.less(color variables)globals/custom-theme.less(Pandoc's Skylighting typography)
npm run cssto compile changes
Just like
/build/demo/*.htmlfiles, we can preview our changes at/build/custom/*
Once you've compiled your custom-theme.less go to /build/custom/custom-theme.html and preview your changes! You can see how it looks with lots of different programming languages. You could also view the build/demo/*html files to see how they've changed too.
⚠️ It's not a good idea to edit the/demofolder!
The /themes/demo/* files are just for demo purposes. These can be previewed with your new CSS changes, but should be left alone. Our repository should be up-to-date with all the correct devDependencies, but if anything goes wrong, send me an issue.2
Finally, just a quick note on Less CSS and those .less files. I'm only using this to nicely order the CSS files for quick viewing and compiling. I don't advocate using preprocessors anymore.3
It's best to stick to dark themes, but you can create a light one too!
Our main code blocks use a dark theme. The light theme is only used for notes sections, where needed. For that reason, I'd generally stick with dark themes for your custom-theme.less. You could look at how Print First CSS manages it's light theme and use those variables if you wish, but I can't guarantee that it won't change in future.
We're ready to add your brand new theme to Anki!
Open the Anki desktop app and:
- Go to
Tools > Manage Note Types - Select the
APF: ...Note Type - Select the
Cardsbutton - Select the
Stylingoption - Delete the CSS
- Add your custom CSS from your custom
main.cssfile - Repeat for each Card Type you'd like to edit
Take care to keep your repository up-to-date, so that whenever Anki Programming Flashcards update, you don't lose your changes.
Every time this repo the updates it's CSS with a new release, make sure your clone or fork is up-to-date. Upload the .apkg deck to the Anki desktop app first, then manually override your CSS.
If you have any problems, create an issue in this repo.
Check out Pandoc's syntax highlighting and demos (number 18).
Pandoc's Skylighting comes with a bunch of default styles. The json names are very similar to the --color-code-dark-* variables and .sourceCode class names we're using. You can see a visual overview of all default themes.
pandoc --list-highlight-stylespandoc --print-highlight-style=<theme>pandoc -s data-code.md --highlight-style=<theme> -o data-code.html
It'll take a little playing around to find the right match of colours. Have fun, and please do share your themes!
There's a known bug in Pandoc that I've noted here — currently some (all?) languages have limited "tokens", meaning our Markdown code blocks don't always render as well as other highlighting scripts. No matter how you arrange your colours, there's going to be trade-offs (which colours work best for each token?).
Another thing to mention is dependency hell, and I feel I've made the best of the available options for highlighting (for long-term support).
This is now out of scope for this repo.
Footnotes
-
Our
/data/*htmlfiles are not supposed to be rendered in the browser. They're just for speedy compiling of data ready for your Anki Flashcard fields. ↩ ↩2 -
It seems that without theOtherwise running#commitnumber(e.g:github:badlydrawnrob/print-first-cssin dev dependencies) runningnpm update --savewill automatically update all packages, including the very latestprint-first-cssGithub repo commit.npm update <github-repo-package>won't update properly. I keep all the packages up-to-date anyway, but if you have any issues you might have to change the#commitnumber inpackage.jsonand runnpm install print-first-cssto force it to update.npm auditandnpm audit fixcan remove other errors (follow the prompts). ↩ -
There's plenty of time for preprocessors, fancy frameworks, and whatever else takes your fancy later in your career. Find yourself a good book and get learning! ↩