A widget for trilium notes for live previewing markdown files with support for anchors, images, and sync scroll.
I know Trilium isn't a markdown editor, but I still use markdown for other things like my GitHub READMEs and I like storing everything in one place--Trilium. The only problem was, I couldn't preview my markdown files, and that's super helpful to have before I go pushing a commit. After looking, I couldn't find an existing widget for it, so I decided to make my own.
- Preview markdown notes in real time
- Global and per-note styles
- Embed local images
- Clickable in-page anchor links
- Syncable scrollbars
- GFM-compliant with tables and more
- Download the
zip
file from the latest release on GitHub. - Import the zip into Trilium, but make sure you uncheck
Safe Import
! - (optional) Create one (or more) child code notes of
CSS
type and fill it with any global markdown styles.
Create a code note with markdown type. Then, to make a note previewable, simply add the #markdownPreview
attribute to it. (You may have to switch notes afterward for the preview to appear.)
After that, just start writing in markdown on the code editor side. You'll see the preview update with you as you go.
If you're going to add any images or styles to the note, it can be annoying to see the preview cards at the bottom. You can hide those by adding the #hideChildrenOverview
native to Trilium.
Syntax highlighting is enabled by default, you can disable this by unchecking the promoted attribute syntaxHighlighting
on the widget note!
To use a local image, attach the image as a child of the markdown note. You can then simply refer to it by filename.
Remote images can be attached just like any other image using the full url.
The actual heading anchors are created automatically and match GFM style. That means for complex headings you can have multiple -
in a row. e.g. Heading (subtext)
becomes #heading--subtext-
.
From there you can create anchor links by linking them as [link text](#heading-name)
replacing any special characters (and spaces) with -
.
By default, MarkdownPreview will try to keep the scroll bars in sync no matter which side you are scrolling. The widget is not perfect at keeping them exactly at the same place contextually because the rendering can be so different.
You can disable the sync entirely by adding the #markdownScrollSync
attribute with none
as the value. You can also disable each side separately with left
or right
. For instance, if you want the preview to automatically scroll as you scroll the source, but not the other way around, then use #markdownScrollSync=left
.
Both the global and local styles are picked up and reapplied on note switch, so no need to keep reloading if you are tinkering with your styles!
As mentioned in the installation section, any CSS
note that is a child to the widget code will automatically be picked up and applied.
Local styles are specific to the markdown note. Just make a CSS
note as a child of the markdown note and it'll be picked up!