1- import { visit } from "unist-util-visit" ;
21import { existsSync , readFileSync } from "fs" ;
3- import { join , dirname } from "path" ;
4- import type { Plugin } from "unified" ;
52import type { Root } from "hast" ;
3+ import { dirname , join } from "path" ;
4+ import type { Plugin } from "unified" ;
5+ import { visit } from "unist-util-visit" ;
66
77// Options for the Excalidraw plugin
88interface ExcalidrawOptions {
@@ -14,7 +14,7 @@ interface ExcalidrawOptions {
1414const rehypeExcalidraw : Plugin < [ ExcalidrawOptions ?] , Root > = ( options = { } ) => {
1515 return ( tree , file ) => {
1616 // Track paragraphs that contain Excalidraw diagrams
17- let paragraphsToReplace = [ ] ;
17+ const paragraphsToReplace = [ ] ;
1818
1919 // Find paragraphs containing Excalidraw diagrams
2020 visit ( tree , "element" , ( node ) => {
@@ -49,12 +49,12 @@ const rehypeExcalidraw: Plugin<[ExcalidrawOptions?], Root> = (options = {}) => {
4949 const lightSvgContent = readFileSync ( lightSvgPath , "utf-8" ) ;
5050 const darkSvgContent = readFileSync ( darkSvgPath , "utf-8" ) ;
5151
52- const lightDataUrl = `data:image/svg+xml;base64,${ Buffer . from ( lightSvgContent ) . toString (
53- "base64" ,
54- ) } `;
55- const darkDataUrl = `data:image/svg+xml;base64,${ Buffer . from ( darkSvgContent ) . toString (
56- "base64" ,
57- ) } `;
52+ const lightDataUrl = `data:image/svg+xml;base64,${ Buffer . from (
53+ lightSvgContent ,
54+ ) . toString ( "base64" ) } `;
55+ const darkDataUrl = `data:image/svg+xml;base64,${ Buffer . from (
56+ darkSvgContent ,
57+ ) . toString ( "base64" ) } `;
5858
5959 paragraph . tagName = "div" ;
6060 paragraph . properties = {
@@ -85,7 +85,10 @@ const rehypeExcalidraw: Plugin<[ExcalidrawOptions?], Root> = (options = {}) => {
8585 ] ;
8686 }
8787 } catch ( error ) {
88- console . error ( `Failed to process Excalidraw diagram ${ diagramName } :` , error ) ;
88+ console . error (
89+ `Failed to process Excalidraw diagram ${ diagramName } :` ,
90+ error ,
91+ ) ;
8992 }
9093 }
9194
0 commit comments