silverbulletmd / silverbullet

The knowledge tinkerer's notebook
https://silverbullet.md
MIT License
2.36k stars 169 forks source link

Store extracted customStyles in uiOptions #731

Closed joekrill closed 7 months ago

joekrill commented 7 months ago

Stores the results of loading/parsing settings.customStyles inuiOptions.

Motivation

For the treeview plug I'd like to match the main application styles as closely as possible to be consistent. For the best results, we really need to:

  1. Use the CSS variables and styles defined by the current theme.
  2. Know the current theme (dark mode).
  3. Apply any user-defined custom styles.

The first two are fairly simple to handle in a plug (see here and here). In order to get the custom styles, though, I would have to duplicate the logic of the loadCustomStyles function. While relatively straight-forward, it seemed like this might be less error prone, more maintainable, more performant, and allow other plugs can take advantage of the functionality without having to re-implement it. Now a plug can just call await editor.getUiOption("customStyles") to get the custom styles.

Thoughts? Does this seem like a useful and reasonable change? And is uiOptions the right place for this?

We could also consider making this functionality the default for all panels created using showPanel. I had originally planned on putting up a PR for that, before realizing that it was pretty straight-forward to leave it up to the plug. That also has a lot more implications and would affect any existing plugs (though it did give the Markdown Preview dark mode support!). I guess the real question is: should it be a simple opt-in, simple opt-out, or up to the plug to handle the details?

gorootde commented 7 months ago

Guess this would also be the first step to fix #705

joekrill commented 7 months ago

Guess this would also be the first step to fix #705

Yes it would help! If/after this (or something like it) gets merged, I was planning on then putting up a PR for the built-in Markdown plug to handle dark mode and custom styles.

zefhemel commented 7 months ago

Looks good