@fujocoded/remark-excalidraw
v0.1.0
Published
Load excalidraw diagrams via remark
Maintainers
Readme
@fujocoded/remark-excalidraw
What is @fujocoded/remark-excalidraw?
@fujocoded/remark-excalidraw is a remark plugin that turns Markdown image
links to .excalidraw files into client-rendered Excalidraw drawings in MDX.
To do that, it:
- Reads the linked
.excalidrawfile during your build - Embeds the drawing content into the generated MDX
- Imports the Excalidraw React renderer for you
- Adds width and height when it can read the scene bounds
[!NOTE] If the scene cannot be parsed, the drawing still renders in the browser without the extra size hints.
What's included in @fujocoded/remark-excalidraw?
remarkExcalidraw, the default remark pluginPluginArgs, the options type for the pluginExcalidrawWrapperOptions, the options type for wrapping drawingsExcalidrawWrapperContext, the data passed to wrapper callbacksExcalidrawComponent(from@fujocoded/remark-excalidraw/component), the React component used by generated MDX
What can you do with @fujocoded/remark-excalidraw?
- Keep Excalidraw drawings next to your Markdown and render them as page content
- Give each drawing stable width and height so the page does not jump while the renderer loads
- Wrap drawings in your own MDX component for captions, links, zoom controls, or layout
- Preserve string HTML attributes that another remark plugin placed on the original image
Setup
Run the following command:
npm install @fujocoded/remark-excalidrawAdd the plugin to your MDX config:
import mdx from "@astrojs/mdx"; import remarkExcalidraw from "@fujocoded/remark-excalidraw"; import { defineConfig } from "astro/config"; export default defineConfig({ // ... integrations: [ mdx({ remarkPlugins: [remarkExcalidraw], }), ], });Link an Excalidraw file from Markdown:

Okay how do I actually see this in action?
Want a small Astro project you can copy from? See
__example__/.
Configuring wrappers
To put your own component around each drawing, pass wrapper:
import mdx from "@astrojs/mdx";
import remarkExcalidraw from "@fujocoded/remark-excalidraw";
import { defineConfig } from "astro/config";
export default defineConfig({
integrations: [
mdx({
remarkPlugins: [
[
remarkExcalidraw,
{
wrapper: {
name: "ZoomableFigure",
importPath: "../components/ZoomableFigure.astro",
attributes: ({ alt, fileName }) => ({
id: fileName,
linkLabel: `Open this diagram in another window`,
}),
},
},
],
],
}),
],
});The wrapper options are:
name=> Required. Names the MDX component that wraps each drawingimportPath=> Optional. Importsnamefrom this path when you want the generated MDX to add the import for you. When omitted, the wrapper is used without adding an importattributes=> Optional. Adds attributes to the wrapper component. Pass an object for fixed attributes, or a function when the attributes need the drawingalt,fileName,imageUrl,markdownPath, orsourcePathexportPadding=> Optional. Sets how many pixels of padding are added to each side of the inferred drawing bounds. When omitted, the plugin uses10
