Skip to content

Build your personal knowledge base with Trilium Notes

fix(theme): make the inline code style apply again

Elian Doran44c9fe7fc584
diff --git a/apps/client/src/print.css b/apps/client/src/print.css
index b340e0e101..54b8a1d212 100644
--- a/apps/client/src/print.css
+++ b/apps/client/src/print.css
@@ -171,6 +171,21 @@ body[data-note-type="text"] .ck-content {
}
}
+/* #region Inline code */
+/* The print window loads neither style.css nor a theme (see loadStylesheets() in index.ts), so this
+ * repeats the on-screen rule with print-safe values instead of reading --inline-code-*. Printers
+ * drop backgrounds by default, which leaves the border as the only thing setting an inline snippet
+ * apart from the prose around it — so it has to survive greyscale on its own. */
+.ck-content code:not(pre code) {
+ padding: 0.1em 0.35em;
+ border: 1px solid #999;
+ border-radius: 3pt;
+ background-color: transparent;
+ font-size: 0.9em;
+ overflow-wrap: break-word;
+}
+/* #endregion */
+
/* #region Footnotes */
.footnote-reference a,
.footnote-back-link a {
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 39e1d217a1..3dd3fdeb07 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -1075,6 +1075,33 @@ code {
color: inherit !important;
}
+/*
+ * Inline code — a `code` that is not the body of a code block.
+ *
+ * CKEditor ships its own `.ck-content code` rule with a hardcoded grey, which ignores the theme
+ * entirely. The rule below overrides it (one class more specific) for every surface that renders
+ * note content: the editable and read-only text notes, doc notes and the print sheet.
+ *
+ * The values are theme-tunable; the defaults here are a translucent neutral grey so they hold up
+ * on a light and a dark background alike, which is what the legacy themes fall back to.
+ */
+:where(:root) {
+ --inline-code-background-color: rgba(128, 128, 128, 0.18);
+ --inline-code-border-color: rgba(128, 128, 128, 0.28);
+ --inline-code-hover-background-color: rgba(128, 128, 128, 0.3);
+}
+
+.ck-content code:not(pre code) {
+ padding: 0.1em 0.35em;
+ border: 1px solid var(--inline-code-border-color);
+ border-radius: 5px;
+ background-color: var(--inline-code-background-color);
+ /* Monospace runs visually larger than the surrounding prose at the same nominal size. */
+ font-size: 0.9em;
+ /* A long path or identifier must wrap rather than push the paragraph past the note width. */
+ overflow-wrap: break-word;
+}
+
.animated {
animation-duration: 1s;
animation-fill-mode: both;
diff --git a/apps/client/src/stylesheets/theme-next-dark.css b/apps/client/src/stylesheets/theme-next-dark.css
index deabb0dbb1..99fd7e9fa8 100644
--- a/apps/client/src/stylesheets/theme-next-dark.css
+++ b/apps/client/src/stylesheets/theme-next-dark.css
@@ -293,6 +293,10 @@
--card-border-color: transparent;
--card-box-shadow: none;
+ --inline-code-background-color: rgba(255, 255, 255, 0.08);
+ --inline-code-border-color: rgba(255, 255, 255, 0.14);
+ --inline-code-hover-background-color: rgba(255, 255, 255, 0.15);
+
--calendar-color: var(--menu-text-color);
--calendar-weekday-labels-color: var(--muted-text-color);
--calendar-day-hover-color: var(--hover-item-text-color);
diff --git a/apps/client/src/stylesheets/theme-next-light.css b/apps/client/src/stylesheets/theme-next-light.css
index bc55309f82..13b0d842fe 100644
--- a/apps/client/src/stylesheets/theme-next-light.css
+++ b/apps/client/src/stylesheets/theme-next-light.css
@@ -292,6 +292,10 @@
--card-shadow-color: rgba(0, 0, 0, 0.1);
--card-box-shadow: none;
+ --inline-code-background-color: rgba(0, 0, 0, 0.05);
+ --inline-code-border-color: rgba(0, 0, 0, 0.11);
+ --inline-code-hover-background-color: rgba(0, 0, 0, 0.1);
+
--calendar-color: var(--menu-text-color);
--calendar-weekday-labels-color: var(--muted-text-color);
--calendar-day-hover-color: var(--hover-item-text-color);
diff --git a/apps/client/src/stylesheets/theme-next/notes/text.css b/apps/client/src/stylesheets/theme-next/notes/text.css
index 33514de52e..d9f2a2686e 100644
--- a/apps/client/src/stylesheets/theme-next/notes/text.css
+++ b/apps/client/src/stylesheets/theme-next/notes/text.css
@@ -782,15 +782,6 @@ html .note-detail-editable-text > :not(figure, .include-note, hr):first-child {
opacity: 1;
}
-@media (screen) {
- .ck-content p code {
- border: 1px solid var(--card-border-color);
- box-shadow: var(--card-box-shadow);
- border-radius: 6px;
- background-color: var(--card-background-color);
- }
-}
-
.ck-content:not(.word-wrap) pre code {
white-space: pre;
}
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css
index cbc5c064bf..1437f9a8cc 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css
@@ -263,12 +263,16 @@ body.background-effects.theme-supports-background-effects .llm-chat-message-user
margin: 0.25em 0;
}
-.llm-chat-markdown code {
- background: var(--accented-background-color);
- padding: 0.15em 0.4em;
- border-radius: 4px;
+/* Same treatment as inline code in a note (style.css) — a chat answer and the note it ends up in
+ * should not render the same snippet differently. Translucent, so it composites over the bubble. */
+.llm-chat-markdown code:not(pre code) {
+ background: var(--inline-code-background-color);
+ border: 1px solid var(--inline-code-border-color);
+ padding: 0.1em 0.35em;
+ border-radius: 5px;
font-family: var(--monospace-font-family, monospace);
font-size: 0.9em;
+ overflow-wrap: break-word;
}
.llm-chat-markdown pre {
diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.css b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.css
index fa79b552a4..cf99720acd 100644
--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.css
+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.css
@@ -90,5 +90,5 @@ body.mobile .note-detail-readonly-text {
}
.note-detail-readonly-text-content code.copyable-inline-code:hover {
- background-color: var(--accented-background-color);
+ background-color: var(--inline-code-hover-background-color);
}
diff --git a/packages/share-theme/src/styles/content.css b/packages/share-theme/src/styles/content.css
index c0351e78cc..97407ed7f3 100644
--- a/packages/share-theme/src/styles/content.css
+++ b/packages/share-theme/src/styles/content.css
@@ -11,11 +11,17 @@
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 {
+.ck-content code:not(pre code) {
padding: 2px 5px;
+ overflow-wrap: break-word;
}
.ck-content pre code {