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

data-math

Enhance code elements with precompiled MathML rendering. Add data-math to any code element for automatic MathML injection with numbering, copy, and Markdown integration.

Overview

The data-math attribute enhances <code> elements with precompiled MathML. The original LaTeX source stays readable without JavaScript, and when JS runs, it is replaced by rendered MathML.

How It Works

  1. Add data-math to a <code> element with LaTeX source as its text content
  2. Add data-mathml with the precompiled MathML string
  3. On page load, the script reads data-mathml, injects a <math> element, and hides the original <code>
  4. Without data-mathml, or in a browser that cannot render MathML, the LaTeX source displays as-is — readable fallback with no JS dependency
  5. The rendered <math> gets alttext set to the LaTeX source (unless your MathML already has one)
  6. The data-mathml string is sanitized before insertion: only MathML elements survive, and event handlers, href, src, style, id, name and xlink:/xml: attributes are removed. Treat it as author-controlled markup all the same — generate it at build time, not from user input.

Attributes

Attribute Type Description
data-math token list Space-separated tokens: inline, numbered, copyable. An empty value defaults to block rendering.
data-mathml string Precompiled MathML string to inject. Without this, the element shows the raw LaTeX source.
data-label-copy string Copy button text for copyable. Default "Copy LaTeX". Read from the element or its nearest ancestor that sets it, so one attribute on <article> localises every equation.
data-label-copied string Announced (and shown on the button for two seconds) after a successful copy. Default "Copied to clipboard".
data-label-copy-failed string Announced (and shown on the button) when the clipboard refuses. Default "Copy failed".
data-math-state string Set automatically: "rendered" when MathML injected, "source" when showing raw LaTeX.
data-math-init boolean State hook, set once the element is enhanced. Do not set it. Enhancement is tracked internally, so a cloned equation is adopted (not rendered twice) and its copy button works.

Tokens

Token Description
inline Renders inline math, wrapped in a <span> instead of a block wrapper.
numbered Displays an equation number. Numbers follow document order and are renumbered when equations are added or removed. Equations with an id are listed in window.VBMath.equations ({ id, number, latex }, rebuilt in document order).
copyable Adds a Copy LaTeX <button> after the rendered math. Activating it copies the original LaTeX source and announces the result.

Inline Math

Use the inline token for math that flows within paragraph text.

Numbered Equations

Combine numbered with an id for linkable, numbered equations.

Copyable Math

The copyable token adds a Copy LaTeX button after the rendered math. Activating it (click, Enter or Space) copies the LaTeX source to the clipboard, announces the result through VB's shared live region and shows it on the button for two seconds. A refused copy (no clipboard permission, insecure context) is announced too. Localise the texts with data-label-copy, data-label-copied and data-label-copy-failed on the element or an ancestor.

Markdown Integration

Markdown processors emit code.language-math for fenced math blocks. The enhancement script auto-detects these — no extra configuration needed.

This produces the standard HTML output:

The code.language-math selector is matched automatically alongside [data-math]. For precompiled MathML, add data-mathml to the element at build time via a Remark or Markdown-it plugin.

Styling

Hook Description
[data-math-rendered] The wrapper holding the rendered <math> (a block wrapper, or a <span> for inline). It takes the source's id, so :target highlights a linked equation.
[data-math-numbered] Numbered wrapper; a grid with the number in ::after.
[data-equation-number] The equation's number on the wrapper (read by attr() in ::after).
[data-math-copyable], button[data-math-copy] Copyable wrapper and its button. The button carries data-state="copied" or "failed" for two seconds after use.
[data-math-state="source"] The fallback: source shown as code.

Events

Event Detail Description
math:rendered { latex, inline, number } Fired on the source element after MathML is injected. latex is the source text, inline is a boolean, number is the equation number at that moment (or null); a later insert above it renumbers the wrapper.

Progressive Enhancement

Without data-mathml, the LaTeX source displays as a readable <code> block. This is the no-JS fallback:

The element receives data-math-state="source" so you can style the fallback state differently if needed.

Dynamic Content

Elements added to the DOM after page load are automatically enhanced via a MutationObserver. No manual initialization needed.

Accessibility

  • The injected <math> is read as math by screen readers with MathML support (VoiceOver; NVDA and JAWS with a math add-on such as MathCAT). Support elsewhere, notably TalkBack, is limited.
  • For those, the <math> carries alttext with the LaTeX source. Where LaTeX is a poor spoken form, put a plain-language alttext in your MathML (it is kept), or describe the equation in the surrounding text.
  • The original LaTeX source stays in the DOM, hidden
  • Copy results are announced through VB's shared role="status" live region (a refused copy through the assertive one), placed outside the button so the button's name does not change for assistive tech mid-announcement
  • Numbered equations are linkable via id and standard <a href>; the number is drawn in CSS, so write "Equation 1" in your link text

Related

  • <math> — MathML itself, its styling and the math font.
  • <code> — the element that carries the LaTeX source.
  • data-copy — copy buttons for any text. copyable is the math-specific version that copies the LaTeX behind a rendered equation.
↑