twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
1.06k stars 67 forks source link

Magic to retrieve dark/light mode setting information #273

Open Akkete opened 1 year ago

Akkete commented 1 year ago

I would like to render my code outputs differently based on if light or dark mode is used in settings (e.g. make plots white on black or black on white). I imagine this would most likely take the form of a magic command most likely. There are probbaly some other options that might be useful as well, but I don't know which.

mayurankv commented 1 year ago

Seen #187. If you can set a background in the programming language plotter (i.e. set_facecolor in matplotlib), then you can write a short line to have two different background colours set.

For example ax.set_facecolor('white' if @theme == 'light' else 'black'). You could actually just set two dictionaries of colours you want (some colorscheme) and select either dictionary using this for a range of different colours.

All of this logic could be additionally implemented in a pre codeblock or in the code that is run every time from settings.