Skip to content

Commit

Permalink
refactor(markdown): removed rehype-slug in favor of our own impleme…
Browse files Browse the repository at this point in the history
…ntation (withastro#3234)

* Moved types arround

* Removed `rehype-slug` in favor of our own implementation

* Changeset

* Removed rehype-slug from examples

* Remove rehype-slug from tests

* Updated reference

* rehypeCollectHeaders is a function again

* Reverted rehype-slug removes

* Re-added rehype-slug to reference
  • Loading branch information
JuanM04 authored Apr 30, 2022
1 parent 03a8552 commit 8aaa3c4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
"prismjs": "^1.28.0",
"prompts": "^2.4.2",
"recast": "^0.20.5",
"rehype-slug": "^5.0.1",
"resolve": "^1.22.0",
"rollup": "^2.70.2",
"semver": "^7.3.7",
Expand Down
31 changes: 12 additions & 19 deletions src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import type { AddressInfo } from 'net';
import type * as babel from '@babel/core';
import type * as vite from 'vite';
import { z } from 'zod';
import type { ShikiConfig, RemarkPlugins, RehypePlugins } from '@astrojs/markdown-remark';
import type {
ShikiConfig,
RemarkPlugins,
RehypePlugins,
MarkdownHeader,
MarkdownMetadata,
MarkdownRenderingResult,
} from '@astrojs/markdown-remark';
import type { AstroConfigSchema } from '../core/config';
import type { AstroComponentFactory, Metadata } from '../runtime/server';
import type { ViteConfigWithSSR } from '../core/create-vite';
Expand Down Expand Up @@ -530,7 +537,7 @@ export interface AstroUserConfig {
* @description
* Pass a custom [Remark](https://github.com/remarkjs/remark) plugin to customize how your Markdown is built.
*
* **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 and [Smartypants](https://github.com/silvenon/remark-smartypants). You must explicitly add these plugins to your `astro.config.mjs` file, if desired.
*
* ```js
* {
Expand All @@ -549,13 +556,13 @@ export interface AstroUserConfig {
* @description
* Pass a custom [Rehype](https://github.com/remarkjs/remark-rehype) plugin to customize how your Markdown is built.
*
* **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 and [Smartypants](https://github.com/silvenon/remark-smartypants). You must explicitly add these plugins to your `astro.config.mjs` file, if desired.
*
* ```js
* {
* markdown: {
* // Example: The default set of rehype plugins used by Astro
* rehypePlugins: [['rehype-toc', { headings: ['h2', 'h3'] }], [addClasses, { 'h1,h2,h3': 'title' }], 'rehype-slug'],
* rehypePlugins: ['rehype-slug', ['rehype-toc', { headings: ['h2', 'h3'] }], [addClasses, { 'h1,h2,h3': 'title' }]],
* },
* };
* ```
Expand Down Expand Up @@ -774,24 +781,10 @@ export interface ManifestData {
routes: RouteData[];
}

export interface MarkdownHeader {
depth: number;
slug: string;
text: string;
}

export interface MarkdownMetadata {
headers: MarkdownHeader[];
source: string;
html: string;
}

export interface MarkdownParserResponse {
export interface MarkdownParserResponse extends MarkdownRenderingResult {
frontmatter: {
[key: string]: any;
};
metadata: MarkdownMetadata;
code: string;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/astro-markdown-plugins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe('Astro Markdown plugins', () => {
['rehype-autolink-headings', { behavior: 'prepend' }],
],
rehypePlugins: [
'rehype-slug',
['rehype-toc', { headings: ['h2', 'h3'] }],
[addClasses, { 'h1,h2,h3': 'title' }],
'rehype-slug',
],
},
});
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/astro-markdown-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@astrojs/preact": "workspace:*",
"astro": "workspace:*",
"hast-util-select": "^5.0.1"
"hast-util-select": "^5.0.1",
"rehype-slug": "^5.0.1"
}
}

0 comments on commit 8aaa3c4

Please sign in to comment.