Skip to content

Build your personal knowledge base with Trilium Notes

style/collapsible blocks: make the style available even when the plugin is not loaded

Adorian Doran7d2fcf6ceef6
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 333713d90f..e69d67e1d1 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -3033,6 +3033,204 @@ iframe.print-iframe {
}
}
+/*
+ * 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).
+ */
+
+.ck-editor__editable details.trilium-collapsible {
+
+ .ck-placeholder::before {
+ opacity: 0.5;
+ }
+
+ /* Body-paragraph placeholder ("Content") is registered on the first body
+ * block. Hide it whenever the body has more than one block — the hint is
+ * only useful when the body is a single empty <p>. The body blocks live in
+ * the editing-only `.trilium-collapsible-content` wrapper, so `:has(> :nth-child(2))`
+ * matches a wrapper with 2+ body children; `:not(:last-child)` would only hide
+ * the placeholder on non-last paragraphs, leaving the last one (e.g. the
+ * original empty body after Enter-in-summary) still visible. */
+ .trilium-collapsible-content:has(> :nth-child(2)) > p.ck-placeholder::before {
+ display: none;
+ }
+
+ /* The shared `> *:last-child:not(summary)` rule now lands on the content
+ * wrapper (which has no margin of its own); zero the wrapper's last body
+ * block instead so the collapsible keeps its tight bottom padding. */
+ .trilium-collapsible-content > *:last-child {
+ margin-bottom: 0;
+ }
+
+ > summary {
+ cursor: text;
+ padding-right: calc(var(--_inline-padding) + 1lh); /* extra space for the handle on the right */
+
+ /* Block selection handle (mirror of the table widget's drag handle).
+ * Click selects the whole <details>; movement uses Alt+↑/↓ from there.
+ * Sits in the details' top-left padding area, visible on hover. */
+ > .trilium-collapsible-handle {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ right: var(--_inline-padding);
+ z-index: 1000;
+ width: 1lh;
+ height: 1lh;
+ cursor: default;
+ opacity: 0;
+ transition: opacity 0.15s ease;
+
+ &::before {
+ position: absolute;
+ inset: 0;
+ content: "\ec6c";
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ font-size: 1em;
+ font-family: boxicons;
+ color: var(--muted-text-color, currentColor);
+ }
+ }
+ }
+
+ &:hover > summary > .trilium-collapsible-handle,
+ &:focus-within > summary > .trilium-collapsible-handle {
+ opacity: 1;
+ }
+}
+
/* Unknown state: orange outline */
.tn-unknown-task-state .todo-list__label input[type="checkbox"] {
outline: 3px solid var(--task-checkbox-unknown-state-color);
diff --git a/packages/ckeditor5-collapsible/theme/collapsible.css b/packages/ckeditor5-collapsible/theme/collapsible.css
index 483745fd7e..947f200aa6 100644
--- a/packages/ckeditor5-collapsible/theme/collapsible.css
+++ b/packages/ckeditor5-collapsible/theme/collapsible.css
@@ -1,196 +1,9 @@
-/*
- * 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).
- */
-
-.ck-editor__editable details.trilium-collapsible {
-
- .ck-placeholder::before {
- opacity: 0.5;
- }
-
- /* Body-paragraph placeholder ("Content") is registered on the first body
- * block. Hide it whenever the body has more than one block — the hint is
- * only useful when the body is a single empty <p>. The body blocks live in
- * the editing-only `.trilium-collapsible-content` wrapper, so `:has(> :nth-child(2))`
- * matches a wrapper with 2+ body children; `:not(:last-child)` would only hide
- * the placeholder on non-last paragraphs, leaving the last one (e.g. the
- * original empty body after Enter-in-summary) still visible. */
- .trilium-collapsible-content:has(> :nth-child(2)) > p.ck-placeholder::before {
- display: none;
- }
-
- /* The shared `> *:last-child:not(summary)` rule now lands on the content
- * wrapper (which has no margin of its own); zero the wrapper's last body
- * block instead so the collapsible keeps its tight bottom padding. */
- .trilium-collapsible-content > *:last-child {
- margin-bottom: 0;
- }
-
- > summary {
- cursor: text;
- padding-right: calc(var(--_inline-padding) + 1lh); /* extra space for the handle on the right */
-
- /* Block selection handle (mirror of the table widget's drag handle).
- * Click selects the whole <details>; movement uses Alt+↑/↓ from there.
- * Sits in the details' top-left padding area, visible on hover. */
- > .trilium-collapsible-handle {
- position: absolute;
- top: 0;
- bottom: 0;
- right: var(--_inline-padding);
- z-index: 1000;
- width: 1lh;
- height: 1lh;
- cursor: default;
- opacity: 0;
- transition: opacity 0.15s ease;
-
- &::before {
- position: absolute;
- inset: 0;
- content: "\ec6c";
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 1em;
- font-family: boxicons;
- color: var(--muted-text-color, currentColor);
- }
- }
- }
-
- &:hover > summary > .trilium-collapsible-handle,
- &:focus-within > summary > .trilium-collapsible-handle {
- opacity: 1;
- }
-}
+/* 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.
+ *
+ * Use only editor-specific styles in the current CSS file. */
/*
* Drop indicator drawn while the user drags a collapsible by its handle.