From 70f0a09d3041a8ee053c67651fdda15dffc17549 Mon Sep 17 00:00:00 2001 From: Maksim Markelov Date: Wed, 28 Jul 2021 19:33:19 +0300 Subject: [PATCH] Add remark-slug (#862) * Add remark-slug * Add remark-slug in documentation * Add changeset --- .changeset/fluffy-pillows-rule.md | 6 ++++++ docs/src/pages/guides/markdown-content.md | 6 ++---- packages/markdown-support/package.json | 1 + packages/markdown-support/src/index.ts | 2 ++ yarn.lock | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 .changeset/fluffy-pillows-rule.md diff --git a/.changeset/fluffy-pillows-rule.md b/.changeset/fluffy-pillows-rule.md new file mode 100644 index 000000000..4a2441b5b --- /dev/null +++ b/.changeset/fluffy-pillows-rule.md @@ -0,0 +1,6 @@ +--- +'docs': patch +'@astrojs/markdown-support': patch +--- + +Added remark-slug to default plugins diff --git a/docs/src/pages/guides/markdown-content.md b/docs/src/pages/guides/markdown-content.md index 0717ba158..4ef908f6b 100644 --- a/docs/src/pages/guides/markdown-content.md +++ b/docs/src/pages/guides/markdown-content.md @@ -7,11 +7,11 @@ Astro comes with out-of-the-box Markdown support powered by the expansive [remar ## Remark and Rehype Plugins -In addition to custom components inside the [`` component](/guides/markdown-content#astros-markdown-component), Astro comes with [GitHub-flavored Markdown](https://github.github.com/gfm/) support, [Footnotes](https://github.com/remarkjs/remark-footnotes) syntax, [Smartypants](https://github.com/silvenon/remark-smartypants), and syntax highlighting via [Prism](https://prismjs.com/) pre-enabled. +In addition to custom components inside the [`` component](/guides/markdown-content#astros-markdown-component), Astro comes with [GitHub-flavored Markdown](https://github.github.com/gfm/) support, [Footnotes](https://github.com/remarkjs/remark-footnotes) syntax, [Smartypants](https://github.com/silvenon/remark-smartypants), [Remark-slug](https://github.com/remarkjs/remark-slug) and syntax highlighting via [Prism](https://prismjs.com/) pre-enabled. Also, Astro supports third-party plugins for Markdown. You can provide your plugins in `astro.config.mjs`. -> **Note:** Enabling custom `remarkPlugins` or `rehypePlugins` removes Astro's built-in support for [GitHub-flavored Markdown](https://github.github.com/gfm/) support, [Footnotes](https://github.com/remarkjs/remark-footnotes) syntax, [Smartypants](https://github.com/silvenon/remark-smartypants). You must explicitly add these plugins to your `astro.config.mjs` file, if desired. +> **Note:** Enabling custom `remarkPlugins` or `rehypePlugins` removes Astro's built-in support for [GitHub-flavored Markdown](https://github.github.com/gfm/) support, [Footnotes](https://github.com/remarkjs/remark-footnotes) syntax, [Smartypants](https://github.com/silvenon/remark-smartypants), [Remark-slug](https://github.com/remarkjs/remark-slug). You must explicitly add these plugins to your `astro.config.mjs` file, if desired. ## Add a Markdown plugin in Astro @@ -24,7 +24,6 @@ export default { remarkPlugins: [ // Add a Remark plugin that you want to enable for your project. // If you need to provide options for the plugin, you can use an array and put the options as the second item. - // 'remark-slug', // ['remark-autolink-headings', { behavior: 'prepend'}], ], rehypePlugins: [ @@ -44,7 +43,6 @@ You can provide names of the plugins as well as import them: export default { markdownOptions: { remarkPlugins: [ - import('remark-slug'), [import('remark-autolink-headings'), { behavior: 'prepend' }], ], }, diff --git a/packages/markdown-support/package.json b/packages/markdown-support/package.json index d5f10add1..3d9917a79 100644 --- a/packages/markdown-support/package.json +++ b/packages/markdown-support/package.json @@ -25,6 +25,7 @@ "remark-gfm": "^1.0.0", "remark-parse": "^9.0.0", "remark-rehype": "^8.1.0", + "remark-slug": "^6.1.0", "unified": "^9.2.1", "unist-util-map": "^3.0.0" }, diff --git a/packages/markdown-support/src/index.ts b/packages/markdown-support/src/index.ts index 168738ea2..5278d44d6 100644 --- a/packages/markdown-support/src/index.ts +++ b/packages/markdown-support/src/index.ts @@ -12,6 +12,7 @@ import unified from 'unified'; import markdown from 'remark-parse'; import markdownToHtml from 'remark-rehype'; import rehypeStringify from 'rehype-stringify'; +import remarkSlug from 'remark-slug'; export { AstroMarkdownOptions, MarkdownRenderingOptions }; @@ -30,6 +31,7 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp const { headers, rehypeCollectHeaders } = createCollectHeaders(); let parser = unified() .use(markdown) + .use(remarkSlug) .use([remarkExpressions, { addResult: true }]); if (remarkPlugins.length === 0) { diff --git a/yarn.lock b/yarn.lock index 1e7e262fe..4b683212d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8295,7 +8295,7 @@ remark-rehype@^8.1.0: dependencies: mdast-util-to-hast "^10.2.0" -remark-slug@^6.0.0: +remark-slug@^6.0.0, remark-slug@^6.1.0: version "6.1.0" resolved "https://registry.yarnpkg.com/remark-slug/-/remark-slug-6.1.0.tgz#0503268d5f0c4ecb1f33315c00465ccdd97923ce" integrity sha512-oGCxDF9deA8phWvxFuyr3oSJsdyUAxMFbA0mZ7Y1Sas+emILtO+e5WutF9564gDsEN4IXaQXm5pFo6MLH+YmwQ==