The latest version of Marked 2, 2.6.18, is released for direct customers and in review for Setapp and Mac App Store customers. It has two things that I think will be of interest to many.
Too much coffee? Not enough?
First, I finally figured out a way to stop the Table of Contents and other fixed-position elements from jittering when the preview scrolls. That started with the last OS as a result of new rubber-banding in web views. I could set the body to fixed position and scroll the containing div, but that broke all of the positioning that Marked needs to do for things like bookmarking and header navigation. After months of experimenting, I decided, just for giggles, to try other positioning values on the body element. Eventually found that temporarily setting it to
sticky would stop the jitter and not break my ability to get document-relative positions. In my testing I haven’t found any notable repercussions to this, so I’m releasing it. Using Marked is significantly better now, what without elements jumping around and such.
Mermaid users will love this…
Second, over the last couple of years, many users have run into complications when embedding their own scripts. It used to be that every time the preview updated, Marked did a full page load, which would then run scripts triggered by onload. But a few versions back I modified the page load such that new content is injected into the container div without requiring a reload. This was a major step forward in usability, but it meant that those custom scripts wouldn’t trigger again after the initial load. So I worked up a solution that allows you to “hook” the update function, triggering any function whenever the preview updates. It’s a simple script block you can embed along with your custom script, e.g. Mermaid. If you use it on every document, you can injected the scripts with a custom preprocessor. See Embedding Scripts for details on
A few other fixes showed up in this release as well. Visit the changelog for a full list.