Skip to content

Commit

Permalink
feat: show filename ui above the code block
Browse files Browse the repository at this point in the history
  • Loading branch information
taga3s committed Sep 10, 2024
1 parent 6aa4f1c commit 1d3fa42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/modules/rehype-momiji/rehypeMomiji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<div>${highlightCode}</div>
<div style="display: flex; flex-direction: column; gap: 2px;">
${filename ? `<div style="width: fit-content; padding: 4px 8px; font-size: 14px; color: white; background-color: gray;">${filename}</div>` : ""}
${highlightCode}
</div>
`;

const parsedRoot = parser.parse(container) as Root;
Expand Down
2 changes: 1 addition & 1 deletion app/routes/posts/md_test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ publishedAt: "2024-09-XX"

- 以下は、TypeScriptのサンプルコードです。

```ts
```ts title="sample.ts"
console.log("Hello, TypeScript!");
```

0 comments on commit 1d3fa42

Please sign in to comment.