Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
taga3s committed Dec 15, 2024
1 parent cdfb8ef commit 64ce8ef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
4 changes: 3 additions & 1 deletion app/packages/rehype-embedded-github-code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const rehypeEmbeddedGithubCode: Plugin<Option[], Root> = (options): Transformer<

const githubCodePromises: Promise<void>[] = [];

const regex = new RegExp(/https:\/\/github\.com\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+\/blob\/[a-zA-Z0-9._-]+\/?[^\s]*/g);

const transform: Transformer<Root> = async (tree) => {
visit(tree, "element", (node, index, parent) => {
if (node.tagName !== "a" || node.properties["data-remark"] !== "remark-embedded-github-code") {
if (node.tagName !== "a" || node.properties.href === undefined || !regex.test(String(node.properties.href))) {
return;
}
if (index === undefined || parent === undefined) {
Expand Down
30 changes: 0 additions & 30 deletions app/packages/remark-embedded-github-code/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import rehypeMermaid from './app/packages/rehype-mermaid/rehypeMermaid'
import remarkEmojiName from './app/packages/remark-emoji-name'
import { remarkAttentionBlock } from './app/packages/remark-attention-block'
import { rehypeAttentionBlock } from './app/packages/rehype-attention-block'
import { remarkEmbeddedGithubCode } from './app/packages/remark-embedded-github-code'
import { rehypeEmbeddedGithubCode } from './app/packages/rehype-embedded-github-code'

export default defineConfig(() => {
Expand All @@ -28,7 +27,7 @@ export default defineConfig(() => {
ssg({ entry: "./app/server.ts" }),
mdx({
jsxImportSource: 'hono/jsx',
remarkPlugins: [remarkGfm, remarkBreaks, remarkFrontmatter, remarkMdxFrontmatter, remarkEmbeddedGithubCode, remarkMomijiCodeFilename, remarkEmojiName, remarkAttentionBlock],
remarkPlugins: [remarkGfm, remarkBreaks, remarkFrontmatter, remarkMdxFrontmatter, remarkMomijiCodeFilename, remarkEmojiName, remarkAttentionBlock],
rehypePlugins: [[rehypeMomiji, { excludeLangs: ['mermaid'] }], rehypeMermaid, [rehypeEmbeddedGithubCode, { githubPAT: "" }], rehypeAttentionBlock],
})
],
Expand Down

0 comments on commit 64ce8ef

Please sign in to comment.