From 8bdad0b2fcad3c5e06f9f7ad59dd85a3d51d7024 Mon Sep 17 00:00:00 2001 From: saicaca Date: Sat, 22 Jun 2024 01:31:29 +0800 Subject: [PATCH] feat: add support for GitHub style admonition syntax --- astro.config.mjs | 4 ++-- package.json | 1 + pnpm-lock.yaml | 15 +++++++++++++++ src/content/posts/markdown-extended.md | 11 +++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 4245936..1257656 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -11,7 +11,7 @@ import { remarkReadingTime } from "./src/plugins/remark-reading-time.mjs" import { GithubCardComponent } from "./src/plugins/rehype-component-github-card.mjs" import { AdmonitionComponent } from "./src/plugins/rehype-component-admonition.mjs" import remarkDirective from "remark-directive" /* Handle directives */ -import remarkDirectiveRehype from 'remark-directive-rehype' /* Pass directives to rehype */ +import remarkGithubAdmonitionsToDirectives from "remark-github-admonitions-to-directives"; import rehypeComponents from "rehype-components"; /* Render the custom directive content */ import svelte from "@astrojs/svelte" import swup from '@swup/astro'; @@ -60,7 +60,7 @@ export default defineConfig({ sitemap(), ], markdown: { - remarkPlugins: [remarkMath, remarkReadingTime, remarkDirective, parseDirectiveNode], + remarkPlugins: [remarkMath, remarkReadingTime, remarkGithubAdmonitionsToDirectives, remarkDirective, parseDirectiveNode], rehypePlugins: [ rehypeKatex, rehypeSlug, diff --git a/package.json b/package.json index b04997e..725aa8d 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "@types/markdown-it": "^14.1.1", "@types/mdast": "^4.0.4", "@types/sanitize-html": "^2.11.0", + "remark-github-admonitions-to-directives": "^1.0.5", "stylus": "^0.63.0" }, "pnpm": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cea6f41..6528b76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -142,6 +142,9 @@ importers: '@types/sanitize-html': specifier: ^2.11.0 version: 2.11.0 + remark-github-admonitions-to-directives: + specifier: ^1.0.5 + version: 1.0.5 stylus: specifier: ^0.63.0 version: 0.63.0 @@ -3918,6 +3921,9 @@ packages: remark-gfm@4.0.0: resolution: {integrity: sha512-U92vJgBPkbw4Zfu/IiW2oTZLSL3Zpv+uI7My2eq8JxKgqraFdU8YUGicEJCEgSbeaG+QDFqIcwwfMTOEelPxuA==} + remark-github-admonitions-to-directives@1.0.5: + resolution: {integrity: sha512-MSRzDs51HGbUrHJ0es8POuxwJiUycWw4aYCTN2RZhdOm5UvyqdB8ApWoGBj9QAiPSHKw2HWl1hd5rRzWxVfNew==} + remark-math@6.0.0: resolution: {integrity: sha512-MMqgnP74Igy+S3WwnhQ7kqGlEerTETXMvJhrUzDikVZ2/uogJCb+WHUg97hK9/jcfc0dkD73s3LN8zU49cTEtA==} @@ -9235,6 +9241,15 @@ snapshots: transitivePeerDependencies: - supports-color + remark-github-admonitions-to-directives@1.0.5: + dependencies: + '@types/mdast': 4.0.4 + mdast-util-directive: 3.0.0 + unified: 11.0.5 + unist-util-visit: 5.0.0 + transitivePeerDependencies: + - supports-color + remark-math@6.0.0: dependencies: '@types/mdast': 4.0.4 diff --git a/src/content/posts/markdown-extended.md b/src/content/posts/markdown-extended.md index 3e50770..258d7ea 100644 --- a/src/content/posts/markdown-extended.md +++ b/src/content/posts/markdown-extended.md @@ -63,4 +63,15 @@ This is a note with a custom title. :::note[MY CUSTOM TITLE] This is a note with a custom title. ::: +``` + +> [!TIP] +> [The GitHub syntax](https://github.com/orgs/community/discussions/16925) is also supported. + +``` +> [!NOTE] +> The GitHub syntax is also supported. + +> [!TIP] +> The GitHub syntax is also supported. ``` \ No newline at end of file