Added support for overriding CSS styles with STYLES page

This commit is contained in:
Zef Hemel
2023-02-28 10:07:20 +01:00
parent 91cc9a13c7
commit 288e67e380
15 changed files with 63 additions and 27 deletions
+16 -7
View File
@@ -331,13 +331,7 @@ export class Editor {
}
});
// Need to find a nicer way of doing this stuff
if (this.builtinSettings.fontFamily) {
document.getElementById("sb-root")!.setAttribute(
"style",
`--editor-font: ${this.builtinSettings.fontFamily};`,
);
}
this.loadCustomStyles().catch(console.error);
await this.dispatchAppEvent("editor:init");
}
@@ -995,6 +989,21 @@ export class Editor {
contentDOM.setAttribute("autocapitalize", "on");
}
async loadCustomStyles() {
try {
const { text: stylesText } = await this.space.readPage("STYLES");
const cssBlockRegex = /```css([^`]+)```/;
const match = cssBlockRegex.exec(stylesText);
if (!match) {
return;
}
const css = match[1];
document.getElementById("custom-styles")!.innerHTML = css;
} catch {
// Nuthin'
}
}
private restoreState(pageName: string): boolean {
const pageState = this.openPages.get(pageName);
const editorView = this.editorView!;