Skip to content

Commit a805afc

Browse files
committed
Add mdast deps
1 parent ea2b270 commit a805afc

File tree

5 files changed

+96
-32
lines changed

5 files changed

+96
-32
lines changed

packages/mdx/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
"@code-hike/scroller": "^0.3.0-next.0",
2727
"@code-hike/utils": "^0.3.0-next.0",
2828
"estree-util-value-to-estree": "^1.3.0",
29-
"unist-util-visit": "^2.0.0"
29+
"unist-util-visit": "^2.0.0",
30+
"hast-util-to-estree": "^1.4.0",
31+
"remark-rehype": "^8.1.0",
32+
"unified": "^9.2.2"
3033
},
3134
"peerDependencies": {
3235
"react": "^16.8.3 || ^17 || ^18"

packages/mdx/src/annotations.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export function extractJSXAnnotations(
206206
props[attr.name] = attr.value
207207
})
208208
const { as, focus, ...data } = props
209+
// data.children = wrapChildren(jsxAnnotation.children);
209210

210211
const Component = annotationsMap[as] || as
211212
annotations.push({

packages/mdx/src/to-estree.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Expression } from "estree"
22
import isPlainObject from "is-plain-obj"
3-
import { CodeLink } from "./links"
43
import { annotationsMap } from "./annotations"
4+
// import unified from "unified"
5+
// import remarkRehype from "remark-rehype"
6+
// import { toEstree } from "hast-util-to-estree"
57

68
// forked from https://github.com/remcohaszing/estree-util-value-to-estree/blob/main/src/index.ts
79

@@ -230,3 +232,30 @@ export function valueToEstree(
230232

231233
throw new TypeError(`Unsupported value: ${String(value)}`)
232234
}
235+
236+
// export async function mdastToEstree(node: Node) {
237+
// const nodeTypes = [
238+
// "mdxFlowExpression",
239+
// "mdxJsxFlowElement",
240+
// "mdxJsxTextElement",
241+
// "mdxTextExpression",
242+
// "mdxjsEsm",
243+
// ]
244+
// const changedTree = unified()
245+
// .use(remarkRehype, {
246+
// allowDangerousHtml: true,
247+
// passThrough: nodeTypes,
248+
// })
249+
// .use(rehypeRecma as any)
250+
// .runSync(node as any)
251+
252+
// return changedTree
253+
// }
254+
255+
// function rehypeRecma() {
256+
// return (tree: any) => toEstree(tree)
257+
// }
258+
259+
// export function wrapChildren() {
260+
// return {}
261+
// }
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
1+
# Hello
22

3-
```js
4-
function lorem(ipsum, dolor = 1) {
5-
const sit = ipsum == null ? 0 : ipsum.sit
6-
dolor = sit - amet(dolor)
7-
return sit
8-
? consectetur(ipsum, 0, dolor < 0 ? 0 : dolor)
9-
: []
10-
}
11-
```
12-
13-
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
14-
15-
```js app.js focus=2:4
16-
function adipiscing(...elit) {
17-
if (!elit.sit) {
18-
return []
19-
}
20-
21-
const sed = elit[0]
22-
return eiusmod.tempor(sed) ? sed : [sed]
23-
}
24-
```
25-
26-
---
27-
28-
TODO
29-
30-
- add `omnipresent` option to plugin to avoid `import { CH } from "@code-hike/mdx"` in every file
3+
<foo x={<div />} />

yarn.lock

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8510,6 +8510,11 @@ estraverse@^5.2.0:
85108510
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880"
85118511
integrity sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==
85128512

8513+
estree-util-attach-comments@^1.0.0:
8514+
version "1.0.0"
8515+
resolved "https://registry.yarnpkg.com/estree-util-attach-comments/-/estree-util-attach-comments-1.0.0.tgz#51d280e458ce85dec0b813bd96d2ce98eae8a3f2"
8516+
integrity sha512-sL7dTwFGqzelPlB56lRZY1CC/yDxCe365WQpxNd49ispL40Yv8Tv4SmteGbvZeFwShOOVKfMlo4jrVvwoaMosA==
8517+
85138518
estree-util-attach-comments@^2.0.0:
85148519
version "2.0.0"
85158520
resolved "https://registry.yarnpkg.com/estree-util-attach-comments/-/estree-util-attach-comments-2.0.0.tgz#2c06d484dfcf841b5946bcb84d5412cbcd544e22"
@@ -9941,6 +9946,21 @@ [email protected]:
99419946
xtend "^4.0.0"
99429947
zwitch "^1.0.0"
99439948

9949+
hast-util-to-estree@^1.4.0:
9950+
version "1.4.0"
9951+
resolved "https://registry.yarnpkg.com/hast-util-to-estree/-/hast-util-to-estree-1.4.0.tgz#896ef9150a3f5cfbaff37334f75f31d6a324bab6"
9952+
integrity sha512-CiOAIESUKkSOcYbvTth9+yM28z5ArpsYqxWc7LWJxOx975WRUBDjvVuuzZR2o09BNlkf7bp8G2GlOHepBRKJ8Q==
9953+
dependencies:
9954+
comma-separated-tokens "^1.0.0"
9955+
estree-util-attach-comments "^1.0.0"
9956+
estree-util-is-identifier-name "^1.1.0"
9957+
hast-util-whitespace "^1.0.0"
9958+
property-information "^5.0.0"
9959+
space-separated-tokens "^1.0.0"
9960+
style-to-object "^0.3.0"
9961+
unist-util-position "^3.1.0"
9962+
zwitch "^1.0.0"
9963+
99449964
hast-util-to-estree@^2.0.0:
99459965
version "2.0.2"
99469966
resolved "https://registry.yarnpkg.com/hast-util-to-estree/-/hast-util-to-estree-2.0.2.tgz#79c5bf588915610b3f0d47ca83a74dc0269c7dc2"
@@ -9972,6 +9992,11 @@ hast-util-to-parse5@^6.0.0:
99729992
xtend "^4.0.0"
99739993
zwitch "^1.0.0"
99749994

9995+
hast-util-whitespace@^1.0.0:
9996+
version "1.0.4"
9997+
resolved "https://registry.yarnpkg.com/hast-util-whitespace/-/hast-util-whitespace-1.0.4.tgz#e4fe77c4a9ae1cb2e6c25e02df0043d0164f6e41"
9998+
integrity sha512-I5GTdSfhYfAPNztx2xJRQpG8cuDSNt599/7YUn7Gx/WxNMsG+a835k97TDkFgk123cwjfwINaZknkKkphx/f2A==
9999+
997510000
hast-util-whitespace@^2.0.0:
997610001
version "2.0.0"
997710002
resolved "https://registry.yarnpkg.com/hast-util-whitespace/-/hast-util-whitespace-2.0.0.tgz#4fc1086467cc1ef5ba20673cb6b03cec3a970f1c"
@@ -12444,6 +12469,20 @@ [email protected]:
1244412469
unist-util-position "^3.0.0"
1244512470
unist-util-visit "^2.0.0"
1244612471

12472+
mdast-util-to-hast@^10.2.0:
12473+
version "10.2.0"
12474+
resolved "https://registry.yarnpkg.com/mdast-util-to-hast/-/mdast-util-to-hast-10.2.0.tgz#61875526a017d8857b71abc9333942700b2d3604"
12475+
integrity sha512-JoPBfJ3gBnHZ18icCwHR50orC9kNH81tiR1gs01D8Q5YpV6adHNO9nKNuFBCJQ941/32PT1a63UF/DitmS3amQ==
12476+
dependencies:
12477+
"@types/mdast" "^3.0.0"
12478+
"@types/unist" "^2.0.0"
12479+
mdast-util-definitions "^4.0.0"
12480+
mdurl "^1.0.0"
12481+
unist-builder "^2.0.0"
12482+
unist-util-generated "^1.0.0"
12483+
unist-util-position "^3.0.0"
12484+
unist-util-visit "^2.0.0"
12485+
1244712486
mdast-util-to-hast@^11.0.0:
1244812487
version "11.2.1"
1244912488
resolved "https://registry.yarnpkg.com/mdast-util-to-hast/-/mdast-util-to-hast-11.2.1.tgz#85ca3b188b8cd9171176454803be738c1cf0a855"
@@ -15917,6 +15956,13 @@ remark-parse@^10.0.0:
1591715956
mdast-util-from-markdown "^1.0.0"
1591815957
unified "^10.0.0"
1591915958

15959+
remark-rehype@^8.1.0:
15960+
version "8.1.0"
15961+
resolved "https://registry.yarnpkg.com/remark-rehype/-/remark-rehype-8.1.0.tgz#610509a043484c1e697437fa5eb3fd992617c945"
15962+
integrity sha512-EbCu9kHgAxKmW1yEYjx3QafMyGY3q8noUbNUI5xyKbaFP89wbhDrKxyIQNukNYthzjNHZu6J7hwFg7hRm1svYA==
15963+
dependencies:
15964+
mdast-util-to-hast "^10.2.0"
15965+
1592015966
remark-rehype@^9.0.0:
1592115967
version "9.0.0"
1592215968
resolved "https://registry.yarnpkg.com/remark-rehype/-/remark-rehype-9.0.0.tgz#83532a48e048373411ca50c53d84fb1a35bc7bfe"
@@ -18095,6 +18141,18 @@ unified@^10.0.0:
1809518141
trough "^2.0.0"
1809618142
vfile "^5.0.0"
1809718143

18144+
unified@^9.2.2:
18145+
version "9.2.2"
18146+
resolved "https://registry.yarnpkg.com/unified/-/unified-9.2.2.tgz#67649a1abfc3ab85d2969502902775eb03146975"
18147+
integrity sha512-Sg7j110mtefBD+qunSLO1lqOEKdrwBFBrR6Qd8f4uwkhWNlbkaqwHse6e7QvD3AP/MNoJdEDLaf8OxYyoWgorQ==
18148+
dependencies:
18149+
bail "^1.0.0"
18150+
extend "^3.0.0"
18151+
is-buffer "^2.0.0"
18152+
is-plain-obj "^2.0.0"
18153+
trough "^1.0.0"
18154+
vfile "^4.0.0"
18155+
1809818156
union-value@^1.0.0:
1809918157
version "1.0.1"
1810018158
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847"
@@ -18168,7 +18226,7 @@ unist-util-position-from-estree@^1.0.0, unist-util-position-from-estree@^1.1.0:
1816818226
dependencies:
1816918227
"@types/unist" "^2.0.0"
1817018228

18171-
unist-util-position@^3.0.0:
18229+
unist-util-position@^3.0.0, unist-util-position@^3.1.0:
1817218230
version "3.1.0"
1817318231
resolved "https://registry.yarnpkg.com/unist-util-position/-/unist-util-position-3.1.0.tgz#1c42ee6301f8d52f47d14f62bbdb796571fa2d47"
1817418232
integrity sha512-w+PkwCbYSFw8vpgWD0v7zRCl1FpY3fjDSQ3/N/wNd9Ffa4gPi8+4keqt99N3XW6F99t/mUzp2xAhNmfKWp95QA==

0 commit comments

Comments
 (0)