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

Commits on Mar 3, 2019

  1. Add example for syntax highlighting and live editor (#432)

    * Scaffold out syntax highlighting example
    
    * Add example for syntax highlighting and live editor
    
    Fixes #253
    johno authored Mar 3, 2019
    1
    Copy the full SHA
    d95669a View commit details

Commits on Mar 5, 2019

  1. Add documentation page for editor plugins (#436)

    Based on the completed plugins from #119
    trevordmiller authored and johno committed Mar 5, 2019
    1
    Copy the full SHA
    638b0ed View commit details
  2. Fix template string escaping (#437)

    Related #433
    johno authored Mar 5, 2019
    Copy the full SHA
    44fa47d View commit details
  3. v0.20.2

    johno committed Mar 5, 2019
    1
    Copy the full SHA
    caa2462 View commit details
11 changes: 11 additions & 0 deletions docs/editor-plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Editor Plugins

* [vscode][]: VSCode
* [vim][]: Vim
* [sublime][]: Sublime

[vscode]: https://github.com/silvenon/vscode-mdx

[vim]: https://github.com/jxnblk/vim-mdx-js

[sublime]: https://github.com/jonsuh/mdx-sublime
3 changes: 3 additions & 0 deletions examples/syntax-highlighting/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.cache
public
12 changes: 12 additions & 0 deletions examples/syntax-highlighting/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
plugins: [
{
resolve: 'gatsby-mdx',
options: {
defaultLayouts: {
default: require.resolve('./src/components/Layout')
}
}
}
]
}
18 changes: 18 additions & 0 deletions examples/syntax-highlighting/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"private": true,
"name": "gatsby",
"version": "0.0.1",
"scripts": {
"start": "gatsby develop",
"build": "gatsby build"
},
"dependencies": {
"@mdx-js/mdx": "^0.16.8",
"@mdx-js/tag": "^0.16.8",
"gatsby": "^2.0.98",
"gatsby-mdx": "^0.3.5",
"prism-react-renderer": "^0.1.6",
"react-live": "^1.12.0",
"unified-ui": "^0.0.3"
}
}
5 changes: 5 additions & 0 deletions examples/syntax-highlighting/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Gatsby + MDX

```sh
yarn && yarn start
```
46 changes: 46 additions & 0 deletions examples/syntax-highlighting/src/components/CodeBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint react/jsx-key: 0 */

import React from 'react'
import Highlight, {defaultProps} from 'prism-react-renderer'
import {LiveProvider, LiveEditor, LiveError, LivePreview} from 'react-live'

export default ({children, className, live, render}) => {
const language = className.replace(/language-/, '')

if (live) {
return (
<div style={{marginTop: '40px'}}>
<LiveProvider code={children}>
<LivePreview />
<LiveEditor />
<LiveError />
</LiveProvider>
</div>
)
}
if (render) {
return (
<div style={{marginTop: '40px'}}>
<LiveProvider code={children}>
<LivePreview />
</LiveProvider>
</div>
)
}

return (
<Highlight {...defaultProps} code={children} language={language}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<pre className={className} style={{...style, padding: '20px'}}>
{tokens.map((line, i) => (
<div key={i} {...getLineProps({line, key: i})}>
{line.map((token, key) => (
<span key={key} {...getTokenProps({token, key})} />
))}
</div>
))}
</pre>
)}
</Highlight>
)
}
28 changes: 28 additions & 0 deletions examples/syntax-highlighting/src/components/Layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import {MDXProvider} from '@mdx-js/tag'
import {Container, baseStyles} from 'unified-ui'

import CodeBlock from './CodeBlock'

const Style = ({children}) => (
<style
dangerouslySetInnerHTML={{
__html: children
}}
/>
)

const components = {
h1: props => <h1 style={{color: 'tomato'}} {...props} />,
pre: props => <div {...props} />,
code: CodeBlock
}

export default props => (
<MDXProvider components={components}>
<>
<Style>{baseStyles}</Style>
<Container {...props} />
</>
</MDXProvider>
)
18 changes: 18 additions & 0 deletions examples/syntax-highlighting/src/pages/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Hello, world!

```js
import React from 'react'
import Example from './place'

export default () => (
<Example />
)
```

```js render=true
<div style={{ backgroundColor: 'rebeccapurple', padding: '20px', marginTop: '20px' }} />
```

```js live=true
<div style={{ backgroundColor: 'tomato', padding: '20px' }} />
```
Loading