astro-mystv0.3.0

astro-myst/XrefPreview.astro#

Shows a preview of the referenced figure, equation, table, theorem, section or bibliography entry when a cross-reference or citation is hovered or focused. Targets on other pages of your site are fetched once and cached. Previews are disabled on devices without hover, and Esc closes them.

---
import XrefPreview from 'astro-myst/XrefPreview.astro';
---

<XrefPreview />
PropDefaultDescription
selector'a.myst-xref, a.myst-cite'CSS selector of the links that get previews
delay150Delay in milliseconds before a preview opens

Add it once per page, for example in your layout. It removes its listeners when it leaves the page, so view transitions (<ClientRouter />) do not stack previews.

The preview is a div.myst.myst-preview with role="tooltip", appended to <body>. It holds a copy of the target element (for a section heading: the heading and the two elements after it), preceded by div.myst-preview-source with the title of the page when the target is on another page. base.css draws the box; theme.css adds its colours.

Browser scripts#

The integration’s scripts option adds these to every page; each acts only on MyST content.

ScriptDefaultMarkup it uses or adds
syncTabsonTab inputs with data-myst-sync (from :sync:): checking one checks every other input with the same key
copyCodeoffAdds button.myst-code-copy to each div.myst-code-wrapper; it shows “Copied” for a moment after a click
mermaidoffReplaces the source in each pre.mermaid with the diagram’s SVG and marks it data-processed

Stylesheets#

ImportAdded byContents
astro-myst/katex.cssstyles: 'base' and 'theme'KaTeX’s styles, matching the math HTML that mystmd pre-renders (KaTeX 0.15.6)
astro-myst/base.cssstyles: 'base' and 'theme'Only what MyST content needs to work: equation numbers, scrolling for wide content, code colours in dark mode, line numbers, the position of copy buttons, tabs, grids, figure layout, heading anchors, bibliography markers, the preview box
astro-myst/theme.cssstyles: 'theme'An optional look for MyST components, and for tables and link targets inside .myst

With styles: false, import them yourself (see Styling). Every rule in base.css and theme.css has zero specificity (:where()), except the custom properties that theme.css declares on :root, .dark and [data-theme="dark"], and sits in the cascade layer components; both files first declare Tailwind 4’s layer order, @layer theme, base, components, utilities. The two base.css overrides of KaTeX’s (unlayered) stylesheet are not in a layer.

Both switch to dark mode when the system prefers it, unless <html> has the class light or data-theme="light", and when an ancestor has the class dark or data-theme="dark".

Custom properties#

Declared by theme.css on :root. The dark values apply in dark mode, as described above.

PropertyLightDarkUsed for
--myst-accent#1f5f8b#79b8e8Cross-references, citations, footnote links, the active tab, hovered link cards
--myst-muted#5f6b76#9aa5b1Heading and equation numbers, heading anchors, captions, part titles, inactive tabs, sidebars
--myst-border#d9dee3#2f3740Borders and rules
--myst-surface#f6f8fa#161b22Backgrounds of admonitions, proofs, code blocks without highlighting and previews
--myst-note#2f6fb0#6aa7e6note admonitions and kinds without a colour of their own
--myst-tip#2e8540#5fbf73tip, hint and seealso admonitions
--myst-warning#b7791f#e0a84awarning, caution, attention and important admonitions
--myst-danger#c0392b#ef6f61danger and error admonitions, unresolved references, missing citations, unhandled directives, notebook errors
--myst-proof#6b4fa1#b39ddbTheorems, proofs and other prf: kinds
--myst-highlightrgba(31, 95, 139, 0.08)rgba(121, 184, 232, 0.12)Background of cross-references, highlight of the target of a followed link

Other custom properties:

PropertyWherePurpose
--myst-ctheme.css, on each admonitionColour of the admonition’s border and title: var(--myst-note), var(--myst-tip), … by kind. Set it on a class of your own to colour an admonition, for example one with :class: success.
--myst-preview-bg, --myst-preview-fgRead by base.css, defaulting to Canvas and CanvasText; theme.css sets the background to var(--myst-surface) on .myst-previewBackground and text colour of hover previews
--myst-grid-cols-0 … --myst-grid-cols-3The renderer, as an inline style of each gridColumns of a {grid}: -0 on narrow screens, -1 from 576 px, -2 from 768 px, -3 from 992 px
--shiki-dark, --shiki-dark-bg, …Shiki, as inline styles of codeDark theme colours that base.css switches to in dark mode
--myst-margin-widthRead by theme.css, default 14remWidth of margin notes in the page margin, with the class myst-margin-column (see Margin notes)

Emitted markup#

The classes astro-myst adds start with myst-, except mermaid (for Mermaid.js), Shiki’s shiki, shiki-themes and theme names on code blocks, line and highlighted on code lines, task-list-item and language-…. Classes that authors set with a directive’s :class: option are kept as written, as is MyST’s button class from the {button} role (astro-myst adds myst-button next to it). Labelled elements get an id that MyST makes from the label: lowercase, with other characters than letters, digits and - replaced by - (eq:main becomes eq-main).

ContentMarkup
Section headingh2#id > span.myst-heading-number + text + a.myst-heading-anchor (h1 to h6 by depth; the number only when headings are numbered)
Inline mathspan.myst-math-inline with KaTeX’s HTML
Display mathdiv.myst-math-display#id > div.myst-math-body + span.myst-equation-number
Figure, table, code listingfigure.myst-container.myst-{kind}#id[data-kind], plus .myst-numbered when numbered and .myst-subfigure for sub-figures; caption figcaption > span.myst-caption-number; legend div.myst-legend
Imageimg (lazy loading); :align: adds .myst-align-left, .myst-align-center or .myst-align-right. .mp4 files become video (autoplay, muted, loop, playsinline).
Tablediv.myst-table-wrapper > table > thead + tbody
Codediv.myst-code-wrapper#id[data-lang] > div.myst-code-filename + pre.shiki.myst-code-block > code > span.line; .myst-line-numbers on the pre with line numbers, span.line.highlighted for emphasized lines. Without highlighting: pre.myst-code-block > code.language-{lang}. A listing with a caption is wrapped in figure.myst-container.myst-code. The copyCode script appends button.myst-code-copy to the wrapper.
Mermaid diagrampre.mermaid with the diagram source, which the mermaid script replaces with an SVG
Iframediv.myst-iframe > iframe
Cross-referencea.myst-xref[data-xref-kind], plus [data-xref-remote] for targets on other pages and [data-xref-external] for other MyST sites; unresolved: span.myst-xref.myst-xref-unresolved
Citationa.myst-cite[data-cite] linking to #cite-{label}, inside span.myst-cite-group for groups; missing: span.myst-cite.myst-cite-error
Bibliographysection.myst-bibliography > h2 + ol.myst-bibliography-list > li#cite-{label} (cite-knuth1984; for a DOI cite-doi-10.5281-zenodo.6476040); with numbered citations ol.myst-numbered and li[data-enumerator]. Appended to the page, or where a {bibliography} directive stands.
Footnotessup.myst-footnote-ref > a#fnref-{key} (further references to the same footnote: #fnref-{key}-2, …); section.myst-footnotes > h2.myst-footnotes-title + ol > li#fn-{key}, ending with a.myst-footnote-backref
Admonitionaside.myst-admonition.myst-admonition-{kind} > div.myst-admonition-title + div.myst-admonition-body; with :class: dropdown: details.myst-admonition > summary.myst-admonition-title + div.myst-admonition-body
Dropdowndetails.myst-dropdown > summary.myst-dropdown-title (from {dropdown}; [open] with :open:)
Theorem, proof, exercise, solutionaside.myst-proof.myst-proof-{kind}#id > div.myst-proof-title + div.myst-proof-body; the title holds strong (“Theorem 1”) and the optional title in parentheses
Abstract and other partssection.myst-part.myst-part-{name}[data-part] > h2.myst-part-title, for parts in the body and in the frontmatter (frontmatter abstract, summary and keypoints before the content, other parts after it)
Table of contents ({toc})nav.myst-toc[data-toc-context] around the list of links mystmd builds; data-toc-context is page, project, section or children
Tabsdiv.myst-tabs > (input[type=radio] + label + div.myst-tab-panel)*, working without JavaScript; inputs of tabs with :sync: carry data-myst-sync
Griddiv.myst-grid with --myst-grid-cols-0 … --myst-grid-cols-3
Carddiv.myst-card, or a.myst-card with :link:; inside div.myst-card-header, div.myst-card-title, div.myst-card-footer
Aside, margin note, sidebaraside.myst-aside.myst-aside-{kind}: myst-aside-sidebar for {sidebar}, myst-aside-topic for {topic}; {aside} and {margin} get myst-aside-margin. An optional title is a div.myst-admonition-title. The theme hangs margin notes in the page margin inside an element with the class myst-margin-column.
Glossarydiv.myst-glossary > dl > dt#id + dd
Abbreviation, keyboard, small caps, unitsabbr[title], kbd, span.myst-smallcaps, span.myst-si
Chemical formula ({chem})span.myst-chem with numbers in sub: H<sub>2</sub>O
Inline expression ({eval})span.myst-eval[data-expression] with the result of the executed expression
Buttona.button.myst-button from the {button} role; a button to a label is also a cross-reference, a.myst-xref.button.myst-button
Task list itemli.task-list-item > input[type=checkbox][disabled]
Notebook celldiv.myst-notebook-cell with the code and div.myst-outputs#id
Notebook outputpre.myst-output-stream.stdout (or .stderr), pre.myst-output-error, div.myst-output with an image, div.myst-output.myst-output-html, pre.myst-output with plain text
Hidden cell, input or outputdetails.myst-hidden > summary (“Show code”, “Show output”, “Show cell”) followed by the content
Unknown directive or rolediv.myst-unhandled / span.myst-unhandled with the source in code
Other unknown node typesdiv.myst-{type}, or span.myst-{type} inside paragraphs, headings and captions

Change any of these with a custom renderer.