Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): style collapsible blocks like the app

Elian Dorand810f37ba314
diff --git a/apps/client/src/index.ts b/apps/client/src/index.ts
index eb7862097e..64c0a80195 100644
--- a/apps/client/src/index.ts
+++ b/apps/client/src/index.ts
@@ -3,6 +3,7 @@
// which loads ahead of the stylesheets `loadStylesheets()` appends.
import "@triliumnext/ckeditor5/src/theme/adaptive_colors.css";
import "@triliumnext/ckeditor5/src/theme/admonitions.css";
+import "@triliumnext/ckeditor5/src/theme/collapsible_blocks.css";
import "@triliumnext/ckeditor5/src/theme/external_links.css";
import "@triliumnext/ckeditor5/src/theme/footnotes.css";
import "@triliumnext/ckeditor5/src/theme/headings.css";
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index e58d50dd19..50ab2564c7 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -2923,136 +2923,6 @@ iframe.print-iframe {
margin-bottom: 8px;
}
-/*
- * Collapsible blocks
- */
-
- /*
- * Shared styles for collapsible blocks (rendered as native HTML <details>/<summary>).
- * Used in both the editor and the read-only/published view via .ck-content.
- */
-
-.ck-content details.trilium-collapsible {
- --collapsible-block-background: var(--card-background-color);
- --collapsible-block-summary-background: var(--card-background-color);
- --collapsible-block-summary-delimiter-color: var(--main-background-color);
-
- --_border-radius: 8px;
- --_block-padding: .75rem;
- --_inline-padding: 1rem;
- --_margin-between-collapsibles: 3px;
- --_content-indent: 2rem;
- --_arrow-gap: 2rem;
-
- position: relative;
- overflow: hidden;
- isolation: isolate;
- margin: 1em 0;
- border-radius: var(--_border-radius);
- background: var(--collapsible-block-background);
- padding: var(--_block-padding) var(--_inline-padding) var(--_block-padding) var(--_content-indent);
-
- &:not(& + &):has(+ details.trilium-collapsible) {
- /* First collapsibile from the series */
- margin-bottom: var(--_margin-between-collapsibles);
- border-end-start-radius: 0;
- border-end-end-radius: 0;
- }
-
- & + &:has(+ details.trilium-collapsible) {
- /* Middle collapsibile blocks from the series */
- margin-bottom: var(--_margin-between-collapsibles);
- margin-top: 0;
- border-radius: 0;
- }
-
- & + &:not(:has(+ details.trilium-collapsible)) {
- /* The last collapsibile from the series */
- margin-top: 0;
- border-start-start-radius: 0;
- border-start-end-radius: 0;
- }
-
- > summary {
- position: relative;
- left: calc(0px - var(--_content-indent ) / 2);
- width: calc(100% + var(--_content-indent));
- padding-left: var(--_arrow-gap);
- cursor: pointer;
- font-weight: 500;
- outline: none;
- list-style: none; /* native marker replaced by the custom arrow below */
-
- &::-webkit-details-marker {
- display: none;
- }
-
- &::after {
- display: block;
- content: "";
- z-index: -1;
- position: absolute;
- top: calc(0px - (var(--_block-padding) + 1px));
- left: calc(0px - var(--_content-indent ) / 2);
- width: calc(100% + var(--_inline-padding) * 2 + 1px);
- height: calc(100% + var(--_block-padding) * 2 + 1px);
- background: var(--collapsible-block-summary-background);
- }
-
- &:hover::after {
- background: var(--card-background-hover-color);
- }
- }
-
- &[open] > summary {
- margin-bottom: calc(var(--_block-padding) * 2);
-
- &::after {
- border-bottom: 2px solid var(--collapsible-block-summary-delimiter-color);
- }
- }
-
- >*:last-child:not(summary) {
- margin-bottom: 0;
- }
-}
-
-/*
- * Custom arrow, shared by every view. In the editor it is a real <span> (inserted by the
- * editing downcast) because it needs click and keyboard handlers; elsewhere that span
- * doesn't exist — the arrow is deliberately not part of the saved HTML — so the data view
- * (read-only text notes, markdown preview) draws it on the summary instead and lets the
- * native <details> toggle do the work. Both share the geometry and the glyph below.
- */
-.ck-content details.trilium-collapsible > summary > .trilium-collapsible-arrow,
-.ck-content:not(.ck-editor__editable) details.trilium-collapsible > summary::before {
- position: absolute;
- left: 0;
- top: -0.05em;
- width: 1lh;
- height: 1lh;
- display: flex;
- justify-content: center;
- align-items: center;
- font-family: boxicons;
- cursor: pointer;
- user-select: none;
- /* Scaled rather than sized with font-size, so the box keeps the summary's line metrics
- * and the arrow stays centred on the first line of the title. */
- transform: scale(1.3);
- transition: transform 0.15s ease;
-}
-
-.ck-content details.trilium-collapsible > summary > .trilium-collapsible-arrow::before,
-.ck-content:not(.ck-editor__editable) details.trilium-collapsible > summary::before {
- content: "\ea50";
-}
-
-.ck-content details.trilium-collapsible[open] > summary > .trilium-collapsible-arrow,
-.ck-content:not(.ck-editor__editable) details.trilium-collapsible[open] > summary::before {
- transform: scale(1.3) rotate(90deg);
-}
-
/*
* Editor-only tweaks: summary acts like a regular editable text block, and the arrow is the
* only collapse affordance (clicking the summary text places a caret instead of toggling).
diff --git a/packages/ckeditor5/src/theme/collapsible.css b/packages/ckeditor5/src/theme/collapsible.css
index 0fe6206164..aee365fe57 100644
--- a/packages/ckeditor5/src/theme/collapsible.css
+++ b/packages/ckeditor5/src/theme/collapsible.css
@@ -1,7 +1,6 @@
-/* The shared styles for the collapsible blocks are located at
- * apps/client/src/stylesheets/style.css, so the styles are available even when
- * this plugin is not loaded yet.
+/* The shared styles for the collapsible blocks are in `collapsible_blocks.css`, which the client
+ * entry imports, so the styles are available even when this plugin is not loaded yet.
*
* Use only editor-specific styles in the current CSS file. */
diff --git a/packages/ckeditor5/src/theme/collapsible_blocks.css b/packages/ckeditor5/src/theme/collapsible_blocks.css
new file mode 100644
index 0000000000..fdb008cc33
--- /dev/null
+++ b/packages/ckeditor5/src/theme/collapsible_blocks.css
@@ -0,0 +1,126 @@
+/*
+ * Collapsible blocks (native <details>/<summary>) in note content, shared by the editor, read-only
+ * notes, the share theme and the print view. Editor-only rules are in `collapsible.css` and the
+ * client's `style.css`.
+ */
+
+.ck-content details.trilium-collapsible {
+ --collapsible-block-background: var(--card-background-color);
+ --collapsible-block-summary-background: var(--card-background-color);
+ --collapsible-block-summary-delimiter-color: var(--main-background-color);
+
+ --_border-radius: 8px;
+ --_block-padding: .75rem;
+ --_inline-padding: 1rem;
+ --_margin-between-collapsibles: 3px;
+ --_content-indent: 2rem;
+ --_arrow-gap: 2rem;
+
+ position: relative;
+ overflow: hidden;
+ isolation: isolate;
+ margin: 1em 0;
+ border-radius: var(--_border-radius);
+ background: var(--collapsible-block-background);
+ padding: var(--_block-padding) var(--_inline-padding) var(--_block-padding) var(--_content-indent);
+
+ &:not(& + &):has(+ details.trilium-collapsible) {
+ /* First collapsibile from the series */
+ margin-bottom: var(--_margin-between-collapsibles);
+ border-end-start-radius: 0;
+ border-end-end-radius: 0;
+ }
+
+ & + &:has(+ details.trilium-collapsible) {
+ /* Middle collapsibile blocks from the series */
+ margin-bottom: var(--_margin-between-collapsibles);
+ margin-top: 0;
+ border-radius: 0;
+ }
+
+ & + &:not(:has(+ details.trilium-collapsible)) {
+ /* The last collapsibile from the series */
+ margin-top: 0;
+ border-start-start-radius: 0;
+ border-start-end-radius: 0;
+ }
+
+ > summary {
+ position: relative;
+ left: calc(0px - var(--_content-indent ) / 2);
+ width: calc(100% + var(--_content-indent));
+ padding-left: var(--_arrow-gap);
+ cursor: pointer;
+ font-weight: 500;
+ outline: none;
+ list-style: none; /* native marker replaced by the custom arrow below */
+
+ &::-webkit-details-marker {
+ display: none;
+ }
+
+ &::after {
+ display: block;
+ content: "";
+ z-index: -1;
+ position: absolute;
+ top: calc(0px - (var(--_block-padding) + 1px));
+ left: calc(0px - var(--_content-indent ) / 2);
+ width: calc(100% + var(--_inline-padding) * 2 + 1px);
+ height: calc(100% + var(--_block-padding) * 2 + 1px);
+ background: var(--collapsible-block-summary-background);
+ }
+
+ &:hover::after {
+ background: var(--card-background-hover-color);
+ }
+ }
+
+ &[open] > summary {
+ margin-bottom: calc(var(--_block-padding) * 2);
+
+ &::after {
+ border-bottom: 2px solid var(--collapsible-block-summary-delimiter-color);
+ }
+ }
+
+ >*:last-child:not(summary) {
+ margin-bottom: 0;
+ }
+}
+
+/*
+ * Custom arrow, shared by every view. In the editor it is a real <span> (inserted by the
+ * editing downcast) because it needs click and keyboard handlers; elsewhere that span
+ * doesn't exist — the arrow is deliberately not part of the saved HTML — so the data view
+ * (read-only text notes, markdown preview) draws it on the summary instead and lets the
+ * native <details> toggle do the work. Both share the geometry and the glyph below.
+ */
+.ck-content details.trilium-collapsible > summary > .trilium-collapsible-arrow,
+.ck-content:not(.ck-editor__editable) details.trilium-collapsible > summary::before {
+ position: absolute;
+ left: 0;
+ top: -0.05em;
+ width: 1lh;
+ height: 1lh;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ font-family: boxicons;
+ cursor: pointer;
+ user-select: none;
+ /* Scaled rather than sized with font-size, so the box keeps the summary's line metrics
+ * and the arrow stays centred on the first line of the title. */
+ transform: scale(1.3);
+ transition: transform 0.15s ease;
+}
+
+.ck-content details.trilium-collapsible > summary > .trilium-collapsible-arrow::before,
+.ck-content:not(.ck-editor__editable) details.trilium-collapsible > summary::before {
+ content: "\ea50";
+}
+
+.ck-content details.trilium-collapsible[open] > summary > .trilium-collapsible-arrow,
+.ck-content:not(.ck-editor__editable) details.trilium-collapsible[open] > summary::before {
+ transform: scale(1.3) rotate(90deg);
+}
diff --git a/packages/share-theme/src/base.css b/packages/share-theme/src/base.css
index d1b2a0f575..c950d90aa2 100644
--- a/packages/share-theme/src/base.css
+++ b/packages/share-theme/src/base.css
@@ -125,6 +125,11 @@ html.theme-dark {
color-scheme: dark;
}
+/* The page background under the name the content styles shared with the app read it by. */
+:root {
+ --main-background-color: var(--background-primary);
+}
+
body {
background: var(--background-primary);
font-family: "Inter", system-ui, sans-serif;
diff --git a/packages/share-theme/src/index.ts b/packages/share-theme/src/index.ts
index dc66baf2eb..17a7a259cd 100644
--- a/packages/share-theme/src/index.ts
+++ b/packages/share-theme/src/index.ts
@@ -22,6 +22,7 @@ import "virtual:code-themes.css";
import "@triliumnext/ckeditor5/src/theme/ck-content.css";
import "@triliumnext/ckeditor5/src/theme/tabs.css";
import "@triliumnext/ckeditor5/src/theme/multicolumn.css";
+import "@triliumnext/ckeditor5/src/theme/collapsible_blocks.css";
import "@triliumnext/ckeditor5/src/theme/todo_lists.css";
import { applyTabs, revealFragment } from "@triliumnext/ckeditor5/src/plugins/tabs/tabs_read_only.js";