Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

markdown-viewer

Render markdown with progressive enhancement. Supports external files, inline content, pluggable parsers, and VB theme integration.

Overview

A platform-native markdown viewer custom element. Renders markdown into light DOM so VB's CSS cascade, themes, and component styles apply automatically. Progressive enhancement via the <pre> slot ensures content is readable without JavaScript.

Content Slots

The component resolves content using this priority chain:

<pre>

Raw markdown is visible as readable text if JS is disabled. Hidden after render.

<script>

If a <script> has an unknown MIME type the browser does not execute or render it. Here we use text/markdown to create a markdown block to render. Like the next approach using <template>, there is no fallback without JavaScript support.

<template>

Inert DOM node can be consulted as long as you put the data-md attribute on it, framework-friendly. No fallback without JS.

Escape < and & in <pre> and <template> slots. The HTML parser reads those slots before the viewer does, so a literal tag in the prose or in a code fence (List<String>, <div>) is turned into an element and silently disappears from the markdown. Write &lt; and &amp;, or use the <script type="text/markdown"> slot, whose content is raw text, for code-heavy documents.

src

Fetch external markdown with fetch(). Like <include-file>, src is same-origin by default: only http(s) URLs on the page's origin load, a redirect to another origin is refused, and blob:, data: and javascript: URLs are always refused. Add allow-cross-origin to load from another origin. That server must also allow it with CORS, and the content is still sanitized.

Changing src re-fetches. Removing it falls back to the slots. If the fetch or parse fails, the viewer sets data-error and fires markdown-viewer:error. A <pre> slot stays visible as the fallback. Without one, the viewer shows a role="alert" message whose text comes from data-label-error (default “Failed to load markdown”).

Theme Propagation

Set data-theme on the viewer or let it inherit from the nearest ancestor with [data-theme]. The theme propagates to the .md-content container.

Custom Parser

The default parser is marked with GFM enabled. Override it with any function that accepts a markdown string and returns an HTML string:

Syntax Highlighting

Add the highlight attribute to fire markdown-viewer:highlight events for each code block. Bring your own highlighter:

Mermaid Diagrams

Add data-auto-mermaid to have main.js load a bridge that upgrades ```mermaid fences in the output to <diagram-wc>:

Or wire it yourself: listen for markdown-viewer:rendered and lazy-load Mermaid only when needed:

Callout Blocks

The default parser renders :::type … ::: blocks as callouts. The types are note, info, tip, warning and danger. Text after the type replaces the default title, which is the capitalised type name. Each callout is an <aside data-callout="…" role="note"> whose first child is a visible <p data-callout-title>, so its kind is not shown by colour alone. That is the same markup you write by hand in HTML: the styling comes from the shared data-callout attribute, not from this component, so markdown and hand-written callouts look identical and follow the same theme hooks. A custom .parser replaces this syntax along with the rest of the default parser.

Sanitising

By default, rendered HTML (including the output of a custom .parser) passes through the shared Vanilla Breeze sanitizer. The cleaned nodes are then inserted directly. They are never turned back into a string and parsed a second time, because that round trip is how mutation XSS gets past sanitizers. The viewer sanitizes by default because it renders untrusted text such as AI output (<ai-summary>) and user comments (<markdown-editor>).

Removed:

  • <script>, <style>, <iframe>, <object>, <embed>, <form>, <base>, <link>, <meta>, <noscript>, <title> and the other raw-text elements, SVG <foreignObject>, MathML <mglyph> and <malignmark>, and comments.
  • Every on* event handler and every style attribute, which blocks fixed-position overlays and page-wide CSS.
  • Form-hijacking attributes (form, formaction, formmethod, formtarget and similar), invokers that reach into the page (popovertarget, commandfor, interestfor), and autofocus and ping.
  • javascript: and vbscript: URLs, data: URLs in links, and non-media data: URLs in src.
  • On a nested <markdown-viewer> or <include-file>: the attributes that fetch or opt out (src, sanitize, allow-cross-origin, trusted).

Rewritten:

  • id and name get a user-content- prefix (as on GitHub), so content cannot clobber page globals or page ids. Links and label references inside the same document are updated to match, so [jump](#setup) pointing at a raw <h2 id="setup"> in the same markdown still works. References to ids outside the content are dropped, except href="#…" links, which still point at the page.
  • Buttons and submit, reset and image inputs become type="button", so they cannot submit a surrounding form.

Kept: ordinary markdown output, and inline HTML such as <details>, <kbd> and tables. Also kept are class, data-* and ARIA attributes, inline SVG and MathML, task-list checkboxes, data:image sources, and remote images. Remote images make tracking pixels possible: add a Content-Security-Policy img-src rule if that matters to you.

Turning it off (trusted content only)

Attributes

AttributeValuesDefaultDescription
srcstring—URL of external markdown file
allow-cross-originboolean—Permit a src on another origin (CORS still applies; content is still sanitized unless sanitize="off"). Without it src must be same-origin http(s); redirects are re-checked
sanitize"on", "off", "false"onSanitizing is on unless this is "off" or "false" (any other value, or no attribute, keeps it on). Off writes parser output raw with innerHTML: trusted first-party markdown only, never with a cross-origin or user-influenced src
highlightboolean—Fire per-block markdown-viewer:highlight events after render
pingstring—URL to ping with render metadata via sendBeacon
data-themestring—Theme name propagated to .md-content container
data-label-errorstringFailed to load markdownText of the role="alert" message shown when src fails to load or parse and no <pre> fallback is visible
data-auto-mermaidboolean—Upgrade ```mermaid fences in the rendered output to <diagram-wc> (main.js loads the markdown-mermaid bridge when present)

Events

EventDetailDescription
markdown-viewer:fetch{ src }Fired when external fetch begins
markdown-viewer:rendered{ src, node }Fired after parse and render complete
markdown-viewer:highlight{ node, language }Fired per code block when highlight attribute is set
markdown-viewer:error{ error }Fired on fetch or parse failure

JavaScript API

Property / MethodDescription
.parserGet/set custom parser function (md → html string). Overrides the default marked parser (and its callout syntax). Its output is still sanitized unless sanitize="off".
.markdownGet the current markdown source. Set a string to render it instead of the slots or src. Set null or '' to fall back to them.
.render()Force a re-render from the current content source. Returns a Promise.
.reload()Re-fetch the src URL and re-render. Returns a Promise.

Progressive Enhancement

The <pre> slot provides the best progressive enhancement:

SlotJS disabledCrawlableRecommended for
srcNothing visibleNoExternal files
<script>Nothing visibleNoBuild-time content
<template>Nothing visibleNoFramework content
<pre>Raw text visibleYesProgressive enhancement
↑