-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MDX] Support remark and rehype plugins, with defaults (#3977)
* feaet: allow remark and rehype plugin config * deps: add remark-gfm, remark-smartypants * feat: add gfm and smartypants by default * test: add GFM and remark plugin tests * feat: preserve default plugins with "extends" * docs: add remarkPlugins * docs: add rehypePlugins * chore: changeset * fix: remove skip from mdx tests * chore: dup hyperlink flavor text * chore: authGen -> autoGen * nit: markdown -> Markdown Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * nit: markdown -> Markdown 1 Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * nit: markdown -> Markdown 2 Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * nit: markdown -> Markdown 3 Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * nit: markdown -> Markdown 4 Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
- Loading branch information
1 parent
d50f46b
commit 19433eb
Showing
8 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/mdx': minor | ||
--- | ||
|
||
Add remarkPlugins and rehypePlugins to config, with the same default plugins as our standard Markdown parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/integrations/mdx/test/fixtures/mdx-remark-plugins/src/pages/with-gfm.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# GitHub-flavored Markdown test | ||
|
||
This should auto-gen a link: https://example.com |
19 changes: 19 additions & 0 deletions
19
packages/integrations/mdx/test/fixtures/mdx-remark-plugins/src/pages/with-toc.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# TOC test | ||
|
||
## Table of contents | ||
|
||
## Section 1 | ||
|
||
Some text! | ||
|
||
### Subsection 1 | ||
|
||
Some subsection test! | ||
|
||
### Subsection 2 | ||
|
||
Oh cool, more text! | ||
|
||
## Section 2 | ||
|
||
And section 2, with a hyperlink to check GFM is preserved: https://handle-me-gfm.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import mdx from '@astrojs/mdx'; | ||
|
||
import { expect } from 'chai'; | ||
import { parseHTML } from 'linkedom'; | ||
import { loadFixture } from '../../../astro/test/test-utils.js'; | ||
import remarkToc from 'remark-toc'; | ||
|
||
const FIXTURE_ROOT = new URL('./fixtures/mdx-remark-plugins/', import.meta.url); | ||
|
||
describe('MDX remark plugins', () => { | ||
it('supports custom remark plugins - TOC', async () => { | ||
const fixture = await loadFixture({ | ||
root: FIXTURE_ROOT, | ||
integrations: [mdx({ | ||
remarkPlugins: [remarkToc], | ||
})], | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/with-toc/index.html'); | ||
const { document } = parseHTML(html); | ||
|
||
const tocLink1 = document.querySelector('ul a[href="#section-1"]'); | ||
expect(tocLink1).to.not.be.null; | ||
}); | ||
|
||
it('applies GitHub-flavored markdown by default', async () => { | ||
const fixture = await loadFixture({ | ||
root: FIXTURE_ROOT, | ||
integrations: [mdx()], | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/with-gfm/index.html'); | ||
const { document } = parseHTML(html); | ||
|
||
const autoGenLink = document.querySelector('a[href="https://example.com"]'); | ||
expect(autoGenLink).to.not.be.null; | ||
}); | ||
|
||
it('preserves default GitHub-flavored markdown with "extends"', async () => { | ||
const fixture = await loadFixture({ | ||
root: FIXTURE_ROOT, | ||
integrations: [mdx({ | ||
remarkPlugins: { extends: [remarkToc] }, | ||
})], | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/with-toc/index.html'); | ||
const { document } = parseHTML(html); | ||
|
||
const tocLink1 = document.querySelector('ul a[href="#section-1"]'); | ||
expect(tocLink1).to.not.be.null; | ||
const autoGenLink = document.querySelector('a[href="https://handle-me-gfm.com"]'); | ||
expect(autoGenLink).to.not.be.null; | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.