-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: handle all admonitions via JSX component (#7152)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
- Loading branch information
1 parent
17fe43e
commit 5746c58
Showing
39 changed files
with
708 additions
and
249 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
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
45 changes: 45 additions & 0 deletions
45
packages/docusaurus-mdx-loader/src/remark/admonitions/LICENSE
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,45 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Elvis Wolcott | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
--- | ||
|
||
MIT License | ||
|
||
Copyright (c) Facebook, Inc. and its affiliates. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
3 changes: 3 additions & 0 deletions
3
packages/docusaurus-mdx-loader/src/remark/admonitions/README.md
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 @@ | ||
# Docusaurus admonitions | ||
|
||
Code from [remark-admonitions](https://github.com/remarkjs/remark-directive) (MIT license) has been copied to this folder, and highly customized for Docusaurus needs. |
25 changes: 25 additions & 0 deletions
25
...ges/docusaurus-mdx-loader/src/remark/admonitions/__tests__/__fixtures__/base.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...aurus-mdx-loader/src/remark/admonitions/__tests__/__fixtures__/interpolation.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
...s/docusaurus-mdx-loader/src/remark/admonitions/__tests__/__snapshots__/index.test.ts.snap
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,44 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`admonitions remark plugin base 1`] = ` | ||
"<p>The blog feature enables you to deploy in no time a full-featured blog.</p> | ||
<admonition title="Sample Title" type="info"><p>Check the <a href="./api/plugins/plugin-content-blog.md">Blog Plugin API Reference documentation</a> for an exhaustive list of options.</p></admonition> | ||
<h2>Initial setup {#initial-setup}</h2> | ||
<p>To set up your site's blog, start by creating a <code>blog</code> directory.</p> | ||
<admonition type="tip"><p>Use the <strong><a href="introduction.md#fast-track">Fast Track</a></strong> to understand Docusaurus in <strong>5 minutes ⏱</strong>!</p><p>Use <strong><a href="https://docusaurus.new">docusaurus.new</a></strong> to test Docusaurus immediately in your browser!</p></admonition> | ||
<p>++++tip</p> | ||
<p>Admonition with different syntax</p> | ||
<p>++++</p>" | ||
`; | ||
|
||
exports[`admonitions remark plugin custom keywords 1`] = ` | ||
"<p>The blog feature enables you to deploy in no time a full-featured blog.</p> | ||
<p>:::info Sample Title</p> | ||
<p>Check the <a href="./api/plugins/plugin-content-blog.md">Blog Plugin API Reference documentation</a> for an exhaustive list of options.</p> | ||
<p>:::</p> | ||
<h2>Initial setup {#initial-setup}</h2> | ||
<p>To set up your site's blog, start by creating a <code>blog</code> directory.</p> | ||
<admonition type="tip"><p>Use the <strong><a href="introduction.md#fast-track">Fast Track</a></strong> to understand Docusaurus in <strong>5 minutes ⏱</strong>!</p><p>Use <strong><a href="https://docusaurus.new">docusaurus.new</a></strong> to test Docusaurus immediately in your browser!</p></admonition> | ||
<p>++++tip</p> | ||
<p>Admonition with different syntax</p> | ||
<p>++++</p>" | ||
`; | ||
|
||
exports[`admonitions remark plugin custom tag 1`] = ` | ||
"<p>The blog feature enables you to deploy in no time a full-featured blog.</p> | ||
<p>:::info Sample Title</p> | ||
<p>Check the <a href="./api/plugins/plugin-content-blog.md">Blog Plugin API Reference documentation</a> for an exhaustive list of options.</p> | ||
<p>:::</p> | ||
<h2>Initial setup {#initial-setup}</h2> | ||
<p>To set up your site's blog, start by creating a <code>blog</code> directory.</p> | ||
<p>:::tip</p> | ||
<p>Use the <strong><a href="introduction.md#fast-track">Fast Track</a></strong> to understand Docusaurus in <strong>5 minutes ⏱</strong>!</p> | ||
<p>Use <strong><a href="https://docusaurus.new">docusaurus.new</a></strong> to test Docusaurus immediately in your browser!</p> | ||
<p>:::</p> | ||
<admonition type="tip"><p>Admonition with different syntax</p></admonition>" | ||
`; | ||
|
||
exports[`admonitions remark plugin interpolation 1`] = ` | ||
"<p>Test admonition with interpolated title/body</p> | ||
<admonition type="tip"><mdxAdmonitionTitle>My <code>interpolated</code> <strong>title</strong> <button style={{color: "red"}} onClick={() => alert("click")}>test</mdxAdmonitionTitle><p><code>body</code> <strong>interpolated</strong> content</p></admonition>" | ||
`; |
53 changes: 53 additions & 0 deletions
53
packages/docusaurus-mdx-loader/src/remark/admonitions/__tests__/index.test.ts
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,53 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import path from 'path'; | ||
import remark from 'remark'; | ||
import remark2rehype from 'remark-rehype'; | ||
import stringify from 'rehype-stringify'; | ||
|
||
import vfile from 'to-vfile'; | ||
import plugin from '../index'; | ||
import type {AdmonitionOptions} from '../index'; | ||
|
||
const processFixture = async ( | ||
name: string, | ||
options?: Partial<AdmonitionOptions>, | ||
) => { | ||
const filePath = path.join(__dirname, '__fixtures__', `${name}.md`); | ||
const file = await vfile.read(filePath); | ||
|
||
const result = await remark() | ||
.use(plugin, options) | ||
.use(remark2rehype) | ||
.use(stringify) | ||
.process(file); | ||
|
||
return result.toString(); | ||
}; | ||
|
||
describe('admonitions remark plugin', () => { | ||
it('base', async () => { | ||
const result = await processFixture('base'); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
it('custom keywords', async () => { | ||
const result = await processFixture('base', {keywords: ['tip']}); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
it('custom tag', async () => { | ||
const result = await processFixture('base', {tag: '++++'}); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
it('interpolation', async () => { | ||
const result = await processFixture('interpolation'); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.