-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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-rehype options from Astro Markdown config (#5427)
* [MDX] Support remark-rehype options from Astro Markdown config * [MDX] Add remarkRehype to MdxOptions, extend with default markdown config * [MDX] Add remarkRehype to README * [MDX] Fix remarkRehype inheritance, add tests * [MDX] Update remarkRehype docs in README Co-authored-by: Sarah Rainsberger <[email protected]> * [MDX] Fix remarkRehype docs Co-authored-by: Sarah Rainsberger <[email protected]>
- Loading branch information
1 parent
fcada72
commit 2a1c085
Showing
7 changed files
with
126 additions
and
7 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 | ||
--- | ||
|
||
Uses remark-rehype options from astro.config.mjs |
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
5 changes: 5 additions & 0 deletions
5
...egrations/mdx/test/fixtures/mdx-astro-markdown-remarkRehype/src/pages/index.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,5 @@ | ||
# Hello world | ||
|
||
This[^1] should be visible. | ||
|
||
[^1]: And there would be a footnote. |
81 changes: 81 additions & 0 deletions
81
packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js
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,81 @@ | ||
import mdx from '@astrojs/mdx'; | ||
|
||
import { expect } from 'chai'; | ||
import { parseHTML } from 'linkedom'; | ||
import { loadFixture } from '../../../astro/test/test-utils.js'; | ||
|
||
describe('MDX with Astro Markdown remark-rehype config', () => { | ||
it('Renders footnotes with values from the default configuration', async () => { | ||
const fixture = await loadFixture({ | ||
root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url), | ||
integrations: [mdx()], | ||
markdown: { | ||
remarkRehype: { | ||
footnoteLabel: 'Catatan kaki', | ||
footnoteBackLabel: 'Kembali ke konten', | ||
}, | ||
}, | ||
}); | ||
|
||
await fixture.build(); | ||
const html = await fixture.readFile('/index.html'); | ||
const { document } = parseHTML(html); | ||
|
||
expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki'); | ||
expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal( | ||
'Kembali ke konten' | ||
); | ||
}); | ||
|
||
it('Renders footnotes with values from custom configuration extending the default', async () => { | ||
const fixture = await loadFixture({ | ||
root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url), | ||
integrations: [mdx({ | ||
remarkRehype: { | ||
footnoteLabel: 'Catatan kaki', | ||
footnoteBackLabel: 'Kembali ke konten', | ||
}, | ||
})], | ||
markdown: { | ||
remarkRehype: { | ||
footnoteBackLabel: 'Replace me', | ||
}, | ||
}, | ||
}); | ||
|
||
await fixture.build(); | ||
const html = await fixture.readFile('/index.html'); | ||
const { document } = parseHTML(html); | ||
|
||
expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki'); | ||
expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal( | ||
'Kembali ke konten' | ||
); | ||
}); | ||
|
||
it('Renders footnotes with values from custom configuration without extending the default', async () => { | ||
const fixture = await loadFixture({ | ||
root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url), | ||
integrations: [mdx({ | ||
extendPlugins: 'astroDefaults', | ||
remarkRehype: { | ||
footnoteLabel: 'Catatan kaki', | ||
}, | ||
})], | ||
markdown: { | ||
remarkRehype: { | ||
footnoteBackLabel: 'Kembali ke konten', | ||
}, | ||
}, | ||
}); | ||
|
||
await fixture.build(); | ||
const html = await fixture.readFile('/index.html'); | ||
const { document } = parseHTML(html); | ||
|
||
expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki'); | ||
expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal( | ||
'Back to content' | ||
); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.