Skip to content

Commit c2a7386

Browse files
authored
Add explore ast link (#353)
* Add explore ast link * Allow html in md because jsx * Fix `remark-mdx` to support inline jsx
1 parent fc40de3 commit c2a7386

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

docs/advanced/ast.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import { Button } from 'rebass'
2+
13
# AST
24

5+
export const AST_EXPLORER_LINK = 'https://astexplorer.net/#/gist/2befce6edce1475eb4bbec001356b222/35997d3b44347daabad8dd1a107adc22dd873de2'
6+
7+
<Button is="a" href={AST_EXPLORER_LINK}>Explore the AST</Button>
8+
39
This document defines two syntax trees:
410

511
* [MDXAST][], a superset of [mdast][], to represent markdown with embedded JSX

docs/getting-started/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,5 @@ following commands:
156156
[next]: https://github.com/zeit/next.js
157157

158158
[context]: https://reactjs.org/docs/context.html
159+
159160
[context-caveats]: https://reactjs.org/docs/context.html#caveats

packages/remark-mdx/index.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,30 @@ function mdx(_options) {
2727
}
2828

2929
function attachParser(parser) {
30-
const tokenizers = parser.prototype.blockTokenizers
31-
const blocks = parser.prototype.blockMethods
32-
const html = tokenizers.html
30+
const blocks = parser.prototype.blockTokenizers
31+
const inlines = parser.prototype.inlineTokenizers
32+
const methods = parser.prototype.blockMethods
3333

34-
tokenizers.esSyntax = tokenizeEsSyntax
35-
tokenizers.html = tokenizeJsx
34+
blocks.esSyntax = tokenizeEsSyntax
35+
blocks.html = wrap(blocks.html)
36+
inlines.html = wrap(inlines.html)
3637

37-
blocks.splice(blocks.indexOf('paragraph'), 0, 'esSyntax')
38+
methods.splice(methods.indexOf('paragraph'), 0, 'esSyntax')
3839

39-
function tokenizeJsx() {
40-
const node = html.apply(this, arguments)
40+
function wrap(original) {
41+
tokenizeJsx.locator = original.locator
4142

42-
if (node) {
43-
node.type = 'jsx'
44-
}
43+
return tokenizeJsx
44+
45+
function tokenizeJsx() {
46+
const node = original.apply(this, arguments)
4547

46-
return node
48+
if (node) {
49+
node.type = 'jsx'
50+
}
51+
52+
return node
53+
}
4754
}
4855
}
4956

0 commit comments

Comments
 (0)