feat: add support for GitHub style admonition syntax

This commit is contained in:
saicaca 2024-06-22 01:31:29 +08:00
parent 176b38a4cb
commit 8bdad0b2fc
4 changed files with 29 additions and 2 deletions

View File

@ -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,

View File

@ -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": {

View File

@ -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

View File

@ -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.
```