@beoe/rehype-gnuplot
Version:
rehype gnuplot plugin
18 lines (17 loc) • 663 B
JavaScript
import { rehypeCodeHookImg } from "@beoe/rehype-code-hook-img";
import { waitFor } from "@beoe/rehype-code-hook";
/**
* If all gnuplot diagrams are cached it would not even load module in memory.
* If there are diagrams, it would load module and first few renders would be async,
* but all consequent renders would be sync
*/
export const render = waitFor(async () => {
// @ts-ignore
const gnuplot = (await import("gnuplot-wasm")).default;
return gnuplot().then(({ render }) => render);
}, (render) => (code) => render(code));
export const rehypeGnuplot = rehypeCodeHookImg({
language: "gnuplot",
render,
});
export default rehypeGnuplot;