Skip to content

Build your personal knowledge base with Trilium Notes

feat(markdown): don't auto-highlight

Elian Doran1ee4aef2b124
diff --git a/apps/client/src/widgets/type_widgets/code/Markdown.tsx b/apps/client/src/widgets/type_widgets/code/Markdown.tsx
index 05a27ad511..41fb888755 100644
--- a/apps/client/src/widgets/type_widgets/code/Markdown.tsx
+++ b/apps/client/src/widgets/type_widgets/code/Markdown.tsx
@@ -1,9 +1,9 @@
import "./Markdown.css";
import VanillaCodeMirror from "@triliumnext/codemirror";
-import { renderToHtml } from "@triliumnext/commons";
+import { CustomMarkdownRenderer, renderToHtml } from "@triliumnext/commons";
import DOMPurify from "dompurify";
-import { Marked } from "marked";
+import { Marked, type Tokens } from "marked";
import { createContext } from "preact";
import { useContext, useEffect, useMemo, useState } from "preact/hooks";
@@ -13,6 +13,23 @@ import { TypeWidgetProps } from "../type_widget";
const marked = new Marked({ breaks: true, gfm: true });
+/**
+ * The default {@link CustomMarkdownRenderer} falls back to
+ * `language-text-x-trilium-auto` on unlabeled fences, which drives
+ * `syntax_highlight.ts` into `highlightAuto` — that dynamic-imports every hljs
+ * language bundle on first render and runs detection on each block, which is
+ * both slow and often wrong on short snippets. For the live preview we instead
+ * emit unlabeled fences without a `language-` class so the highlighter skips
+ * them entirely.
+ */
+class MarkdownPreviewRenderer extends CustomMarkdownRenderer {
+ override code(token: Tokens.Code): string {
+ const html = super.code(token);
+ if (token.lang) return html;
+ return html.replace('<code class="language-text-x-trilium-auto">', `<code class="language-text-plain">`);
+ }
+}
+
interface MarkdownContextValue {
html: string;
setEditorView: (view: VanillaCodeMirror | null) => void;
@@ -175,7 +192,8 @@ export function renderWithSourceLines(src: string): string {
const html = renderToHtml(src, "", {
sanitize: (h) => DOMPurify.sanitize(h),
wikiLink: { formatHref: (id) => `#root/${id}` },
- demoteH1: false
+ demoteH1: false,
+ renderer: new MarkdownPreviewRenderer({ async: false })
});
if (!html) return "";
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html
index c6ab832bdb..f25684284a 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html
@@ -52,8 +52,7 @@
<ul>
<li>Type a few words to filter between commands.</li>
<li>Use the up and down arrows on the keyboard or the mouse to select a command.</li>
- <li
- >Press <kbd>Enter</kbd> to execute the command.</li>
+ <li>Press <kbd>Enter</kbd> to execute the command.</li>
</ul>
<p>To exit the command palette:</p>
<ul>
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Printing & Exporting as PDF.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Printing & Exporting as PDF.html
index 331753192b..f945451b0f 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Printing & Exporting as PDF.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Printing & Exporting as PDF.html
@@ -5,7 +5,7 @@
</figure>
<p>Trilium allows printing notes to a real printer, or generating a structured
PDF for a single note or for multiple notes through&nbsp;<a class="reference-link"
- href="#root/pOsGYCXsbNQG/_help_GTwFsgaA0lCt">Collections</a>.</p>
+ href="#root/_help_GTwFsgaA0lCt">Collections</a>.</p>
<p>Note that not all note types are printable as of now. We do plan to increase
the coverage of supported note types in the future.</p>
<p>Printing and exporting as PDF are not perfect. Due to technical limitations,
@@ -20,10 +20,10 @@
<p>On the desktop application of Trilium it is possible to export a note
as PDF. To print a note:</p>
<ul>
- <li>Press the menu button in the&nbsp;<a class="reference-link" href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_8YBEPzcpUgxw">Note buttons</a>&nbsp;area
+ <li>Press the menu button in the&nbsp;<a class="reference-link" href="#root/_help_8YBEPzcpUgxw">Note buttons</a>&nbsp;area
and select <em>Print note</em>.</li>
- <li>Alternatively, printing can be triggered from a <a href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/_help_A9Oc6YKKc65v">keyboard shortcut</a> (unassigned
- by default) or through the <a href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/wArbEsdSae6g/_help_F1r9QtzQLZqm">command palette</a>.</li>
+ <li>Alternatively, printing can be triggered from a <a href="#root/_help_A9Oc6YKKc65v">keyboard shortcut</a> (unassigned
+ by default) or through the <a href="#root/_help_F1r9QtzQLZqm">command palette</a>.</li>
</ul>
<p>This will trigger the print preview screen next.</p>
<h3>Print preview &amp; print options</h3>
@@ -32,11 +32,9 @@
<li>
<p>The printer to use</p>
<ul>
- <li>
- <p><em>Save as PDF</em> generates a PDF that is structured (maintains a table
- of contents, keeps the text selectable). Prefer this over other virtual
- PDF printers that ship with the operating system.</p>
- </li>
+ <li><em>Save as PDF</em> generates a PDF that is structured (maintains a table
+ of contents, keeps the text selectable). Prefer this over other virtual
+ PDF printers that ship with the operating system.</li>
</ul>
</li>
<li>
@@ -71,7 +69,7 @@
spellcheck="false">#printScale</code>, <code spellcheck="false">#printMargins</code>).</p>
<p>This means that the print settings will be restored when printing the
same note. There are no default settings that can be configured for all
- the notes, but this can be achieved via <a href="#root/pOsGYCXsbNQG/tC7s2alapj8V/zEY4DaJG4YT5/_help_bwZpz2ajCEwO">inheritable attributes</a>.</p>
+ the notes, but this can be achieved via <a href="#root/_help_bwZpz2ajCEwO">inheritable attributes</a>.</p>
</aside>
<h2>Printing on the browser</h2>
<p>This feature allows printing of notes. It works on both the desktop client,
@@ -116,8 +114,7 @@
<ol>
<li>First create a collection.</li>
<li>Configure it to use&nbsp;<a class="reference-link" href="#root/_help_mULW0Q3VojwY">List View</a>.</li>
- <li
- >Print the collection note normally.</li>
+ <li>Print the collection note normally.</li>
</ol>
<p>The resulting collection will contain all the children of the collection,
while maintaining the hierarchy.</p>
@@ -134,9 +131,9 @@
href="#root/_help_4TIF1oA4VQRO">Options</a>&nbsp;and assigning a key combination
for:</p>
<ul>
- <li class="ck-list-marker-italic"><em>Print Active Note</em>
+ <li><em>Print Active Note</em>
</li>
- <li class="ck-list-marker-italic"><em>Export Active Note as PDF</em>
+ <li><em>Export Active Note as PDF</em>
</li>
</ul>
<h2>Constraints &amp; limitations</h2>
@@ -212,13 +209,12 @@
<p>To remark:</p>
<ul>
<li>Multiple CSS notes can be add by using multiple <code spellcheck="false">~printCss</code> relations.</li>
- <li
- >If the note pointing to the <code spellcheck="false">printCss</code> doesn't
+ <li>If the note pointing to the <code spellcheck="false">printCss</code> doesn't
have the right note type or mime type, it will be ignored.</li>
- <li>If migrating from a previous version where&nbsp;<a class="reference-link"
- href="#root/_help_AlhDUqhENtH7">Custom app-wide CSS</a>, there's no need for
- <code
- spellcheck="false">@media print {</code> since the style-sheet is used only for printing.</li>
+ <li>If migrating from a previous version where&nbsp;<a class="reference-link"
+ href="#root/_help_AlhDUqhENtH7">Custom app-wide CSS</a>, there's no need for
+ <code
+ spellcheck="false">@media print {</code> since the style-sheet is used only for printing.</li>
</ul>
<h2>Under the hood</h2>
<p>Both printing and exporting as PDF use the same mechanism: a note is rendered
@@ -232,13 +228,7 @@
understand why a particular note doesn't render well. The mechanism for
rendering is similar to the one used in&nbsp;<a class="reference-link"
href="#root/_help_0ESUbbAxVnoK">Note List</a>.</p>
-<ol class="footnote-section footnotes"
-data-footnote-section="" role="doc-endnotes">
- <li class="footnote-item" data-footnote-item="" data-footnote-index="1"
- data-footnote-id="sr779u3zm6" role="doc-endnote" id="fnsr779u3zm6"><span class="footnote-back-link" data-footnote-back-link="" data-footnote-id="sr779u3zm6"><sup><strong><a href="#fnrefsr779u3zm6">^</a></strong></sup></span>
- <div
- class="footnote-content" data-footnote-content="">
- <p>&nbsp;</p>
- </div>
+<ol>
+ <li><sup><strong><a href="#fnrefsr779u3zm6">^</a></strong></sup>
</li>
</ol>
\ No newline at end of file
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Read-Only Notes.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Read-Only Notes.html
index 8fff5ceb53..6536535e16 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Read-Only Notes.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Read-Only Notes.html
@@ -54,8 +54,7 @@
hide the Mermaid source code and display the diagram preview in full-size.
In this case, the read-only mode can be easily toggled on or off via a
dedicated button in the&nbsp;<a class="reference-link" href="#root/_help_XpOYSgsLkTJy">Floating buttons</a>&nbsp;area.</li>
- <li
- ><a class="reference-link" href="#root/_help_81SGnPGMk7Xc">Geo Map</a>&nbsp;will
+ <li><a class="reference-link" href="#root/_help_81SGnPGMk7Xc">Geo Map</a>&nbsp;will
disallow all interaction that would otherwise change the map (dragging
notes, adding new items).</li>
</ul>
\ No newline at end of file
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Code.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Code.html
index a658cdc82a..3702117519 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Code.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Code.html
@@ -4,16 +4,15 @@
<p>This can be useful for a few things:</p>
<ul>
<li>computer programmers can store code snippets as notes with syntax highlighting</li>
- <li
- >JavaScript code notes can be executed inside Trilium for some extra functionality
+ <li>JavaScript code notes can be executed inside Trilium for some extra functionality
<ul>
<li>we call such JavaScript code notes "scripts" - see&nbsp;<a class="reference-link"
href="#root/_help_CdNpE2pqjmI6">Scripting</a>
</li>
</ul>
- </li>
- <li>JSON, XML etc. can be used as storage for structured data (typically used
- in conjunction with scripting)</li>
+ </li>
+ <li>JSON, XML etc. can be used as storage for structured data (typically used
+ in conjunction with scripting)</li>
</ul>
<p>For shorter snippets of code that can be embedded in&nbsp;<a href="#root/_help_iPIMuisry3hd">Text</a>&nbsp;notes,
see&nbsp;<a href="#root/_help_QxEyIjRBizuC">Code blocks</a>.</p>
@@ -41,26 +40,24 @@
<h2>Word wrap</h2>
<p>Long lines can be displayed on multiple lines:</p>
<ul>
- <li>Globally for all code notes, from&nbsp;<a class="reference-link" href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_4TIF1oA4VQRO">Options</a>&nbsp;→ <em>Code Notes.</em>
+ <li>Globally for all code notes, from&nbsp;<a class="reference-link" href="#root/_help_4TIF1oA4VQRO">Options</a>&nbsp;→ <em>Code Notes.</em>
</li>
<li>For a particular note, by going to the menu in&nbsp;<a class="reference-link"
- href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_8YBEPzcpUgxw">Note buttons</a>&nbsp;and
- selecting <em>Word wrap</em> and selecting the appropriate option:
+ href="#root/_help_8YBEPzcpUgxw">Note buttons</a>&nbsp;and selecting <em>Word wrap</em> and
+ selecting the appropriate option:
<ul>
<li><em>Auto</em>, to respect the global word wrap for code notes.</li>
- <li
- ><em>On</em> or <em>Off</em>, to change the state of the word wrap for this
+ <li><em>On</em> or <em>Off</em>, to change the state of the word wrap for this
note regardless of the global option.</li>
- </ul>
+ </ul>
</li>
</ul>
<h2>Adjusting options using the status bar</h2>
<aside class="admonition note">
<p>This feature is only available for the&nbsp;<a class="reference-link"
- href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_IjZS7iK5EXtb">New Layout</a>.
- For the old layout, the tab width can be adjusted at note level using the
- <code
- spellcheck="false">#tabWidth</code>attribute, but re-indentation is not available.</p>
+ href="#root/_help_IjZS7iK5EXtb">New Layout</a>. For the old layout, the tab width
+ can be adjusted at note level using the <code spellcheck="false">#tabWidth</code> attribute,
+ but re-indentation is not available.</p>
</aside>
<p>The status bar at the bottom of the editor shows the current indentation
settings and language. Clicking on the indentation indicator opens a menu
@@ -70,8 +67,7 @@
override is active, a "Reset to default" option appears.</li>
<li><strong>Display Width</strong> — choose from preset widths (1, 2, 3, 4,
6, 8). Changes are saved as a per-note <code spellcheck="false">#tabWidth</code> label.</li>
- <li
- ><strong>Re-indent Content To</strong> — convert existing indentation to
+ <li><strong>Re-indent Content To</strong> — convert existing indentation to
a different style. For example, re-indent a file from 4 spaces to 2 spaces,
or from spaces to tabs. This rewrites the leading whitespace on every line
while preserving alignment remainders.</li>
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Markdown.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Markdown.html
index be12436732..728e0a74dd 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Markdown.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Markdown.html
@@ -32,46 +32,39 @@
<p>The following features are supported by Trilium's Markdown format and
will show up in the preview pane:</p>
<ul>
- <li>
- <p>All standard and GitHub-flavored syntax (basic formatting, tables, blockquotes)</p>
- </li>
- <li>
- <p>Code blocks with syntax highlight (e.g. <code spellcheck="false">```js</code>)
- and automatic syntax highlight</p>
- </li>
- <li>
- <p><a class="reference-link" href="#root/_help_NwBbFdNZ9h7O">Block quotes &amp; admonitions</a>
- </p>
- </li>
- <li>
- <p><a class="reference-link" href="#root/_help_YfYAtQBcfo5V">Math Equations</a>
- </p>
- </li>
- <li>
- <p><a class="reference-link" href="#root/_help_s1aBHPd79XYj">Mermaid Diagrams</a>&nbsp;using
- <code
- spellcheck="false">```mermaid</code>
- </p>
- </li>
- <li>
- <p><a class="reference-link" href="#root/_help_nBAXQFj20hS1">Include Note</a>&nbsp;(no
- builtin Markdown syntax, but HTML syntax works just fine):</p><pre><code class="language-text-x-trilium-auto">&lt;section class="include-note" data-note-id="vJDjQm0VK8Na" data-box-size="expandable"&gt;
+ <li>All standard and GitHub-flavored syntax (basic formatting, tables, blockquotes)</li>
+ <li
+ >Code blocks with syntax highlight. Note that the language must be specified
+ for syntax highlight to apply (e.g. <code spellcheck="false">```js</code>).</li>
+ <li
+ ><a class="reference-link" href="#root/_help_NwBbFdNZ9h7O">Block quotes &amp; admonitions</a>
+ </li>
+ <li><a class="reference-link" href="#root/_help_YfYAtQBcfo5V">Math Equations</a>
+ </li>
+ <li><a class="reference-link" href="#root/_help_s1aBHPd79XYj">Mermaid Diagrams</a>&nbsp;using
+ <code
+ spellcheck="false">```mermaid</code>
+ </li>
+ <li>
+ <p><a class="reference-link" href="#root/_help_nBAXQFj20hS1">Include Note</a>&nbsp;(no
+ builtin Markdown syntax, but HTML syntax works just fine):</p><pre><code class="language-text-x-trilium-auto">&lt;section class="include-note" data-note-id="vJDjQm0VK8Na" data-box-size="expandable"&gt;
&amp;nbsp;
&lt;/section&gt;n</code></pre>
- </li>
- <li>
- <p><a class="reference-link" href="#root/_help_hrZ1D00cLbal">Internal (reference) links</a>&nbsp;via
- its HTML syntax, or through a <em>Wikilinks</em>-like format (only&nbsp;
- <a
- class="reference-link" href="#root/_help_m1lbrzyKDaRB">Note ID</a>):</p><pre><code class="language-text-x-trilium-auto">[[Hg8TS5ZOxti6]]</code></pre>
- </li>
+ </li>
+ <li>
+ <p><a class="reference-link" href="#root/_help_hrZ1D00cLbal">Internal (reference) links</a>&nbsp;via
+ its HTML syntax, or through a <em>Wikilinks</em>-like format (only&nbsp;
+ <a
+ class="reference-link" href="#root/_help_m1lbrzyKDaRB">Note ID</a>):</p><pre><code class="language-text-x-trilium-auto">[[Hg8TS5ZOxti6]]</code></pre>
+ </li>
</ul>
<h2>Creating Markdown notes</h2>
<p>There are two ways to create a Markdown note:</p>
<ol>
<li>Create a new note (e.g. in the&nbsp;<a class="reference-link" href="#root/_help_oPVyFC7WL2Lp">Note Tree</a>)
and select the type <em>Markdown</em>, just like all the other note types.</li>
- <li>Create a note of type&nbsp;<a class="reference-link" href="#root/_help_6f9hih2hXXZk">Code</a>&nbsp;and
+ <li
+ >Create a note of type&nbsp;<a class="reference-link" href="#root/_help_6f9hih2hXXZk">Code</a>&nbsp;and
select as the language either <em>Markdown</em> or <em>GitHub-Flavored Markdown</em>.
This maintains compatibility with your existing notes prior to the introduction
of this feature.</li>
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Developer-specific formatting/Code blocks.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Developer-specific formatting/Code blocks.html
index d159034940..33cd1f2b65 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Developer-specific formatting/Code blocks.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Developer-specific formatting/Code blocks.html
@@ -62,10 +62,9 @@
<ul>
<li>It is possible to disable the syntax highlighting for all the notes by
selecting “No syntax highlighting” in the “Color scheme” option.</li>
- <li
- >Word wrapping is disabled by default, but can be configured from the same
+ <li>Word wrapping is disabled by default, but can be configured from the same
section.</li>
- <li>The tab width can also be adjusted from Options.</li>
+ <li>The tab width can also be adjusted from Options.</li>
</ul>
<aside class="admonition note">
<p><strong>Context regarding syntax highlighting</strong>
diff --git a/docs/Developer Guide/Developer Guide/Documentation.md b/docs/Developer Guide/Developer Guide/Documentation.md
index 72b644ea00..368acc4d18 100644
--- a/docs/Developer Guide/Developer Guide/Documentation.md
+++ b/docs/Developer Guide/Developer Guide/Documentation.md
@@ -1,5 +1,5 @@
# Documentation
-There are multiple types of documentation for Trilium:<img class="image-style-align-right" src="api/images/HWpeC3cnbb1K/Documentation_image.png" width="205" height="162">
+There are multiple types of documentation for Trilium:<img class="image-style-align-right" src="api/images/gM2IjyH6AzAQ/Documentation_image.png" width="205" height="162">
* The _User Guide_ represents the user-facing documentation. This documentation can be browsed by users directly from within Trilium, by pressing <kbd>F1</kbd>.
* The _Developer's Guide_ represents a set of Markdown documents that present the internals of Trilium, for developers.
diff --git a/docs/User Guide/!!!meta.json b/docs/User Guide/!!!meta.json
index 36deaaf658..ca9f272320 100644
--- a/docs/User Guide/!!!meta.json
+++ b/docs/User Guide/!!!meta.json
@@ -4680,149 +4680,149 @@
{
"type": "relation",
"name": "internalLink",
- "value": "wy8So3yZZlH9",
+ "value": "GTwFsgaA0lCt",
"isInheritable": false,
"position": 10
},
{
"type": "relation",
"name": "internalLink",
- "value": "CohkqWQC1iBv",
+ "value": "8YBEPzcpUgxw",
"isInheritable": false,
"position": 20
},
{
"type": "relation",
"name": "internalLink",
- "value": "GTwFsgaA0lCt",
+ "value": "A9Oc6YKKc65v",
+ "isInheritable": false,
+ "position": 30
+ },
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "F1r9QtzQLZqm",
"isInheritable": false,
"position": 40
},
{
"type": "relation",
"name": "internalLink",
- "value": "mULW0Q3VojwY",
+ "value": "zEY4DaJG4YT5",
"isInheritable": false,
"position": 50
},
{
"type": "relation",
"name": "internalLink",
- "value": "4TIF1oA4VQRO",
+ "value": "bwZpz2ajCEwO",
"isInheritable": false,
"position": 60
},
{
"type": "relation",
"name": "internalLink",
- "value": "KSZ04uQ2D1St",
+ "value": "wy8So3yZZlH9",
"isInheritable": false,
"position": 70
},
{
"type": "relation",
"name": "internalLink",
- "value": "6f9hih2hXXZk",
+ "value": "CohkqWQC1iBv",
"isInheritable": false,
"position": 80
},
{
"type": "relation",
"name": "internalLink",
- "value": "zP3PMqaG71Ct",
+ "value": "mULW0Q3VojwY",
"isInheritable": false,
"position": 90
},
{
"type": "relation",
"name": "internalLink",
- "value": "grjYqerjn243",
+ "value": "4TIF1oA4VQRO",
"isInheritable": false,
"position": 100
},
{
"type": "relation",
"name": "internalLink",
- "value": "gBbsAeiuUxI5",
+ "value": "KSZ04uQ2D1St",
"isInheritable": false,
"position": 110
},
{
"type": "relation",
"name": "internalLink",
- "value": "2FvYrpmOXm29",
+ "value": "6f9hih2hXXZk",
"isInheritable": false,
"position": 120
},
{
"type": "relation",
"name": "internalLink",
- "value": "AlhDUqhENtH7",
+ "value": "zP3PMqaG71Ct",
"isInheritable": false,
"position": 130
},
{
"type": "relation",
"name": "internalLink",
- "value": "bwZpz2ajCEwO",
+ "value": "grjYqerjn243",
"isInheritable": false,
"position": 140
},
{
"type": "relation",
"name": "internalLink",
- "value": "KC1HB96bqqHX",
+ "value": "gBbsAeiuUxI5",
"isInheritable": false,
"position": 150
},
{
"type": "relation",
"name": "internalLink",
- "value": "0ESUbbAxVnoK",
+ "value": "2FvYrpmOXm29",
"isInheritable": false,
"position": 160
},
- {
- "type": "label",
- "name": "iconClass",
- "value": "bx bx-printer",
- "isInheritable": false,
- "position": 30
- },
- {
- "type": "label",
- "name": "shareAlias",
- "value": "printing-and-pdf-export",
- "isInheritable": false,
- "position": 110
- },
{
"type": "relation",
"name": "internalLink",
- "value": "8YBEPzcpUgxw",
+ "value": "AlhDUqhENtH7",
"isInheritable": false,
"position": 170
},
{
"type": "relation",
"name": "internalLink",
- "value": "A9Oc6YKKc65v",
+ "value": "KC1HB96bqqHX",
"isInheritable": false,
"position": 180
},
{
"type": "relation",
"name": "internalLink",
- "value": "F1r9QtzQLZqm",
+ "value": "0ESUbbAxVnoK",
"isInheritable": false,
"position": 190
},
{
- "type": "relation",
- "name": "internalLink",
- "value": "zEY4DaJG4YT5",
+ "type": "label",
+ "name": "iconClass",
+ "value": "bx bx-printer",
"isInheritable": false,
- "position": 200
+ "position": 30
+ },
+ {
+ "type": "label",
+ "name": "shareAlias",
+ "value": "printing-and-pdf-export",
+ "isInheritable": false,
+ "position": 110
}
],
"format": "markdown",
@@ -9864,6 +9864,20 @@
"isInheritable": false,
"position": 60
},
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "8YBEPzcpUgxw",
+ "isInheritable": false,
+ "position": 70
+ },
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "IjZS7iK5EXtb",
+ "isInheritable": false,
+ "position": 80
+ },
{
"type": "label",
"name": "shareAlias",
@@ -9877,20 +9891,6 @@
"value": "bx bx-code",
"isInheritable": false,
"position": 90
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "8YBEPzcpUgxw",
- "isInheritable": false,
- "position": 100
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "IjZS7iK5EXtb",
- "isInheritable": false,
- "position": 110
}
],
"format": "markdown",
diff --git a/docs/User Guide/User Guide/Note Types/Markdown.md b/docs/User Guide/User Guide/Note Types/Markdown.md
index 906645611e..bc949ca6d3 100644
--- a/docs/User Guide/User Guide/Note Types/Markdown.md
+++ b/docs/User Guide/User Guide/Note Types/Markdown.md
@@ -25,7 +25,7 @@ Even if Markdown is now specially treated by having a preview mechanism, Trilium
The following features are supported by Trilium's Markdown format and will show up in the preview pane:
* All standard and GitHub-flavored syntax (basic formatting, tables, blockquotes)
-* Code blocks with syntax highlight (e.g. ` ```js `) and automatic syntax highlight
+* Code blocks with syntax highlight. Note that the language must be specified for syntax highlight to apply (e.g. ` ```js `).
* <a class="reference-link" href="Text/Block%20quotes%20%26%20admonitions.md">Block quotes &amp; admonitions</a>
* <a class="reference-link" href="Text/Math%20Equations.md">Math Equations</a>
* <a class="reference-link" href="Mermaid%20Diagrams.md">Mermaid Diagrams</a> using ` ```mermaid `
diff --git a/packages/commons/src/lib/markdown_renderer.ts b/packages/commons/src/lib/markdown_renderer.ts
index 1afcc48057..87dbfefe25 100644
--- a/packages/commons/src/lib/markdown_renderer.ts
+++ b/packages/commons/src/lib/markdown_renderer.ts
@@ -48,6 +48,14 @@ export interface RenderToHtmlOptions {
* preview) so authored H1s are shown as-is.
*/
demoteH1?: boolean;
+ /**
+ * Optional custom renderer — defaults to {@link CustomMarkdownRenderer}.
+ * Callers that need caller-specific output (e.g. the Markdown live preview
+ * suppressing the auto-language fallback on unlabeled fences) can subclass
+ * and pass an instance. A fresh instance should be passed per call since
+ * marked attaches a parser to the renderer during parsing.
+ */
+ renderer?: Renderer;
}
function escapeHtml(str: string): string {
@@ -160,8 +168,12 @@ function restoreFromMap(text: string, map: Map<string, string>): string {
/**
* Keep renderer code up to date with https://github.com/markedjs/marked/blob/master/src/Renderer.ts.
+ *
+ * Exported so callers can subclass and override specific methods (e.g. `code()`) for
+ * caller-specific output, then pass the subclass instance through
+ * {@link RenderToHtmlOptions.renderer}.
*/
-class CustomMarkdownRenderer extends Renderer {
+export class CustomMarkdownRenderer extends Renderer {
override heading(data: Tokens.Heading): string {
if (data.depth === 1) {
@@ -283,7 +295,7 @@ export function renderToHtml(content: string, title: string, options: RenderToHt
]
});
- const renderer = new CustomMarkdownRenderer({ async: false });
+ const renderer = options.renderer ?? new CustomMarkdownRenderer({ async: false });
let html = marked.parse(processedText, { async: false, renderer }) as string;
html = restoreFromMap(html, formulaMap);