Skip to content

A widget for trilium notes for live previewing markdown files with support for anchors, images, and sync scroll.

License

Notifications You must be signed in to change notification settings

zerebos/Trilium-MarkdownPreview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trilium-MarkdownPreview

A widget for trilium notes for live previewing markdown files with support for anchors, images, and sync scroll.

Why?

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

Banner

Features

  • 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

Installation

  1. Download the zip file from the latest release on GitHub.
  2. Import the zip into Trilium, but make sure you uncheck Safe Import!
  3. (optional) Create one (or more) child code notes of CSS type and fill it with any global markdown styles.

Usage

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

Syntax highlighting is enabled by default, you can disable this by unchecking the promoted attribute syntaxHighlighting on the widget note!

Images

Local

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

Remote images can be attached just like any other image using the full url.

Anchor Links

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 -.

Scroll Sync

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.

Disabling

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.

Styling

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!

Global

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

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!

Showcase

Anchors

anchors.mp4

Local Styles

local_styles.mp4

ScrollSync

scrollsync_both.mp4

ScrollSync=left

scrollsync_left.mp4

About

A widget for trilium notes for live previewing markdown files with support for anchors, images, and sync scroll.

Topics

Resources

License

Stars

Watchers

Forks