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-editor

Side-by-side markdown editor with live preview. Composes a textarea with markdown-viewer.

Overview

A split-pane markdown editor that pairs your <textarea> with a <markdown-viewer> for live preview. Part of the Extras Pack.

The editor adopts the textarea you write rather than replacing it. Its id, <label>, name, required, minlength/maxlength, readonly, dir, form and aria-* attributes all survive the upgrade, so the field submits, validates and resets exactly as a plain textarea does — with or without JavaScript.

Usage

Basic

Wrap a labelled <textarea> with initial content. The editor moves it into the source pane and builds the preview pane beside it.

With Syntax Highlighting

Add the highlight attribute to pass through to the preview viewer. Bring your own highlighter via the markdown-viewer:highlight event.

Form Integration

Put name and any constraints on the <textarea>. That textarea is what the form submits, so the value is sent even before (or without) the upgrade. form.reset() restores the authored text and the preview follows it.

The host placeholder and rows attributes override the textarea's own; there is no default placeholder.

Tab Indentation

Add data-tab-indent to make the Tab key insert two spaces instead of moving focus. To leave the textarea with the keyboard, press Escape and then Tab; Shift+Tab always moves focus back. The textarea carries a description saying so (override it with data-label-tab-hint).

Mermaid Diagrams

Add data-auto-mermaid and ```mermaid fences in the preview upgrade to <diagram-wc>, re-rendered with a debounce while you type.

Labels and Direction

The two panes are named “Markdown source” and “Rendered preview”; override them with data-label-source and data-label-preview. The textarea gets dir="auto" unless you set dir, and the preview uses the same direction, so right-to-left and mixed content lays out correctly.

Attributes

AttributeValuesDefaultDescription
placeholderstring—Textarea placeholder; overrides the textarea's own. No default placeholder
rowsnumber10Textarea rows; overrides the textarea's own rows
highlightboolean—Pass highlight attribute to the preview viewer (markdown-viewer:highlight per code block)
data-tab-indentboolean—Tab inserts two spaces instead of moving focus. Escape then Tab moves focus; Shift+Tab is never captured. Read at upgrade
data-auto-mermaidboolean—Upgrade ```mermaid fences in the live preview to diagram-wc (loads the mermaid bridge)
data-themestring—Theme propagated to the preview pane
data-label-sourcestringMarkdown sourceAccessible name of the source pane; also names the textarea when nothing else does
data-label-previewstringRendered previewAccessible name of the preview pane
data-label-tab-hintstringTab inserts spaces. Press Escape, then Tab, to move focus.Description read with the textarea when data-tab-indent is set

Events

EventDetailDescription
markdown-editor:input{ value }Fired on each keystroke. Bubbles, composed
markdown-editor:change{ value, source }source "user": on blur after the content changed. source "api": when .value is assigned (the next blur does not repeat it). Not fired by form reset. Bubbles, composed

markdown-editor:change carries detail.source: "user" when the textarea loses focus after an edit, "api" when you assign .value. Filter on it to ignore your own assignments. A form reset fires neither.

JavaScript API

PropertyTypeDescription
.valuestringGet or set the markdown. Setting updates the preview immediately and fires markdown-editor:change with source: "api".
.textareaHTMLTextAreaElementThe backing textarea — your own when you provided one. It is the same object for the element’s whole life, including after it is moved in the DOM.

Accessibility

  • Name the textarea as you would any field: a <label for>, a wrapping <label>, aria-label or aria-labelledby. They all keep working after the upgrade. Only when nothing names it does the editor fall back to the source pane label.
  • The source and preview panes are named groups (role="group" with an aria-label), not landmarks, so an editor adds no regions to the page.
  • The preview is not a live region. Re-announcing the whole rendered document on every keystroke would drown out typing; review the preview by moving to its group.
  • With data-tab-indent, Tab is captured for indentation. Escape then Tab moves focus on, and Shift+Tab is never captured, so there is no keyboard trap. A read-only or disabled textarea never captures Tab.
  • Required and length errors are the native textarea's own messages and styling.

Security

The preview is a <markdown-viewer> with its default sanitising on, and the editor never writes HTML itself. Script elements, event-handler attributes and javascript: URLs typed or pasted into the editor are removed before the preview shows them. The preview runs in your page, so treat anything you later render from the submitted markdown as untrusted and sanitise it on the server as well. See the viewer’s sanitising notes for exactly what is kept.

Progressive Enhancement

Without JavaScript the <textarea> renders at full width with monospace styling and is a complete form field: labelled, named, validated and submitted. After the upgrade the same textarea sits in the source pane with the live preview beside it. The panes sit side by side when the editor is at least about 40em wide and stack when it is narrower — the editor’s own width decides, not the viewport’s.

Related

  • contenteditable — in-place editing without a separate source pane, including VB's inline markdown-editable enhancement
↑