API

Props and CSS variables

Everything you can pass to <MarkdownBlock>, and every variable you can set to restyle it.

Props

PropTypeDefaultDescription
sourcestring—Required. The Markdown to render and to copy.
titlestring—Optional label in the toolbar, before the mode.
defaultMode'preview' | 'markdown''preview'Which view shows first.
heightstring | number'24rem'Height of the scrolling body. A number is pixels.
remarkPluginsPluggableList[remarkGfm]Replaces the default remark plugins. The default is remark-gfm.
rehypePluginsPluggableListexternal linksReplaces the default rehype plugins. The default opens external links in a new tab with rel="noopener noreferrer".
componentsComponents—Custom element renderers, forwarded to react-markdown.
labelsPartial<MarkdownBlockLabels>built-inOverrides any of preview, markdown, copy, copied, and wrap. Defaults: Preview, Markdown, Copy, Copied, Word wrap.
classNamestring—Extra class on the root element, for theme variables or layout.
classNamesPartial<Record<MarkdownBlockPart, string>>—Extra classes for root, toolbar, title, actions, button, body, preview, or source.

Passing remarkPlugins or rehypePluginsreplaces the defaults. Include remark-gfm in your list if you still want GitHub-flavored Markdown. The types MarkdownBlockProps, MarkdownBlockLabels, and MarkdownBlockPart are exported.

CSS variables

Set these on a class and pass that class as className.

VariableControls
--amb-bgBackground of the block
--amb-fgText color
--amb-mutedSecondary text, such as the mode label
--amb-borderBorders and table lines
--amb-toolbar-bgToolbar and table header background
--amb-button-bgButton background
--amb-button-hoverButton hover background
--amb-accentPressed wrap button and focus ring
--amb-accent-fgText on the accent color
--amb-code-bgInline code and code block background
--amb-linkLink color in the preview
--amb-radiusCorner radius
--amb-font-sansFont for the toolbar and preview
--amb-font-monoFont for the raw source

Package

Version
0.1.1
License
MIT
Compatibility
React >=18, and Astro with @astrojs/react
Module format
ESM
TypeScript
Types included
Peer dependencies
react >=18
Dependencies
react-markdown ^10.1.0, rehype-external-links ^3.0.0, remark-gfm ^4.0.1
JavaScript
5.7 KB (1.7 KB gzip)
CSS
5.2 KB (1.4 KB gzip)

JavaScript and CSS sizes are measured from this package's built files. React, react-markdown, remark-gfm, and rehype-external-links install separately.