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…
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.
Pre slot (progressive enhancement)
12345678
<markdown-viewer><pre># Hello worldThis is **inline** markdown with a graceful fallback.The raw text is visible if JS is disabled.</pre></markdown-viewer>
<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.
Script slot
1234567
<markdown-viewer><scripttype="text/markdown"># Hello worldThis content is **invisible** without JavaScript.</script></markdown-viewer>
<template>
Inert DOM node can be consulted as long as you put the data-mdattribute 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 < and &, or use the <script type="text/markdown"> slot, whose content is raw text, for code-heavy documents.
Template slot
12345678910
<markdown-viewer><templatedata-md># Hello world| Name | Role ||-------|----------|| Alice | Engineer || Bob | Designer |</template></markdown-viewer>
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.
External file
1234
<markdown-viewersrc="/path/to/document.md"></markdown-viewer><!-- Another origin: explicit opt-in --><markdown-viewersrc="https://docs.example.com/guide.md"allow-cross-origin></markdown-viewer>
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”).
Translated error message
<markdown-viewersrc="/notes.md"data-label-error="Impossible de charger le document."></markdown-viewer>
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.
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-calloutattribute, 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.
Callout syntax
1234567
:::warning**Careful!** This action cannot be undone.::::::tip Pro tipUse the `highlight` attribute to hook up a syntax highlighter.:::
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 styleattribute, 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-Policyimg-src rule if that matters to you.
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"
on
Sanitizing 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
highlight
boolean
—
Fire per-block markdown-viewer:highlight events after render
ping
string
—
URL to ping with render metadata via sendBeacon
data-theme
string
—
Theme name propagated to .md-content container
data-label-error
string
Failed to load markdown
Text of the role="alert" message shown when src fails to load or parse and no <pre> fallback is visible
data-auto-mermaid
boolean
—
Upgrade ```mermaid fences in the rendered output to <diagram-wc> (main.js loads the markdown-mermaid bridge when present)
Events
Event
Detail
Description
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 / Method
Description
.parser
Get/set custom parser function (md → html string). Overrides the default marked parser (and its callout syntax). Its output is still sanitized unless sanitize="off".
.markdown
Get 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.