1
0

STYLES handling changes (via SETTINGS)

This commit is contained in:
Zef Hemel 2023-07-02 14:48:27 +02:00
parent 1ae02416b6
commit fabd785f6d
5 changed files with 20 additions and 11 deletions

View File

@ -1270,8 +1270,11 @@ export class Editor {
}
async loadCustomStyles() {
if (this.settings?.customStyles) {
try {
const { text: stylesText } = await this.space.readPage("STYLES");
const { text: stylesText } = await this.space.readPage(
this.settings?.customStyles,
);
const cssBlockRegex = /```css([^`]+)```/;
const match = cssBlockRegex.exec(stylesText);
if (!match) {
@ -1279,8 +1282,9 @@ export class Editor {
}
const css = match[1];
document.getElementById("custom-styles")!.innerHTML = css;
} catch {
// Nuthin'
} catch (e: any) {
console.error("Failed to load custom styles", e);
}
}
}

View File

@ -35,6 +35,7 @@ export type BuiltinSettings = {
indexPage: string;
// Format: compatible with docker ignore
spaceIgnore?: string;
customStyles?: string;
};
export type PanelConfig = {

View File

@ -6,6 +6,7 @@ release.
## Next
* **Breaking change (for some templates):** Template in various places allowed you to use `{{variables}}` and various handlebars functions. There also used to be a magic `{{page}}` variable that you could use in various places, but not everywhere. This has now been unified. And the magical `{{page}}` now has been replaced with the global `@page` which does not just expose the pages name, but any page meta data. More information here: [[🔌 Core/Templates@vars]]. You will now get completion for built-in handlebars helpers after typing `{{`.
* **Breaking change** (for [[STYLES]] users). The [[STYLES]] page is now no longer “magic” and hardcoded. It can (and must) now be specified in [[SETTINGS]] (see example on that page) for styles to be loaded from it.
* Folding is here (at least with commands, not much UI): {[Fold: Fold]}, {[Fold: Unfold]}, {[Fold: Toggle Fold]}, {[Fold: Fold All]} and {[Fold: Unfold All]}.
* {[Broken Links: Show]} command (not complete yet, but already useful)
* The `Daily Note` template now supports setting a caret position with `|^|`.

View File

@ -4,6 +4,9 @@ This page contains settings for configuring SilverBullet and its Plugs. Changing
# Initial page to load when launching SB
indexPage: SilverBullet
# Load custom CSS styles from the following page
customStyles: STYLES
# Template related settings
pageTemplatePrefix: "template/page/"
snippetPrefix: "snippet/"

View File

@ -1,4 +1,4 @@
If you create a [[STYLES]] page in your project, SilverBullet will look for a CSS code block inside that page and load it upon boot (an example can be found below).
In [[SETTINGS]] you can define a `customStyles` setting that links to a page like this. SilverBullet will load the specified page, find a CSS code block inside that page and load it upon boot (an example can be found below).
This can be used to achieve various things, such as overriding the default editor font or setting wider page widths. What CSS styles you can override is not very well documented, youll have to reverse-engineer things a bit for now, unfortunately.