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

Add explore ast link #353

Merged
merged 3 commits into from
Dec 11, 2018
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
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