diff --git a/app/packages/rehype-mermaid/README.md b/app/packages/rehype-mermaid/README.md
index f06f4d6..9ee180d 100644
--- a/app/packages/rehype-mermaid/README.md
+++ b/app/packages/rehype-mermaid/README.md
@@ -5,7 +5,3 @@
## features
- Generating Mermaid Diagrams
-
-## How to use?
-
-
diff --git a/app/packages/rehype-mermaid/docs/assets/rehype-mermaid-sample.png b/app/packages/rehype-mermaid/docs/assets/rehype-mermaid-sample.png
deleted file mode 100644
index e5e95a2..0000000
Binary files a/app/packages/rehype-mermaid/docs/assets/rehype-mermaid-sample.png and /dev/null differ
diff --git a/app/packages/rehype-mermaid/rehypeMermaid.ts b/app/packages/rehype-mermaid/rehypeMermaid.ts
index b445c7f..c1b7107 100644
--- a/app/packages/rehype-mermaid/rehypeMermaid.ts
+++ b/app/packages/rehype-mermaid/rehypeMermaid.ts
@@ -1,4 +1,4 @@
-import type { Plugin } from "unified";
+import type { Plugin, Transformer } from "unified";
import type { Text, Parent, Root } from "hast";
import { visit } from "unist-util-visit";
import { renderMermaid } from "@mermaid-js/mermaid-cli";
@@ -23,8 +23,8 @@ const rehypeMermaid: Plugin<[], Root> = () => {
const checkIsMermaid = (lang: string): boolean => lang === "mermaid";
- return async (tree) => {
- const mermaidCodeBlocks: MermaidCodeBlock[] = [];
+ const transformer: Transformer = async (tree) => {
+ const mermaidCodeBlockPromises: MermaidCodeBlock[] = [];
visit(tree, "element", (node, index, parent) => {
// Check if the node is a pre tag with a single child
@@ -61,11 +61,11 @@ const rehypeMermaid: Plugin<[], Root> = () => {
const isMermaid = checkIsMermaid(lang);
if (isMermaid && index && parent) {
- mermaidCodeBlocks.push({ textNode, index, parent });
+ mermaidCodeBlockPromises.push({ textNode, index, parent });
}
});
- if (mermaidCodeBlocks.length === 0) {
+ if (mermaidCodeBlockPromises.length === 0) {
return;
}
@@ -76,7 +76,7 @@ const rehypeMermaid: Plugin<[], Root> = () => {
const decoder = new TextDecoder();
await Promise.all(
- mermaidCodeBlocks.map(async ({ textNode, index, parent }, blockIndex) => {
+ mermaidCodeBlockPromises.map(async ({ textNode, index, parent }, blockIndex) => {
const { data: svgBuffer } = await renderMermaid(browser, textNode.value, "svg");
const svgElem = decoder.decode(svgBuffer).replaceAll("my-svg", `my-svg-${blockIndex}`);
@@ -95,6 +95,8 @@ const rehypeMermaid: Plugin<[], Root> = () => {
await browser.close();
};
+
+ return transformer;
};
export default rehypeMermaid;
diff --git a/app/packages/rehype-momiji/README.md b/app/packages/rehype-momiji/README.md
index 8ccf8da..e151c89 100644
--- a/app/packages/rehype-momiji/README.md
+++ b/app/packages/rehype-momiji/README.md
@@ -1,4 +1,4 @@
-# rehype-momiji (in development)
+# rehype-momiji
[rehype](https://github.com/rehypejs/rehype) plugin powered by [shiki](https://shiki.matsu.io/).
@@ -9,6 +9,4 @@
## How to use?
-When you want only highlighting code block, just use this package. If you want to display a filename, you also need to use `remark-momiji`.
-
-
+When you want only highlighting code block, just use this package. If you want to display a filename, you also need to use `remark-momiji-title`.
diff --git a/app/packages/rehype-momiji/buildCodeBlock.ts b/app/packages/rehype-momiji/buildCodeBlock.ts
index 933dc27..99adf5b 100644
--- a/app/packages/rehype-momiji/buildCodeBlock.ts
+++ b/app/packages/rehype-momiji/buildCodeBlock.ts
@@ -1,6 +1,6 @@
import type { BundledLanguage, HighlighterGeneric, BundledTheme } from "shiki";
import { COLOR_SHIRONERI, COLOR_HAI } from "./colors";
-import type { Root } from "hast";
+import type { Element } from "hast";
const buildCodeBlock = (
highlighter: HighlighterGeneric,
@@ -10,7 +10,7 @@ const buildCodeBlock = (
filename: string,
filenameBGColor?: string,
filenameTextColor?: string,
-): Root => {
+): Element | undefined => {
const hast = highlighter.codeToHast(rawCode, {
lang: lang,
theme: theme,
@@ -50,7 +50,11 @@ const buildCodeBlock = (
],
});
- return hast;
+ if (hast.children[0].type !== "element") {
+ return;
+ }
+
+ return hast.children[0];
};
export { buildCodeBlock };
diff --git a/app/packages/rehype-momiji/docs/assets/rehype-momiji-sample.png b/app/packages/rehype-momiji/docs/assets/rehype-momiji-sample.png
deleted file mode 100644
index 7ca4ef6..0000000
Binary files a/app/packages/rehype-momiji/docs/assets/rehype-momiji-sample.png and /dev/null differ
diff --git a/app/packages/rehype-momiji/index.ts b/app/packages/rehype-momiji/index.ts
index 1464377..997a739 100644
--- a/app/packages/rehype-momiji/index.ts
+++ b/app/packages/rehype-momiji/index.ts
@@ -93,23 +93,24 @@ const rehypeMomiji: Plugin