Skip to content

📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

feat: custom styes injection

Smaug67396ee9f7e46721
diff --git a/frontend/app/components/AppPreferenceInputSection.vue b/frontend/app/components/AppPreferenceInputSection.vue
index 996c497a..bdc069a3 100644
--- a/frontend/app/components/AppPreferenceInputSection.vue
+++ b/frontend/app/components/AppPreferenceInputSection.vue
@@ -2,7 +2,7 @@
<div v-for="(section, i) in options" :key="i" class="section">
<h3>{{ section.label }}</h3>
- <div v-for="opt in section.options" :key="opt.key" class="form-group">
+ <div v-for="opt in section.options" :key="opt.key" :class="['form-group', opt.type === 'textarea' ? 'form-group--vertical' : '']">
<div>
<label>{{ opt.label }}</label>
@@ -42,6 +42,17 @@
</label>
</div>
</div>
+
+ <!-- Textarea -->
+ <textarea
+ v-else-if="opt.type === 'textarea'"
+ v-model="p(opt.key).value"
+ class="entry textarea-entry"
+ :placeholder="opt.placeholder || ''"
+ :rows="opt.rows || 6"
+ spellcheck="false"
+ @input="opt.onChange?.(p(opt.key).value)"
+ />
</div>
</div>
</template>
@@ -73,6 +84,10 @@ defineProps<{
gap: 1rem;
justify-content: space-between;
margin-bottom: 1rem;
+
+ &--vertical {
+ flex-direction: column;
+ }
}
label {
@@ -104,4 +119,18 @@ h3 {
grid-template-columns: repeat(2, 1fr);
}
}
+
+.textarea-entry {
+ width: 100%;
+ max-width: 100%;
+ font-size: 0.8rem;
+ line-height: 1.5;
+ resize: vertical;
+ tab-size: 2;
+
+ &::placeholder {
+ color: var(--text-secondary);
+ opacity: 0.7;
+ }
+}
</style>
diff --git a/frontend/app/components/MarkdownEditor/MarkdownEditor.vue b/frontend/app/components/MarkdownEditor/MarkdownEditor.vue
index 0409e545..5a55cbad 100644
--- a/frontend/app/components/MarkdownEditor/MarkdownEditor.vue
+++ b/frontend/app/components/MarkdownEditor/MarkdownEditor.vue
@@ -24,7 +24,7 @@
<div class="panel-header">
<span class="panel-label">Preview</span>
</div>
- <div ref="markdownPreview" :class="['markdown-preview', `${theme}-theme`]" v-html="document.content_compiled" />
+ <div ref="markdownPreview" :class="['markdown-preview', `${theme}-theme`, `document-content`]" v-html="document.content_compiled" />
</div>
</div>
</div>
diff --git a/frontend/app/composables/usePreferences.ts b/frontend/app/composables/usePreferences.ts
index d26d924c..0bb2c47f 100644
--- a/frontend/app/composables/usePreferences.ts
+++ b/frontend/app/composables/usePreferences.ts
@@ -50,6 +50,9 @@ export const DEFAULT_PREFERENCES = {
editorSnippetsEnabled: true as boolean,
editorSimplifiedViewOnMobile: true as boolean,
developerMode: false as boolean,
+ stylesInjectionEnabled: false as boolean,
+ stylesInjection: '' as string,
+ stylesDocumentsInjection: '' as string,
};
// Crée un type mapping automatique : chaque clé => type exact
@@ -113,7 +116,7 @@ export function usePreferences() {
};
}
-type OptionType = 'toggle' | 'select' | 'color' | 'radio' | 'groupCheckbox' | 'anode';
+type OptionType = 'toggle' | 'select' | 'color' | 'radio' | 'groupCheckbox' | 'anode' | 'textarea';
interface BaseOption<K extends PreferenceKey = PreferenceKey> {
label: string;
description?: string;
@@ -152,5 +155,13 @@ interface AnodeOption<K extends PreferenceKey = PreferenceKey> extends BaseOptio
onChange?: (value: Preferences[K]) => void;
}
-export type Option = ToggleOption | ColorOption | SelectOption | RadioOption | GroupCheckboxOption | AnodeOption;
-export type { ColorOption, SelectOption, RadioOption, ToggleOption, GroupCheckboxOption, AnodeOption };
+interface TextareaOption<K extends PreferenceKey = PreferenceKey> extends BaseOption<K> {
+ type: 'textarea';
+ placeholder?: string;
+ rows?: number;
+ language?: string;
+ onChange?: (value: Preferences[K]) => void;
+}
+
+export type Option = ToggleOption | ColorOption | SelectOption | RadioOption | GroupCheckboxOption | AnodeOption | TextareaOption;
+export type { ColorOption, SelectOption, RadioOption, ToggleOption, GroupCheckboxOption, AnodeOption, TextareaOption };
diff --git a/frontend/app/composables/useStyleInjection.ts b/frontend/app/composables/useStyleInjection.ts
new file mode 100644
index 00000000..43a25bef
--- /dev/null
+++ b/frontend/app/composables/useStyleInjection.ts
@@ -0,0 +1,75 @@
+/**
+ * Manages user-injected CSS styles in a safe, encapsulated way.
+ *
+ * - Styles are wrapped in CSS `@layer` to keep them lower priority than app defaults
+ * (unless the user explicitly uses `!important`).
+ * - Each style sheet is a dedicated `<style>` element in the `<head>`.
+ * - When disabled, the elements are fully **removed** from the DOM — not just emptied —
+ * so no residual overrides (CSS variables, etc.) can leak.
+ * - On cleanup (component unmount), elements are also removed.
+ */
+
+interface StyleSheet {
+ id: string;
+ layer: string;
+ el: HTMLStyleElement | null;
+}
+
+function createSheet(id: string, layer: string): StyleSheet {
+ return { id, layer, el: null };
+}
+
+function mountSheet(sheet: StyleSheet, css: string) {
+ if (!css.trim()) {
+ unmountSheet(sheet);
+ return;
+ }
+
+ if (!sheet.el) {
+ sheet.el = document.createElement('style');
+ sheet.el.id = sheet.id;
+ sheet.el.setAttribute('data-user-injection', 'true');
+ document.head.appendChild(sheet.el);
+ }
+
+ // Wrap in @layer so user styles have lower specificity than app defaults
+ sheet.el.textContent = `@layer ${sheet.layer} {\n${css}\n}`;
+}
+
+function unmountSheet(sheet: StyleSheet) {
+ if (sheet.el) {
+ sheet.el.remove();
+ sheet.el = null;
+ }
+}
+
+export function useStyleInjection() {
+ const preferences = usePreferences();
+
+ const enabled = preferences.get('stylesInjectionEnabled');
+ const appCss = preferences.get('stylesInjection');
+ const docsCss = preferences.get('stylesDocumentsInjection');
+
+ const appSheet = createSheet('user-styles-app', 'user-app');
+ const docsSheet = createSheet('user-styles-docs', 'user-documents');
+
+ const apply = () => {
+ if (!enabled.value) {
+ unmountSheet(appSheet);
+ unmountSheet(docsSheet);
+ return;
+ }
+ mountSheet(appSheet, appCss.value);
+ mountSheet(docsSheet, `.document-content {\n${docsCss.value}\n}`);
+ };
+
+ watch(enabled, apply, { immediate: true });
+ watch(appCss, apply);
+ watch(docsCss, apply);
+
+ // Clean up on unmount
+ onScopeDispose(() => {
+ unmountSheet(appSheet);
+ unmountSheet(docsSheet);
+ });
+}
diff --git a/frontend/app/pages/(public)/doc/[id]/index.vue b/frontend/app/pages/(public)/doc/[id]/index.vue
index b2f259a6..f8fed271 100644
--- a/frontend/app/pages/(public)/doc/[id]/index.vue
+++ b/frontend/app/pages/(public)/doc/[id]/index.vue
@@ -14,7 +14,13 @@
<NodeDocumentHeader :doc="article" :public="true" style="margin: 20px 0" />
<!-- Document content if available -->
- <article v-if="hasContent" ref="element" :class="`${article.theme || theme}-theme`" style="max-width: 100%" v-html="article.content_compiled" />
+ <article
+ v-if="hasContent"
+ ref="element"
+ :class="[`${article.theme || theme}-theme`, 'document-content']"
+ style="max-width: 100%"
+ v-html="article.content_compiled"
+ />
<!-- Hierarchical children tree -->
<NodeTree v-if="children.length > 0" :nodes="children" :parent-id="article.id" />
diff --git a/frontend/app/pages/dashboard.vue b/frontend/app/pages/dashboard.vue
index 056cd0f4..a0e4d02b 100644
--- a/frontend/app/pages/dashboard.vue
+++ b/frontend/app/pages/dashboard.vue
@@ -21,6 +21,7 @@ const userStore = useUserStore();
nodesStore.init();
userStore.fetch();
+useStyleInjection(); // Custom styles for the app and documents
const { initGlobalListeners, destroyGlobalListeners } = useCommandCenter();
onMounted(() => {
diff --git a/frontend/app/pages/dashboard/docs/[id].vue b/frontend/app/pages/dashboard/docs/[id].vue
index 995787b3..3a9312fd 100644
--- a/frontend/app/pages/dashboard/docs/[id].vue
+++ b/frontend/app/pages/dashboard/docs/[id].vue
@@ -5,7 +5,13 @@
<div :style="{ maxWidth: width }" class="doc-container">
<NodeDocumentHeader :doc="node" style="margin-bottom: 20px" />
- <article v-if="node" ref="element" :class="`${node.theme || theme}-theme`" style="max-width: 100%" v-html="node.content_compiled" />
+ <article
+ v-if="node"
+ ref="element"
+ :class="[`${node.theme || theme}-theme`, 'document-content']"
+ style="max-width: 100%"
+ v-html="node.content_compiled"
+ />
<NodeDocumentSkeleton v-else />
<NodeDocumentFooter :document="node" :next="next" :previous="previous" />
</div>
diff --git a/frontend/app/pages/dashboard/settings/_views/styles.vue b/frontend/app/pages/dashboard/settings/_views/styles.vue
new file mode 100644
index 00000000..756bab59
--- /dev/null
+++ b/frontend/app/pages/dashboard/settings/_views/styles.vue
@@ -0,0 +1,44 @@
+<template>
+ <div>
+ <h2 class="page-title">Styles injection</h2>
+ <p class="page-subtitle">Inherit and customize the application and document styles.</p>
+
+ <AppPreferenceInputSection :options="options" />
+ </div>
+</template>
+
+<script setup lang="ts">
+type InterfaceOption = Option & {
+ tag?: string;
+};
+
+const options: Array<{ label: string; options: InterfaceOption[] }> = [
+ {
+ label: 'Custom styles',
+ options: [
+ {
+ label: 'Enable custom styles injection',
+ description: 'Inject your own CSS to customize the app and document themes. Changes are applied in real-time.',
+ type: 'toggle',
+ key: 'stylesInjectionEnabled',
+ },
+ {
+ label: 'Application styles',
+ description: 'CSS applied globally to the entire application (layout, sidebar, navbar, etc.)',
+ type: 'textarea',
+ key: 'stylesInjection',
+ placeholder: '/* e.g. */\n:root {\n --surface-base: #1a1a2e;\n}',
+ rows: 8,
+ },
+ {
+ label: 'Document styles',
+ description: 'CSS applied to document content (markdown preview, typography, code blocks, etc.)',
+ type: 'textarea',
+ key: 'stylesDocumentsInjection',
+ placeholder: '/* e.g. */\nh1 {\n color: coral;\n}',
+ rows: 8,
+ },
+ ],
+ },
+];
+</script>
diff --git a/frontend/app/pages/dashboard/settings/index.vue b/frontend/app/pages/dashboard/settings/index.vue
index 071cf968..72e118b2 100644
--- a/frontend/app/pages/dashboard/settings/index.vue
+++ b/frontend/app/pages/dashboard/settings/index.vue
@@ -40,6 +40,7 @@ import SnippetsView from './_views/snippets.vue';
import MarkdownView from './_views/markdown.vue';
import AboutView from './_views/about.vue';
import AdvancedView from './_views/advanced.vue';
+import StylesView from './_views/styles.vue';
type PageKey = keyof typeof pages;
@@ -69,6 +70,7 @@ const pages = {
markdown: MarkdownView,
about: AboutView,
advanced: AdvancedView,
+ styles: StylesView,
} as const;
defineProps<{ isModal?: boolean }>();
@@ -103,6 +105,7 @@ const navSections: NavSection[] = [
items: [
{ key: 'documents', label: 'Documents settings', icon: 'bookmark-stack' },
{ key: 'editor', label: 'Editor settings', icon: 'editor' },
+ { key: 'styles', label: 'Styles injection', icon: 'styles' },
{ key: 'advanced', label: 'Advanced', icon: 'advanced' },
],
},
diff --git a/frontend/public/app-icons/styles.svg b/frontend/public/app-icons/styles.svg
new file mode 100644
index 00000000..94908ec4
--- /dev/null
+++ b/frontend/public/app-icons/styles.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg"viewBox="0 -960 960 960"><path d="M186-80q-54 0-80-22t-26-66q0-58 49-74t116-16h21v-56q0-34-1-55.5t-6-35.5q-5-14-11.5-19.5T230-430q-9 0-16.5 3t-12.5 8q-4 5-5 10.5t1 11.5q6 11 14 21.5t8 24.5q0 25-17.5 42.5T159-291q-25 0-42.5-17.5T99-351q0-27 12-44t32.5-27q20.5-10 47.5-14t58-4q85 0 118 30.5T400-302v147q0 19 4.5 28t15.5 9q12 0 19.5-18t9.5-56h11q-3 62-23.5 87T368-80q-43 0-67.5-13.5T269-134q-10 29-29.5 41.5T186-80Zm373 0q-20 0-32.5-16.5T522-132l102-269q7-17 22-28t34-11q19 0 34 11t22 28l102 269q8 19-4.5 35.5T801-80q-12 0-22-7t-15-19l-20-58H616l-20 58q-4 11-14 18.5T559-80Zm-324-29q13 0 22-20.5t9-49.5v-67q-26 0-38 15.5T216-180v11q0 36 4 48t15 12Zm407-125h77l-39-114-38 114Zm-37-285q-48 0-76.5-33.5T500-643q0-104 66-170.5T735-880q42 0 68 9.5t26 24.5q0 6-2 12t-7 11q-5 7-12.5 10t-15.5 1q-14-4-32-7t-33-3q-71 0-114 48t-43 127q0 22 8 46t36 24q11 0 21.5-5t18.5-14q17-18 31.5-60T712-758q2-13 10.5-18.5T746-782q18 0 27.5 9.5T779-749q-12 43-17.5 75t-5.5 58q0 20 5.5 29t16.5 9q11 0 21.5-8t29.5-30q2-3 15-7 8 0 12 6t4 17q0 28-32 54t-67 26q-26 0-44.5-14T691-574q-15 26-37 40.5T605-519Zm-485-1v-220q0-58 41-99t99-41q58 0 99 41t41 99v220h-80v-80H200v80h-80Zm80-160h120v-60q0-25-17.5-42.5T260-800q-25 0-42.5 17.5T200-740v60Z"/></svg>
\ No newline at end of file