Get Anki's CSS variables for colors

Hi,

Is there a “correct way” to get the CSS for the Anki colors? Right now I am doing the following but it’s a bit hacky:

from aqt import colors
def get_colors(dark):
    """Get CSS string with Anki colors"""
    css = ":root {\n"
    for key, val in colors.__dict__.items():
        if type(val) is dict and (val_ := val.get('dark') if dark else val.get('light')):
            css += f'''   --{key.lower().replace('_', '-')}: {val_};\n'''
    css += '}'
    return css

Cheers

Those colors can also be found in webview.css which gets distributed with Anki, or can be taken from out/sass/_root-vars.css when building from source.

Thanks, I interpret that as that there is no function/method to get them as an object or string?

Thanks

As far as I’m aware, there isn’t.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.