Skip to content

Commit

Permalink
GfmMarkdown remark-github stricter commit hash verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Oct 2, 2024
1 parent 1b2bceb commit 9661b40
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/markdown/gfm-markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import rehypeRaw from "rehype-raw";
import rehypeSanitize from "rehype-sanitize";
import rehypeSlug from "rehype-slug";
import remarkGfm from "remark-gfm";
import remarkGithub, { Options as RemarkGithubOptions } from "remark-github";
import remarkGithub, { defaultBuildUrl, Options as RemarkGithubOptions } from "remark-github";
import { PluggableList } from "unified";
import { AnchorIdSanitizeFixer } from "./anchor-id-sanitize-fixer";
import { alerts } from "./gfm-markdown-alerts";
Expand Down Expand Up @@ -49,7 +49,16 @@ export default function GfmMarkdown(
remarkGfm,
]
if (repository) {
remarkPlugins.push([remarkGithub, {repository} as RemarkGithubOptions])
// https://github.com/remarkjs/remark-github
remarkPlugins.push([remarkGithub, {
repository,
buildUrl(values) {
if (values.type === 'commit' && values.hash.length !== 40 /* SHA-1 */) {
return false
}
return defaultBuildUrl(values)
},
} as RemarkGithubOptions])
}

const rehypePlugins: PluggableList = []
Expand All @@ -65,7 +74,7 @@ export default function GfmMarkdown(
if (allowEmbedHtml) {
rehypePlugins.push(imageHeightFixer)
}
rehypePlugins.push([rehypeGithubAlerts, {alerts: alerts}])
rehypePlugins.push([rehypeGithubAlerts, {alerts}])
rehypePlugins.push(mermaidTransformer)

return (
Expand Down

0 comments on commit 9661b40

Please sign in to comment.