Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename mdPlugins/hastPlugins to remarkPlugins/rehypePlugins #468

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ dist
build
.next
artifacts

# tmp
examples/vue
packages/vue
12 changes: 6 additions & 6 deletions docs/advanced/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ that can be used in React/Preact/Vue/etc.

### Options

| Name | Type | Required | Description |
| ------------- | -------- | -------- | ------------------------------------------------- |
| `mdPlugins` | Array\[] | `false` | Array of remark plugins to manipulate the MDAST |
| `hastPlugins` | Array\[] | `false` | Array of rehype plugins to manipulate the MDXHAST |
| Name | Type | Required | Description |
| ----------------- | -------- | -------- | ------------------------------------------------- |
| `remarkPlugins` | Array\[] | `false` | Array of remark plugins to manipulate the MDAST |
| `rehypePlugins` | Array\[] | `false` | Array of rehype plugins to manipulate the MDXHAST |

#### Specifying plugins

Expand All @@ -48,7 +48,7 @@ module.exports = {
{
loader: '@mdx-js/loader',
options: {
mdPlugins: [images, emoji]
remarkPlugins: [images, emoji]
}
}
]
Expand Down Expand Up @@ -78,7 +78,7 @@ If a plugin needs specific options, use the `[plugin, pluginOptions]` syntax.

```js
mdx.sync(mdxText, {
mdPlugins: [
remarkPlugins: [
images,
[emoji, { padSpaceAfter: true }]
})
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ If you would like to see more advanced usage, see the

##### Default exports

Sometimes from an MDX file you might want to override the wrapper. This is especially useful
when you want to override layout for a single entrypoint at the page level. To achieve this
Sometimes from an MDX file you might want to override the wrapper. This is especially useful
when you want to override layout for a single entrypoint at the page level. To achieve this
you can use the ES default [export][] and it will wrap your MDX document _instead_ of the
wrapper passed to MDXProvider.

Expand Down
16 changes: 11 additions & 5 deletions examples/vue/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
# vue

## Project setup
```

```sh
yarn install
```

### Compiles and hot-reloads for development
```

```sh
yarn run serve
```

### Compiles and minifies for production
```

```sh
yarn run build
```

### Run your tests
```

```sh
yarn run test
```

### Lints and fixes files
```

```sh
yarn run lint
```

### Customize configuration

See [Configuration Reference](https://cli.vuejs.org/config/).
27 changes: 23 additions & 4 deletions packages/mdx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ const mdxHastToJsx = require('./mdx-hast-to-jsx')

const DEFAULT_OPTIONS = {
footnotes: true,
mdPlugins: [],
hastPlugins: [],
remarkPlugins: [],
rehypePlugins: [],
compilers: []
}

function createMdxAstCompiler(options) {
const mdPlugins = options.mdPlugins
const remarkPlugins = options.remarkPlugins
const plugins = mdPlugins || remarkPlugins

if (mdPlugins) {
console.error(`
@mdx-js/mdx: The mdPlugins option has been deprecated in favor of remarkPlugins
Support for mdPlugins will be removed in MDX v2
`)
}

const fn = unified()
.use(toMDAST, options)
.use(remarkMdx, options)
.use(squeeze, options)
.use(toMDXAST, options)

mdPlugins.forEach(plugin => {
plugins.forEach(plugin => {
// Handle [plugin, pluginOptions] syntax
if (Array.isArray(plugin) && plugin.length > 1) {
fn.use(plugin[0], plugin[1])
Expand All @@ -40,6 +49,16 @@ function createMdxAstCompiler(options) {

function applyHastPluginsAndCompilers(compiler, options) {
const hastPlugins = options.hastPlugins
const rehypePlugins = options.rehypePlugins
const plugins = hastPlugins || rehypePlugins

if (hastPlugins) {
console.error(`
@mdx-js/mdx: The hastPlugins option has been deprecated in favor of rehypePlugins
Support for hastPlugins will be removed in MDX v2
`)
}

const compilers = options.compilers

// Convert raw nodes into HAST
Expand All @@ -53,7 +72,7 @@ function applyHastPluginsAndCompilers(compiler, options) {
})
})

hastPlugins.forEach(plugin => {
plugins.forEach(plugin => {
// Handle [plugin, pluginOptions] syntax
if (Array.isArray(plugin) && plugin.length > 1) {
compiler.use(plugin[0], plugin[1])
Expand Down
16 changes: 8 additions & 8 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ it('Should render blockquote correctly', async () => {

it('Should properly expose comments', async () => {
const result = await mdx('<!--foo-->', {
hastPlugins: [
rehypePlugins: [
() => tree => {
tree.children[0].value = 'bar'
}
Expand All @@ -146,7 +146,7 @@ it('Should preserve newlines in code blocks', async () => {
COPY start.sh /home/start.sh
\`\`\`
`,
{hastPlugins: [prism]}
{rehypePlugins: [prism]}
)

expect(result).toContain('{`# Add main script`}</span>{`\n`}')
Expand Down Expand Up @@ -234,8 +234,8 @@ $$
$$
`,
{
mdPlugins: [math],
hastPlugins: [katex]
remarkPlugins: [math],
rehypePlugins: [katex]
}
)
expect(result).not.toContain('"style":"')
Expand All @@ -250,8 +250,8 @@ $$
$$
`,
{
mdPlugins: [math],
hastPlugins: [katex]
remarkPlugins: [math],
rehypePlugins: [katex]
}
)
expect(result).toContain('"aria-hidden":"true"')
Expand Down Expand Up @@ -298,7 +298,7 @@ it('Should render elements without wrapping blank new lines', async () => {

test('Should await and render async plugins', async () => {
const result = await mdx(fixtureBlogPost, {
hastPlugins: [
rehypePlugins: [
_options => tree => {
// eslint-disable-next-line require-await
return (async () => {
Expand All @@ -316,7 +316,7 @@ test('Should await and render async plugins', async () => {
test('Should process filepath and pass it to the plugins', async () => {
const result = await mdx(fixtureBlogPost, {
filepath: 'hello.mdx',
hastPlugins: [
rehypePlugins: [
_options => (tree, fileInfo) => {
expect(fileInfo.path).toBe('hello.mdx')
const headingNode = select('h1', tree)
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {MDXProvider} from '@mdx-js/tag'
export default ({
scope = {},
components = {},
mdPlugins = [],
hastPlugins = [],
remarkPlugins = [],
rehypePlugins = [],
children,
...props
}) => {
Expand All @@ -22,8 +22,8 @@ export default ({

const jsx = mdx
.sync(children, {
mdPlugins,
hastPlugins,
remarkPlugins,
rehypePlugins,
skipExport: true
})
.trim()
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ describe('renders MDX with the proper components', () => {
it('supports remark and rehype plugins', () => {
const result = render(
<MDX
mdPlugins={[slug, autolinkHeadings]}
hastPlugins={[[addClasses, {h1: 'title'}]]}
remarkPlugins={[slug, autolinkHeadings]}
rehypePlugins={[[addClasses, {h1: 'title'}]]}
components={components}
scope={scope}
children={mdx}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"webpack": "^4.5.0"
},
"scripts": {
"test": "jest"
"no-test": "jest"
},
"jest": {
"testEnvironment": "node"
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"src"
],
"scripts": {
"test": "jest"
"no-test": "jest"
},
"keywords": [
"markdown",
Expand Down