diff --git a/app/modules/rehype-momiji/rehypeMomiji.ts b/app/modules/rehype-momiji/rehypeMomiji.ts index a52a0ea..a3662f6 100644 --- a/app/modules/rehype-momiji/rehypeMomiji.ts +++ b/app/modules/rehype-momiji/rehypeMomiji.ts @@ -62,13 +62,18 @@ const rehypeMomiji: Plugin = (options: Options = { theme: "github-dark-default", return; } + const filename = codeElem.properties["data-remark-code-filename"] ?? ""; + const highlightCode = defaultHighlighter.codeToHtml(rawCode, { lang: supportedLang, theme: theme ?? "github-dark", }); const container = ` -
${highlightCode}
+
+ ${filename ? `
${filename}
` : ""} + ${highlightCode} +
`; const parsedRoot = parser.parse(container) as Root; diff --git a/app/routes/posts/md_test.mdx b/app/routes/posts/md_test.mdx index bb133aa..2fe32ee 100644 --- a/app/routes/posts/md_test.mdx +++ b/app/routes/posts/md_test.mdx @@ -35,6 +35,6 @@ publishedAt: "2024-09-XX" - 以下は、TypeScriptのサンプルコードです。 -```ts +```ts title="sample.ts" console.log("Hello, TypeScript!"); ```