Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mdx-js/mdx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.16.5
Choose a base ref
...
head repository: mdx-js/mdx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.16.6
Choose a head ref
  • 14 commits
  • 56 files changed
  • 8 contributors

Commits on Nov 23, 2018

  1. Bump example deps (#334)

    * Bump next example deps
    
    * Use style tag in layout for base styles
    
    * Add codesandbox link
    
    * Update parcel example
    
    * Remove unneeded deps from razzle example
    
    * Remove unneeded cruft from cra example
    johno authored Nov 23, 2018
    1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7a8f638 View commit details
  2. Move react-static docs in nav

    johno committed Nov 23, 2018
    1
    Copy the full SHA
    cceba05 View commit details
  3. Add custom loader docs (#336)

    johno authored Nov 23, 2018
    1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f9b1600 View commit details
  4. Add prisma docs link

    johno committed Nov 23, 2018
    1
    Copy the full SHA
    6949c24 View commit details
  5. 1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e2d5f75 View commit details

Commits on Nov 25, 2018

  1. Fix comment prefix and suffix (#328)

    * Fix comment prefix and suffix
    
    Previously, `<!--` and `--> were part of comments nodes.
    this deferred from the HAST specification.
    
    This PR removed the prefix when comments are found in markdown, and
    thus doesn’t need to replace them when rendering to JSX, but rather
    prefixes and suffixes them.
    
    Closes GH-312.
    
    * Update packages/mdx/md-ast-to-mdx-ast.js
    
    Co-Authored-By: wooorm <tituswormer@gmail.com>
    
    * Update packages/mdx/md-ast-to-mdx-ast.js
    
    Co-Authored-By: wooorm <tituswormer@gmail.com>
    
    * Add test for comments
    
    * Update packages/mdx/mdx-hast-to-jsx.js
    
    Co-Authored-By: wooorm <tituswormer@gmail.com>
    wooorm authored and silvenon committed Nov 25, 2018
    1
    Copy the full SHA
    022b2c6 View commit details

Commits on Nov 27, 2018

  1. enhanced eslint (#338)

    * lint(eslint): enhanced eslint
    
    * chore(review): responded to the review
    
    * chore(review): fixed missing
    
    * lint(eslint): override react/react-in-jsx-scope
    
    * chore(review): yarn run format
    
    * chore(review): delete comment out line
    Himenon authored and silvenon committed Nov 27, 2018
    1
    Copy the full SHA
    8469707 View commit details

Commits on Nov 29, 2018

  1. fix custom loader example (#339)

    This makes the code uglier, unfortunately, but the example provided here is incorrect. Since all the code is indented by 4 spaces, it is treated by the markdown parser as a code block, and you end up seeing the exports in the file inside of a formatted code block. Eliminating the extra indentation fixes this.
    jescalan authored and johno committed Nov 29, 2018
    1
    Copy the full SHA
    0c4c790 View commit details

Commits on Dec 6, 2018

  1. Convert node.meta to undefined if null (#342)

    * Don't add `metaString` prop
    
    Fixes vercel/next-plugins#307
    
    * Remove `metaString` prop from test assert
    
    * Replace metaString prop by metastring
    
    * Fix metastring prop test
    
    * Convert metastring to undefined if null
    
    * Add extra comma to comment
    
    * Fix lint
    hugmanrique authored and johno committed Dec 6, 2018
    1
    Copy the full SHA
    bed7668 View commit details
  2. 1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7147610 View commit details

Commits on Dec 8, 2018

  1. document scope functionality of mdx-js/runtime (#348)

    Jon Sherrard authored and johno committed Dec 8, 2018
    1
    Copy the full SHA
    5854115 View commit details
  2. 1
    Copy the full SHA
    f79665c View commit details
  3. Fix prettier failure (#350)

    johno authored Dec 8, 2018
    1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    dc729db View commit details
  4. v0.16.6

    johno committed Dec 8, 2018
    1
    Copy the full SHA
    fc40de3 View commit details
Showing with 25,414 additions and 170 deletions.
  1. +2 −0 .eslintignore
  2. +20 −1 .eslintrc.yml
  3. +1 −0 .gitignore
  4. +1 −0 docs/_app.js
  5. +1 −1 docs/_ui.js
  6. +45 −5 docs/advanced/custom-loader.md
  7. +25 −5 docs/advanced/writing-a-plugin.md
  8. +49 −3 docs/getting-started/index.md
  9. +0 −1 docs/getting-started/react-static.md
  10. +4 −1 docs/projects.md
  11. +1 −1 examples/create-react-app/config-overrides.js
  12. +5 −8 examples/create-react-app/package.json
  13. +6 −8 examples/create-react-app/src/App.js
  14. +0 −23 examples/create-react-app/src/hello.md
  15. +7,594 −0 examples/create-react-app/yarn.lock
  16. +15 −2 examples/next/components/Layout.js
  17. +0 −3 examples/next/components/markdown.js
  18. +8 −8 examples/next/package.json
  19. BIN examples/next/pages/._app.js.swp
  20. +4 −6 examples/next/pages/_app.js
  21. +1 −2 examples/next/pages/_document.js
  22. +0 −3 examples/next/pages/index.md
  23. +2 −0 examples/next/readme.md
  24. +4,726 −0 examples/next/yarn.lock
  25. +4 −1 examples/parcel/.babelrc
  26. +8 −10 examples/parcel/package.json
  27. +0 −6 examples/parcel/src/content.mdx
  28. +6 −6 examples/parcel/src/main.js
  29. +4,745 −0 examples/parcel/yarn.lock
  30. +6 −7 examples/razzle/package.json
  31. +6 −8 examples/razzle/src/App.js
  32. +0 −4 examples/razzle/src/example.md
  33. +8,021 −0 examples/razzle/yarn.lock
  34. +1 −1 lerna.json
  35. +1 −0 package.json
  36. +1 −1 packages/create-mdx/cli.js
  37. +1 −1 packages/create-mdx/package.json
  38. +3 −3 packages/loader/package.json
  39. +1 −1 packages/loader/test/index.test.js
  40. +4 −4 packages/mdx/index.js
  41. +9 −2 packages/mdx/md-ast-to-mdx-ast.js
  42. +4 −2 packages/mdx/mdx-ast-to-mdx-hast.js
  43. +3 −2 packages/mdx/mdx-hast-to-jsx.js
  44. +2 −2 packages/mdx/package.json
  45. +21 −4 packages/mdx/test/index.test.js
  46. +1 −1 packages/mdxast/index.js
  47. +1 −1 packages/mdxast/package.json
  48. +2 −2 packages/parcel-plugin-mdx/package.json
  49. +6 −7 packages/remark-mdx/index.js
  50. +1 −1 packages/remark-mdx/package.json
  51. +3 −3 packages/runtime/package.json
  52. +13 −2 packages/runtime/readme.md
  53. +1 −2 packages/runtime/test/index.test.js
  54. +1 −1 packages/tag/package.json
  55. +0 −2 packages/tag/test/mdx-provider.test.js
  56. +28 −2 yarn.lock
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
dist
build
.next
21 changes: 20 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ plugins:
- prettier

extends:
- eslint:recommended
- plugin:react/recommended
- plugin:import/errors
- xo
- prettier
@@ -23,9 +25,21 @@ rules:
eqeqeq: off
no-eq-null: off
no-negated-condition: off
no-unused-vars: off
no-unused-vars:
- error
- args: after-used
argsIgnorePattern: "^_"
no-var: error
import/no-extraneous-dependencies: error
prettier/prettier: error
no-console: off
react/prop-types: off
react/display-name: off
react/no-children-prop: off

settings:
react:
version: 16.3.2

overrides:
-
@@ -46,3 +60,8 @@ overrides:
rules:
import/no-unresolved: off
import/no-extraneous-dependencies: off
-
files:
- "examples/next/**/*.js"
rules:
react/react-in-jsx-scope: off
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
package-lock.json
dist
build
bundle.js
.next
*-error.log
1 change: 1 addition & 0 deletions docs/_app.js
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ const navOrder = [
'gatsby',
'x0',
'typescript',
'react-static',
'plugins',
'advanced',
'ast',
2 changes: 1 addition & 1 deletion docs/_ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {Pre, Box, Border} from 'rebass'
import {Pre} from 'rebass'
import {LiveEditor as Editor, LivePreview} from '@compositor/x0/components'

export const Logo = () => <img src="https://mdx-logo.now.sh" width="70" />
50 changes: 45 additions & 5 deletions docs/advanced/custom-loader.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
import { Message } from 'rebass'

# Custom loader

<Message>
This docs page is a WIP
</Message>
By design, the default MDX is very minimal and likely won’t see any additional features outside of the MDX spec. However, webpack [makes it straightforward][webpack-loader] to write your own loader to add custom syntax support.

Consider a scenario where you wanted to add frontmatter support to all your MDX documents. You could achieve this with a remark plugin or a custom loader. Here we’ll write a [custom loader][x0]:

```js
// lib/fm-loader.js
const matter = require('gray-matter')
const stringifyObject = require('stringify-object')

module.exports = async function (src) {
const callback = this.async()
const { content, data } = matter(src)

const code = `export const frontMatter = ${stringifyObject(data)}
${content}`

return callback(null, code)
}
```

The loader code above parses out the frontmatter, exports it as the named export `frontMatter`, and then returns the rest of the document which will then be handled by `@mdx-js/loader` and then `babel-loader`.

Then, you can use it with the following config:

```js
module.exports = {
module: {
rules: [
{
test: /\.mdx?$/,
use: [
'babel-loader',
'@mdx-js/loader',
path.join(__dirname, './lib/fm-loader')
]
}
]
}
}
```

[webpack-loader]: https://webpack.js.org/contribute/writing-a-loader

[x0]: https://github.com/c8r/x0/blob/master/lib/mdx-fm-loader.js
30 changes: 25 additions & 5 deletions docs/advanced/writing-a-plugin.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import { Message } from 'rebass'

# Writing a plugin

<Message>
This docs page is a WIP
</Message>
For a full-fledged introduction to plugins it’s recommended to read the [remark guides][remark-guides] and about [syntax trees][syntax-trees].

Now let’s consider an example where we want to pass all headings through the [title][] module to ensure consistent capitalization. We can use [unist-util-visit][] to visit all headings and change the text nodes with `title(text)`.

```js
const title = require('title')
const visit = require('unist-util-visit')

module.exports = () => (tree, file) => {
visit(tree, 'heading', node => {
visit(node, 'text', textNode => {
const text = textNode.value ? textNode.value.trim() : ''
textNode.value = title(text)
})
})
}
```

[remark-guides]: https://github.com/remarkjs/remark/blob/master/doc/plugins.md#creating-plugins

[syntax-trees]: https://github.com/syntax-tree/unist#syntax-tree

[title]: https://github.com/zeit/title

[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit
52 changes: 49 additions & 3 deletions docs/getting-started/index.md
Original file line number Diff line number Diff line change
@@ -91,10 +91,55 @@ export default props =>
This allows you to remove duplicated component imports and passing.
It will typically go in layout files.

#### How it works
### How it works

MDXProvider uses React [context][] to provide the component mapping to MDXTag.
MDXTag knows to use these components when determining which to render.
MDXProvider uses [React Context][context] to provide the component mapping to
MDXTag. This way MDXTag knows that it should override the standard components
with those provided in this mapping.

Because MDXProvider uses React Context directly, [it is affected by the same
caveats][context-caveats]. It is therefore important that you do **not**
declare your components mapping inline in the JSX. Doing so will trigger a
rerender of your entire MDX page with every render cycle. Not only is this bad
for performance, but it can cause unwanted side affects, like breaking in-page
browser navigation.

Avoid this by following the pattern shown above and declare your mapping as a
constant.

### Updating the mapping object during application runtime

If you need to change the mapping during runtime, declare it on the componentʼs
state object:

```jsx
import React from 'react'
import { MDXProvider } from '@mdx-js/tag'

import { Heading, Text, Pre, Code, Table } from './components'

export default class Layout extends React.Component {
state = {
h1: Heading.H1,
h2: Heading.H2,
// ...
p: Text,
code: Pre,
inlineCode: Code
}

render() {
return (
<MDXProvider components={this.state}>
<main {...this.props} />
</MDXProvider>
)
}
}
```

You can now use the `setState` function to update the mapping object and be
assured that it wonʼt trigger unnecessary renders.

## Projects, libraries and frameworks

@@ -111,3 +156,4 @@ following commands:
[next]: https://github.com/zeit/next.js

[context]: https://reactjs.org/docs/context.html
[context-caveats]: https://reactjs.org/docs/context.html#caveats
1 change: 0 additions & 1 deletion docs/getting-started/react-static.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ export default {
return config;
}
};

```

Finally, add an `.mdx` file anywhere in the `src` directory.
5 changes: 4 additions & 1 deletion docs/projects.md
Original file line number Diff line number Diff line change
@@ -13,10 +13,11 @@
* [spectacle-boilerplate-mdx][]: Boilerplate that facilitates using MDX with
Spectacle

## Sites using MDX
## Sites

* [ZEIT Docs][zeit-docs]
* [Compositor][compositor]
* [Prisma][prisma]

## Other related links

@@ -36,6 +37,8 @@

[compositor]: https://compositor.io

[prisma]: https://www.prisma.io/docs

[awesome-mdx]: https://github.com/transitive-bullshit/awesome-mdx

[spectacle-boilerplate-mdx]: https://github.com/FormidableLabs/spectacle-boilerplate-mdx
2 changes: 1 addition & 1 deletion examples/create-react-app/config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {getBabelLoader} = require('react-app-rewired')
module.exports = (config, env) => {
module.exports = (config, _env) => {
const babelLoader = getBabelLoader(config.module.rules)
config.module.rules.map(rule => {
if (typeof rule.test !== 'undefined' || typeof rule.oneOf === 'undefined') {
13 changes: 5 additions & 8 deletions examples/create-react-app/package.json
Original file line number Diff line number Diff line change
@@ -2,15 +2,12 @@
"private": true,
"name": "mdx-create-react-app",
"dependencies": {
"@mdx-js/loader": "^0.16.0",
"@mdx-js/mdx": "^0.16.0",
"@rebass/markdown": "^1.0.0",
"react": "^16.5.2",
"@mdx-js/loader": "^0.16.4",
"@mdx-js/mdx": "^0.16.4",
"react": "^16.6.3",
"react-app-rewired": "^1.6.2",
"react-dom": "^16.5.2",
"react-scripts": "1.1.5",
"rebass": "^2.3.4",
"styled-components": "^3.4.9"
"react-dom": "^16.6.3",
"react-scripts": "1.1.5"
},
"scripts": {
"start": "react-app-rewired start",
14 changes: 6 additions & 8 deletions examples/create-react-app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import React, {Component} from 'react'
import {MDXProvider} from '@mdx-js/tag'
import {Container, Provider as RebassProvider} from 'rebass'
import createComponents from '@rebass/markdown'

import Hello from './hello.md'

const components = {
h1: props => <h1 style={{color: 'tomato'}} {...props} />
}

class App extends Component {
render() {
return (
<MDXProvider components={createComponents()}>
<RebassProvider>
<Container>
<Hello />
</Container>
</RebassProvider>
<MDXProvider components={components}>
<Hello />
</MDXProvider>
)
}
23 changes: 0 additions & 23 deletions examples/create-react-app/src/hello.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
import {
Card,
Box,
BackgroundImage,
Subhead,
Small
} from 'rebass'

# Hello, world!

This is MDX!

<Box width={300}>
<Card>
<BackgroundImage src="https://images.unsplash.com/photo-1533529318682-0c3e2fc1e225" />
<Box p={2}>
<Subhead>
<a href="https://unsplash.com/photos/e3hDxz86IxI">Alone but Powerful</a>
</Subhead>
<Small>
Photo by <a href="https://unsplash.com/@tentides">Jeremy Bishop</a> on{' '}
<a href="https://unsplash.com">Unsplash</a>
</Small>
</Box>
</Card>
</Box>
Loading