Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): style code blocks like the app's default theme

Elian Doran5878d78f083e
diff --git a/packages/share-theme/src/base.css b/packages/share-theme/src/base.css
index 24b08f1fd1..29939386f0 100644
--- a/packages/share-theme/src/base.css
+++ b/packages/share-theme/src/base.css
@@ -30,6 +30,8 @@ html.theme-light {
--link-hover-background: #3c7fa017;
--link-focus-outline-color: #00000063;
--text-menu-active: var(--background-secondary);
+ /* The code block shadow of `theme-next-light.css`. */
+ --code-block-box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1), 0px 0px 2px rgba(0, 0, 0, 0.2);
/* The tree item colors of `theme-next-light.css`. */
--tree-item-hover-background: rgba(0, 0, 0, 0.032);
--tree-item-active-background: #FFFFFF;
@@ -68,6 +70,8 @@ html.theme-dark {
--link-hover-background: #75c2e324;
--link-focus-outline-color: #ffffff57;
--text-menu-active: var(--background-secondary);
+ /* The code block shadow of `theme-next-dark.css`. */
+ --code-block-box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
/* The tree item colors of `theme-next-dark.css`. */
--tree-item-hover-background: #ffffff0d;
--tree-item-active-background: #ffffff25;
diff --git a/packages/share-theme/src/content/content.css b/packages/share-theme/src/content/content.css
index 91f26aa8a3..906daa8994 100644
--- a/packages/share-theme/src/content/content.css
+++ b/packages/share-theme/src/content/content.css
@@ -22,33 +22,38 @@ iframe.pdf-view {
height: 800px;
}
-.ck-content code,
-.ck-content pre {
+.ck-content code:not(pre code) {
color: var(--text-primary);
background-color: var(--background-secondary);
border: 1px solid var(--background-active);
border-radius: 6px;
-}
-
-/* Only a code block preserves the source's own line breaks. Inline code used to inherit this from
- * the rule above, which kept a long snippet on one line and pushed the page sideways on mobile. */
-.ck-content pre {
- white-space: pre;
-}
-
-.ck-content code:not(pre code) {
padding: 2px 5px;
overflow-wrap: break-word;
}
-.ck-content pre code {
+/* The code blocks of the app's default theme, `theme-next/notes/text.css`. `:root` outranks
+ `ckeditor5-content.css`, which `index.ts` imports after this file. */
+:root .ck-content pre {
+ position: relative;
+ min-width: unset;
+ margin-top: 2px;
border: 0;
+ border-radius: 6px;
+ padding: 1em;
+ color: var(--text-primary);
+ background-color: var(--background-secondary);
+ box-shadow: var(--code-block-box-shadow);
+ white-space: pre;
}
-.ck-content pre {
+:root .ck-content pre:has(> code) {
+ padding: 0;
+}
+
+:root .ck-content pre code {
+ display: block;
+ padding: 1em;
overflow: auto;
- position: relative;
- min-width: unset !important;
}
.ck-content pre .copy-button {