Add remark-slug (#862)
* Add remark-slug * Add remark-slug in documentation * Add changeset
This commit is contained in:
parent
5e3e828a44
commit
70f0a09d30
5 changed files with 12 additions and 5 deletions
6
.changeset/fluffy-pillows-rule.md
Normal file
6
.changeset/fluffy-pillows-rule.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
'docs': patch
|
||||||
|
'@astrojs/markdown-support': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Added remark-slug to default plugins
|
|
@ -7,11 +7,11 @@ Astro comes with out-of-the-box Markdown support powered by the expansive [remar
|
||||||
|
|
||||||
## Remark and Rehype Plugins
|
## Remark and Rehype Plugins
|
||||||
|
|
||||||
In addition to custom components inside the [`<Markdown>` 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 [`<Markdown>` 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`.
|
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
|
## Add a Markdown plugin in Astro
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ export default {
|
||||||
remarkPlugins: [
|
remarkPlugins: [
|
||||||
// Add a Remark plugin that you want to enable for your project.
|
// 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.
|
// 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'}],
|
// ['remark-autolink-headings', { behavior: 'prepend'}],
|
||||||
],
|
],
|
||||||
rehypePlugins: [
|
rehypePlugins: [
|
||||||
|
@ -44,7 +43,6 @@ You can provide names of the plugins as well as import them:
|
||||||
export default {
|
export default {
|
||||||
markdownOptions: {
|
markdownOptions: {
|
||||||
remarkPlugins: [
|
remarkPlugins: [
|
||||||
import('remark-slug'),
|
|
||||||
[import('remark-autolink-headings'), { behavior: 'prepend' }],
|
[import('remark-autolink-headings'), { behavior: 'prepend' }],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"remark-gfm": "^1.0.0",
|
"remark-gfm": "^1.0.0",
|
||||||
"remark-parse": "^9.0.0",
|
"remark-parse": "^9.0.0",
|
||||||
"remark-rehype": "^8.1.0",
|
"remark-rehype": "^8.1.0",
|
||||||
|
"remark-slug": "^6.1.0",
|
||||||
"unified": "^9.2.1",
|
"unified": "^9.2.1",
|
||||||
"unist-util-map": "^3.0.0"
|
"unist-util-map": "^3.0.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,6 +12,7 @@ import unified from 'unified';
|
||||||
import markdown from 'remark-parse';
|
import markdown from 'remark-parse';
|
||||||
import markdownToHtml from 'remark-rehype';
|
import markdownToHtml from 'remark-rehype';
|
||||||
import rehypeStringify from 'rehype-stringify';
|
import rehypeStringify from 'rehype-stringify';
|
||||||
|
import remarkSlug from 'remark-slug';
|
||||||
|
|
||||||
export { AstroMarkdownOptions, MarkdownRenderingOptions };
|
export { AstroMarkdownOptions, MarkdownRenderingOptions };
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
|
||||||
const { headers, rehypeCollectHeaders } = createCollectHeaders();
|
const { headers, rehypeCollectHeaders } = createCollectHeaders();
|
||||||
let parser = unified()
|
let parser = unified()
|
||||||
.use(markdown)
|
.use(markdown)
|
||||||
|
.use(remarkSlug)
|
||||||
.use([remarkExpressions, { addResult: true }]);
|
.use([remarkExpressions, { addResult: true }]);
|
||||||
|
|
||||||
if (remarkPlugins.length === 0) {
|
if (remarkPlugins.length === 0) {
|
||||||
|
|
|
@ -8295,7 +8295,7 @@ remark-rehype@^8.1.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
mdast-util-to-hast "^10.2.0"
|
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"
|
version "6.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/remark-slug/-/remark-slug-6.1.0.tgz#0503268d5f0c4ecb1f33315c00465ccdd97923ce"
|
resolved "https://registry.yarnpkg.com/remark-slug/-/remark-slug-6.1.0.tgz#0503268d5f0c4ecb1f33315c00465ccdd97923ce"
|
||||||
integrity sha512-oGCxDF9deA8phWvxFuyr3oSJsdyUAxMFbA0mZ7Y1Sas+emILtO+e5WutF9564gDsEN4IXaQXm5pFo6MLH+YmwQ==
|
integrity sha512-oGCxDF9deA8phWvxFuyr3oSJsdyUAxMFbA0mZ7Y1Sas+emILtO+e5WutF9564gDsEN4IXaQXm5pFo6MLH+YmwQ==
|
||||||
|
|
Loading…
Reference in a new issue