Markdown

Trilium has always supported Markdown through its import feature, however the file was either transformed to a Text note (converted to Trilium's internal HTML format) or saved as a Code note with only syntax highlight.

This note type is a split view, meaning that both the source code and a preview of the document are displayed side-by-side. See Note types with split view for more information.

Rationale#

The goal of this note type is to fill a gap: rendering Markdown but not altering its structure or its whitespace which would inevitably change otherwise through import/export.

Even if Markdown is now specially treated by having a preview mechanism, Trilium remains at its core a WYSWYG editor so Markdown will not replace text notes.

Features#

Source view pane#

  • Syntax highlighting for the Markdown syntax.
  • Nested syntax highlighting for code inside code blocks.
  • When editing larger documents, the preview scrolls along with the source editor.

Preview pane#

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. <!--CODE_BLOCK_1776454313064_0-->mermaid

  • Include Note (no builtin Markdown syntax, but HTML syntax works just fine):

    <section class="include-note" data-note-id="vJDjQm0VK8Na" data-box-size="expandable">
        &nbsp;
    </section>n
  • Internal (reference) links via its HTML syntax, or through a Wikilinks-like format (only Note ID):

    [[Hg8TS5ZOxti6]]

Creating Markdown notes#

There are two ways to create a Markdown note:

  1. Create a new note (e.g. in the Note Tree) and select the type Markdown, just like all the other note types.
  2. Create a note of type Code and select as the language either Markdown or GitHub-Flavored Markdown. This maintains compatibility with your existing notes prior to the introduction of this feature.

Import/export#

  • By default, when importing a single Markdown file it automatically gets converted to a Text note. To avoid that and have it imported as a Markdown note instead:

    • Right click the Note Tree and select Import into note.
    • Select the file normally.
    • Uncheck Import HTML, Markdown and TXT as text notes if it's unclear from the metadata.
  • When exporting Markdown files, the extension is preserved and the content remains the same as in the source view.

  • Once exported as a Trilium ZIP, the ZIP will preserve the Markdown type without converting to text notes thanks to the meta-information in it.

Conversion between text notes and Markdown notes#

Currently there is no built-in functionality to convert a Text note into a Markdown note or vice-versa. We do have plans to address this in the future.

This can be achieved manually, for a single note:

  1. Export the file as Markdown, with single format.
  2. Import the file again, but unchecking Import HTML, Markdown and TXT as text notes if it's unclear from the metadata.

For multiple notes, the process is slightly more involved:

  1. Export the file as Markdown, ZIP.
  2. Extract the archive.
  3. Remove the !!!meta.json file.
  4. Compress the extracted files back into an archive.
  5. Import the newly create archive, but unchecking Import HTML, Markdown and TXT as text notes if it's unclear from the metadata.

Sync-scrolling & block highlight#

When scrolling through the editing pane, the preview pane will attempt to synchronize its position to make it easier to see the preview.

In addition, the block in the preview matching the position of the cursor in the source view will appear slightly highlighted.

The sync is currently one-way only, scrolling the preview will not synchronize the position of the editor.

This feature cannot be disabled as of now; if the scrolling feels distracting, consider temporarily switching to the editor mode and then switching to preview mode when ready.