Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster committed May 5, 2024
1 parent e143a54 commit a180089
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/demo/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";

import { getCache } from "@beoe/cache";
import { rehypeGraphviz } from "@beoe/astro-graphviz/rehype";
import { rehypeGraphviz } from "@beoe/rehype-graphviz";
import { rehypeMermaid } from "@beoe/rehype-mermaid";
import { rehypeGnuplot } from "@beoe/rehype-gnuplot";

Expand Down Expand Up @@ -31,7 +31,7 @@ export default defineConfig({
],
markdown: {
rehypePlugins: [
[rehypeGraphviz, { class: className }],
[rehypeGraphviz, { cache, class: className }],
[rehypeMermaid, { cache, class: className, strategy: "class-dark-mode" }],
[rehypeGnuplot, { cache, class: className }],
],
Expand Down
3 changes: 2 additions & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"@beoe/astro-graphviz": "workspace:*",
"@beoe/cache": "workspace:*",
"@beoe/rehype-gnuplot": "workspace:*",
"@beoe/rehype-graphviz": "workspace:*",
"@beoe/rehype-mermaid": "workspace:*",
"astro": "^4.7.1",
"sharp": "^0.33.3",
"svg-pan-zoom-gesture": "^0.0.2",
"typescript": "^5.4.5"
}
}
}
2 changes: 1 addition & 1 deletion packages/demo/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
title: Diagram All The Things (beoe)
title: Diagram All The Things
---

39 changes: 21 additions & 18 deletions packages/rehype-graphviz/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,36 @@ type Engine =
export type RenderGraphvizOptions = {
code: string;
class?: string;
/* it is possible to change layout with in dot file itself */
/* it is possible to change layout with in dot code itself */
engine?: Engine;
};

import { Graphviz } from "@hpcc-js/wasm";
const graphviz = await Graphviz.load();
export const renderGraphviz = (o: RenderGraphvizOptions) =>
processGraphvizSvg(
graphviz.layout(o.code, "svg", o.engine || "dot"),
o.class
);
// import { Graphviz } from "@hpcc-js/wasm";
// const graphviz = await Graphviz.load();
// export const renderGraphviz = (o: RenderGraphvizOptions) =>
// processGraphvizSvg(
// graphviz.layout(o.code, "svg", o.engine || "dot"),
// o.class
// );

// import { waitFor } from "@beoe/rehype-code-hook";
import { waitFor } from "@beoe/rehype-code-hook";
/**
* If all graphviz 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 renderGraphviz = waitFor(
// async () => {
// // @ts-ignore
// const Graphviz = (await import("@hpcc-js/wasm")).Graphviz;
// return await Graphviz.load();
// },
// (graphviz) => (o: RenderGraphvizOptions) =>
// processGraphvizSvg(graphviz.dot(o.code), o.class)
// );
export const renderGraphviz = waitFor(
async () => {
// @ts-ignore
const Graphviz = (await import("@hpcc-js/wasm")).Graphviz;
return await Graphviz.load();
},
(graphviz) => (o: RenderGraphvizOptions) =>
processGraphvizSvg(
graphviz.layout(o.code, "svg", o.engine || "dot"),
o.class
)
);

export { processGraphvizSvg };

Expand Down
2 changes: 0 additions & 2 deletions packages/rehype-mermaid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,5 @@ It support caching the same way as [@beoe/rehype-code-hook](/packages/rehype-cod
## TODO

- write about dark mode
- maybe use `waitFor`
- maybe remove `style="max-width: ..."`
- test `mermaid-isomorphic` options (`css, mermaidConfig, prefix, browser, launchOptions`)
- write tips about styling with CSS
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a180089

Please sign in to comment.