Skip to content

0.3.0 — The right colour scheme, and a much cheaper repaint

Choose a tag to compare

@feibuilds feibuilds released this 30 Aug 01:36
· 45 commits to main since this release

The preview follows the colour scheme your Markdown file resolved, the table of contents is opt-in, and a repaint no longer relays out the whole document.

Upgrading from 0.2.x

The table of contents no longer opens on its own. It takes an editor group of a document you did not ask it for, so it is now behind enable_toc, defaulting to false. Set it in Preferences → Package Settings → MarkdownGlance → Settings:

"enable_toc": true

Everything else about it is unchanged, except that closing it from its tab now keeps it closed for that preview instead of having it return a second later.

Changed

A Mermaid diagram now follows the editor's colour scheme. The request asked mermaid.ink for the light theme on a transparent background, so on a dark scheme every label drawn straight onto that background — sequence messages, loop and note text — was near-black on near-black while the filled actor boxes stayed readable. The request now carries Mermaid's dark theme and the preview's own background colour. A diagram is baked by the server and cannot be recoloured by a repaint, so changing scheme under an open preview renders the document again for the new URLs.

The table of contents and the outline drop the document's page margins for 0.8rem of padding — they are lists in a narrow group, not pages.

Added

auto_width, defaulting to true. The table of contents and the outline are given the width their longest heading needs instead of a fixed share of the window, so the rest goes to the content. It is a ceiling, not a target: neither group is ever wider than it used to be. Dragging the divider turns it off for that group; "auto_width": false restores the fixed share everywhere. ADR 0011 has the reasoning.

MarkdownGlance: Copy Diagnostics now reports what a repaint cost — recent_renders with the Markdown in and the HTML out, and recent_paints with the wall clock around PhantomSet.update and whether the paint was skipped as unchanged.

Performance

Editing a 69 KB document pinned one core in sublime_text with plugin_host near idle. The cost was native minihtml layout, and almost all of it was avoidable.

  • A repaint that changes nothing no longer relays out the document. PhantomSet.update identifies a phantom by its region, content, layout and its on_navigate callback; the backend built that callback fresh every repaint, so the set never recognised the phantom already on screen — it erased it and added it back. One callback per surface now lives for the life of the surface, and identical HTML never reaches the phantom set.
  • Repainting the table of contents no longer spins the window's focus. It called reveal, which focuses the group, the view, then the previous group back; each of those fires on_activated, which re-reads the theme and repaints, landing back in the same place. Creation and a mode switch still reveal; a repaint does not.
  • Indentation in a code block no longer costs an element per space. A run of two or more spaces is now U+00A0 rather than one <i class="space">.</i> each — 5774 of them in this repository's own design document. Its HTML falls from 296 KB to 178 KB, and from 9332 elements to 3558.
  • The vendored parser drew a megabyte-sized hash salt. Upstream markdown2 writes SECRET_SALT = bytes(randint(0, 1000000)) — not a random salt but a zero-filled buffer of random length, re-hashed on each of the several hundred _hash_text calls a parse makes. Drawn once per plugin_host, it meant the same document parsed in 123 ms or in 1628 ms depending on the launch. Three random bytes keep the intent.

Fixed

Every surface now follows the colour scheme the Markdown file itself resolved. A Markdown buffer usually has one: MarkdownEditing: Select Color Scheme writes color_scheme into Markdown.sublime-settings, and a syntax-specific setting beats the global UI: Select Color Scheme. The preview, the table of contents and the outline are plain scratch views, so they inherited the global scheme — and that is the scheme minihtml resolves var(--background), var(--foreground) and var(--bluish) against, which is what preview.css is built out of. A light MarkdownEditing scheme over a dark editor rendered as a dark preview beside a light source. Each surface is now put on the source's scheme, and re-put on it whenever the source's moves.

Closing the table of contents from its tab no longer leaves its empty group behind.

Full changelog: 0.2.1...0.3.0