@prosefly/astro-components
v0.9.0
Published
Reusable Astro components for MDX content.
Maintainers
Readme
@prosefly/astro-components
Reusable Astro components for MDX content.
Prosefly natively supports these components in its visual editor, so authors can create and edit content with Prosefly components visually.
Install
Install the package in an Astro v7 project:
pnpm add @prosefly/astro-componentsIf your site renders .mdx pages, make sure MDX is configured in Astro first.
Dahlia and
Lotus projects already include MDX,
the shared integration, icon preloading, and their docs shell.
---
import { Callout } from '@prosefly/astro-components';
---
<Callout type="tip" title="Reusable">
Package components use Prosefly CSS custom properties with built-in fallbacks.
</Callout>Full documentation is available at astro-components.prosefly.dev.
Shared integration
For a standalone Astro site, register
@prosefly/astro-components/integration to configure icon preloading, shared
Markdown transforms, and their styles and client runtimes together:
import { defineConfig } from 'astro/config';
import proseflyComponents from '@prosefly/astro-components/integration';
export default defineConfig({
integrations: [proseflyComponents()],
});Exports
The main entry exports:
AccordionItemandAccordionsAudioPlayerBadgeCalloutCardandCardGridFileTreeIconImageGalleryStepsTabItemandTabsVideoPlayer
The /integration entry exports the proseflyComponents() Astro integration and its
ComponentsIntegrationOptions type.
The markdown entry exports:
rehypeMermaidrehypeVideoPlayerremarkImageGalleryremarkPackageManagerTabs
Advanced icon-only setup
Use /integration for the usual setup. The standalone
@prosefly/astro-components/icon entry remains available when a project wants
only Iconify preloading without Markdown transforms or the full Dahlia or Lotus
theme:
import { defineConfig } from 'astro/config';
import proseflyIcon from '@prosefly/astro-components/icon';
export default defineConfig({
integrations: [
proseflyIcon({
preload: ['lucide:star', 'simple-icons:github'],
}),
],
});The integration can scan src/**/*.astro, src/**/*.md, and src/**/*.mdx
for static icon usage. Set scan: false to disable that behavior or apiBase
to point at an internal Iconify-compatible endpoint.
Independent Markdown transforms
Use /integration for the normal Markdown setup. It enables callouts,
package-manager tabs, image galleries, and video figures in both .md and
.mdx files. The
@prosefly/astro-components/markdown entry remains available for advanced
processor composition:
import { defineConfig } from 'astro/config';
import {
rehypeMermaid,
remarkImageGallery,
remarkPackageManagerTabs,
unified,
} from '@prosefly/astro-components/markdown';
export default defineConfig({
markdown: {
syntaxHighlight: {
type: 'shiki',
excludeLangs: ['math', 'mermaid'],
},
processor: unified({
remarkPlugins: [remarkImageGallery, remarkPackageManagerTabs],
rehypePlugins: [rehypeMermaid],
}),
},
});remarkPackageManagerTabs recognizes common npm commands and can generate
tabs for Node and Python package managers. remarkImageGallery generates gallery
HTML in Markdown and MDX while preserving the original image nodes for Astro
optimization. Use proseflyComponents() to load gallery CSS and runtime
automatically. rehypeMermaid renders mermaid code blocks as
static SVG; direct use requires excluding mermaid from Astro syntax
highlighting. Dahlia and Lotus enable these transforms through the shared
integration by default.
VideoPlayer loops short clips silently while visible and uses native controls
for long videos. proseflyComponents() enables automatic video-figure conversion
in Markdown and MDX by default, including when registered by Dahlia or Lotus. Disable it
with proseflyComponents({ markdown: { videoPlayer: false } }), or register
rehypeVideoPlayer directly when not using the integration. Both accept
{ shortVideoSeconds: 30, labels: { play: 'Play' } } configuration (via
markdown.videoPlayer for the integration). HTML attributes, sources, tracks,
and rich captions are preserved, and no media is fetched at build time.
Audio and mixed-content figures are unchanged. Automatic transforms generate
HTML without importing Astro components; the shared integration loads their
styles and browser runtimes.
Independent Expressive Code plugin
Expressive Code is intentionally separate from proseflyComponents(). Install
astro-expressive-code and register
expressiveCodeHeaderIcons() in its plugins option:
pnpm add astro-expressive-codeimport { defineConfig } from 'astro/config';
import astroExpressiveCode from 'astro-expressive-code';
import { expressiveCodeHeaderIcons } from '@prosefly/astro-components/expressive-code';
export default defineConfig({
integrations: [
astroExpressiveCode({
plugins: [expressiveCodeHeaderIcons()],
}),
],
});Pass { apiBase: 'https://example.com' } to use an Iconify-compatible endpoint
for code-header icons. Dahlia and Lotus already configure this plugin; do not
register it a second time in those themes.
The /expressive-code entry publicly exports only
expressiveCodeHeaderIcons and the ExpressiveCodeHeaderIconsOptions type.
The icon and language-label helpers used by the plugin are internal.
Local Development And Publishing
Workspace exports point to src, so pnpm dev runs the documentation site
directly against the components and TypeScript source with hot reload. It does
not require a package build first. Local site builds also consume source.
pnpm test builds and tests dist, then packs the package and verifies its
published entry points. pnpm pack and pnpm publish override exports and
types using publishConfig; only dist, the README, and license are shipped.
The prepack hook builds the package automatically.
Use pnpm to pack or publish from the source checkout. If publishing with npm
(for example, for trusted publishing), first create a tarball with pnpm pack,
then run npm publish ./prosefly-astro-components-<version>.tgz. Do not run
npm publish directly against the source directory: npm does not apply these
manifest overrides.
Styling
Consumers can theme the components with --pf-* custom properties:
--pf-text-strong--pf-text--pf-text-muted--pf-background--pf-surface--pf-accent--pf-accent-soft--pf-accent-contrast--pf-{info|success|warning|danger}--pf-{info|success|warning|danger}-soft--pf-{info|success|warning|danger}-ink--pf-{info|success|warning|danger}-contrast--pf-callout-{note|tip|warning|danger}-{color|ink|bg}--pf-border-subtle--pf-font-sans--pf-font-mono--pf-radius-sm--pf-radius-md--pf-radius-lg--pf-radius-full
