Coder Social home page Coder Social logo

rauenzi / trilium-markdownpreview Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 1.0 91 KB

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

License: Apache License 2.0

CSS 16.01% JavaScript 83.99%
trilium trilium-widget markdown

trilium-markdownpreview's Introduction

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

trilium-markdownpreview's People

Contributors

rauenzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

wangs-c

trilium-markdownpreview's Issues

ScrollSync blocks scroll for searches inside the document.

If ScrollSync is enabled on the left pane (or both), when doing a search inside the document, Trilium cannot scroll al the way to each of the occurrences.

#markdownScrollSync=right does work, it allows for the left pane to scroll to each of the occurrences in the search.

Child notes css is applied unexpectly.

With this plugin installed, there is a rare case where the css is applied unexpectedly.

For example, I have collections of themes, css styles. If I click on the parent note, the css will be applied which makes unwanted change to the UI.

Peek 2023-08-21 14-26

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.