Skip to content

Commit

Permalink
Add explore ast link (#353)
Browse files Browse the repository at this point in the history
* Add explore ast link

* Allow html in md because jsx

* Fix `remark-mdx` to support inline jsx
  • Loading branch information
johno committed Dec 11, 2018
1 parent fc40de3 commit c2a7386
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
6 changes: 6 additions & 0 deletions docs/advanced/ast.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Button } from 'rebass'

# AST

export const AST_EXPLORER_LINK = 'https://astexplorer.net/#/gist/2befce6edce1475eb4bbec001356b222/35997d3b44347daabad8dd1a107adc22dd873de2'

<Button is="a" href={AST_EXPLORER_LINK}>Explore the AST</Button>

This document defines two syntax trees:

* [MDXAST][], a superset of [mdast][], to represent markdown with embedded JSX
Expand Down
1 change: 1 addition & 0 deletions docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@ 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
31 changes: 19 additions & 12 deletions packages/remark-mdx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,30 @@ function mdx(_options) {
}

function attachParser(parser) {
const tokenizers = parser.prototype.blockTokenizers
const blocks = parser.prototype.blockMethods
const html = tokenizers.html
const blocks = parser.prototype.blockTokenizers
const inlines = parser.prototype.inlineTokenizers
const methods = parser.prototype.blockMethods

tokenizers.esSyntax = tokenizeEsSyntax
tokenizers.html = tokenizeJsx
blocks.esSyntax = tokenizeEsSyntax
blocks.html = wrap(blocks.html)
inlines.html = wrap(inlines.html)

blocks.splice(blocks.indexOf('paragraph'), 0, 'esSyntax')
methods.splice(methods.indexOf('paragraph'), 0, 'esSyntax')

function tokenizeJsx() {
const node = html.apply(this, arguments)
function wrap(original) {
tokenizeJsx.locator = original.locator

if (node) {
node.type = 'jsx'
}
return tokenizeJsx

function tokenizeJsx() {
const node = original.apply(this, arguments)

return node
if (node) {
node.type = 'jsx'
}

return node
}
}
}

Expand Down

1 comment on commit c2a7386

@vercel
Copy link

@vercel vercel bot commented on c2a7386 Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully aliased the URL https://mdx-fbtinbljwj.now.sh to the following aliases.

Please sign in to comment.