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.4
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.5
Choose a head ref
  • 5 commits
  • 9 files changed
  • 2 contributors

Commits on Nov 23, 2018

  1. Add demoboard link (#331)

    johno authored and silvenon committed 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
    6c7e782 View commit details
  2. Create react-static.md (#332)

    * Create react-static.md
    
    * Update react-static.md
    swyxio authored and johno committed 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
    44f4221 View commit details
  3. Fix reference link

    johno committed Nov 23, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    765ae4c View commit details
  4. Don't default components to the empty object (#333)

    This ensures that components passed as context
    will be used instead.
    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
    f1dd09d View commit details
  5. v0.16.5

    johno committed 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
    4fe045f View commit details
54 changes: 54 additions & 0 deletions docs/getting-started/react-static.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# React Static

In order to use MDX with [React Static][react-static] you just need to [configure the `webpack` option](https://react-static.js.org/docs/config/#webpack) in `static.config.js`.

First, scaffold a new React Static site:

```shell
react-static create myapp
yarn add @mdx-js/loader
```

Then add the `webpack` field to your `static.config.js`:

```javascript
export default {
getSiteData: () => ({
// ...
}),
getRoutes: async () => {
// ...
},
webpack: config => {
config.module.rules.map(rule => {
// rules is an array of objects, we want the one with the `oneOf` field
if (
typeof rule.test !== 'undefined' ||
typeof rule.oneOf === 'undefined'
) {
return rule;
}
// add the mdx-js loader to it
rule.oneOf.unshift({
test: /.mdx$/,
use: ['babel-loader', '@mdx-js/loader']
});

return rule;
});
return config;
}
};

```

Finally, add an `.mdx` file anywhere in the `src` directory.
It “Just Works” when you import it.

```markdown
# My first MDX Page

some awesome content
```

[react-static]: http://react-static.js.org
8 changes: 8 additions & 0 deletions docs/projects.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Projects using MDX

## Apps

* [demoboard][]: The simplest editor alive

## Libraries

* [ok-mdx][]: Browser-based MDX editor
* [docz][]: Documentation framework
* [mdx-deck][]: MDX-based presentation decks
@@ -16,6 +22,8 @@

* [awesome-mdx][]

[demoboard]: https://frontarm.com/demoboard

[ok-mdx]: https://github.com/jxnblk/ok-mdx

[mdx-deck]: https://github.com/jxnblk/mdx-deck
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "3.4.0",
"version": "0.16.4",
"version": "0.16.5",
"packages": [
"packages/*"
],
4 changes: 2 additions & 2 deletions packages/loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/loader",
"version": "0.16.4",
"version": "0.16.5",
"description": "Loader for MDX",
"license": "MIT",
"keywords": [
@@ -27,7 +27,7 @@
"index.js"
],
"dependencies": {
"@mdx-js/mdx": "^0.16.4",
"@mdx-js/mdx": "^0.16.5",
"@mdx-js/tag": "^0.16.1",
"loader-utils": "^1.1.0"
},
2 changes: 1 addition & 1 deletion packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ function toJSX(node, parentNode = {}, options = {}) {
this.layout = ${layout || 'null'}
}
render() {
const { components = {}, ...props } = this.props
const { components, ...props } = this.props
return <MDXTag
name="wrapper"
2 changes: 1 addition & 1 deletion packages/mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/mdx",
"version": "0.16.4",
"version": "0.16.5",
"description": "Parse MDX and transpile to JSX",
"license": "MIT",
"keywords": [
18 changes: 14 additions & 4 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ const prism = require('@mapbox/rehype-prism')
const math = require('remark-math')
const katex = require('rehype-katex')
const prettier = require('prettier')
const {MDXTag} = require('@mdx-js/tag')
const {MDXTag, MDXProvider} = require('@mdx-js/tag')
const React = require('react')
const {renderToStaticMarkup} = require('react-dom/server')

@@ -46,8 +46,18 @@ const renderWithReact = async mdxCode => {
)

const element = fn(React, ...Object.values(scope))
const components = {
h1: ({children}) =>
React.createElement('h1', {style: {color: 'tomato'}}, children)
}

const elementWithProvider = React.createElement(
MDXProvider,
{components},
element
)

return renderToStaticMarkup(element)
return renderToStaticMarkup(elementWithProvider)
}

it('Should output parseable JSX', async () => {
@@ -59,7 +69,7 @@ it('Should output parseable JSX', async () => {
it('Should be able to render JSX with React', async () => {
const result = await renderWithReact('# Hello, world!')

expect(result).toContain('<h1>Hello, world!</h1>')
expect(result).toContain('<h1 style="color:tomato">Hello, world!</h1>')
})

it('Should output parseable JSX when using < or >', async () => {
@@ -88,7 +98,7 @@ it('Should match sample blog post snapshot', async () => {
this.layout = null;
}
render() {
const { components = {}, ...props } = this.props;
const { components, ...props } = this.props;
return (
<MDXTag name=\\"wrapper\\" components={components}>
4 changes: 2 additions & 2 deletions packages/parcel-plugin-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/parcel-plugin-mdx",
"version": "0.16.4",
"version": "0.16.5",
"description": "Parcel plugin for MDX",
"license": "MIT",
"keywords": [
@@ -27,7 +27,7 @@
"src"
],
"dependencies": {
"@mdx-js/mdx": "^0.16.4",
"@mdx-js/mdx": "^0.16.5",
"parcel-bundler": "^1.4.1"
},
"peerDependencies": {
4 changes: 2 additions & 2 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/runtime",
"version": "0.16.4",
"version": "0.16.5",
"description": "Parse and render MDX in a runtime environment",
"license": "MIT",
"keywords": [
@@ -30,7 +30,7 @@
"src/"
],
"dependencies": {
"@mdx-js/mdx": "^0.16.4",
"@mdx-js/mdx": "^0.16.5",
"@mdx-js/tag": "^0.16.1",
"buble": "^0.19.6"
},