File tree 29 files changed +1254
-24
lines changed
29 files changed +1254
-24
lines changed Original file line number Diff line number Diff line change 4
4
< title > Code Hike in the browser</ title >
5
5
< link
6
6
rel ="stylesheet "
7
- href ="https://esm.sh/@code-hike/mdx@0.4.0 -next.1 /dist/index.css "
7
+ href ="https://esm.sh/@code-hike/mdx@0.5.2 -next.2 /dist/index.css "
8
8
/>
9
9
</ head >
10
10
< body >
13
13
< script type ="module ">
14
14
import React from "https://esm.sh/react"
15
15
import ReactDOM from "https://esm.sh/react-dom"
16
- import { evaluate } from "https://esm.sh/@mdx-js/mdx?dev "
16
+ import { evaluate } from "https://esm.sh/@mdx-js/mdx?bundle "
17
17
import * as runtime from "https://esm.sh/react/jsx-runtime.js"
18
18
19
- import { remarkCodeHike } from "https://esm.sh/@code-hike/mdx@0.4.0 -next.1 /dist/index.browser.mjs"
20
- import { CH } from "https://esm.sh/@code-hike/mdx@0.4.0 -next.1 /components"
21
- import theme from "https://esm.sh/[email protected] /themes/nord .json" assert { type : "
json "
}
19
+ import { remarkCodeHike } from "https://esm.sh/@code-hike/mdx@0.5.2 -next.2 /dist/index.browser.mjs?bundle "
20
+ import { CH } from "https://esm.sh/@code-hike/mdx@0.5.2 -next.2 /components"
21
+ import theme from "https://esm.sh/[email protected] /themes/dracula .json" assert { type : "
json "
}
22
22
23
23
const mdx = `# Test
24
24
25
- ~~~python hello.py mark=1[22:30]
26
- print("Rendered with Code Hike")
27
- ~~~
25
+ <CH.Code>
26
+
27
+ ~~~python hello.py mark=1[22:30]
28
+ print("Rendered with Code Hike")
29
+ ~~~
30
+
31
+ ~~~js hello.js mark=1[23:36]
32
+ console.log("Rendered with Code Hike")
33
+ ~~~
34
+
35
+ </CH.Code>
28
36
`
29
37
30
38
const { default : Content } = await evaluate ( mdx , {
Original file line number Diff line number Diff line change 4
4
"packages" : [
5
5
" packages/mdx" ,
6
6
" examples/*" ,
7
+ " playground" ,
7
8
" site"
8
9
]
9
10
},
10
11
"scripts" : {
11
12
"build" : " lerna run --stream build" ,
12
13
"build:lib" : " lerna run --stream --scope @*/mdx build" ,
14
+ "build:playground" : " lerna run --stream --scope playground build" ,
13
15
"test" : " lerna run --stream test" ,
14
16
"dev" : " lerna run --stream --scope @*/mdx dev" ,
15
17
"release" : " auto shipit"
Original file line number Diff line number Diff line change
1
+ Test nested syntax highlighting
2
+
3
+ ```` md hi.md
4
+ # Hi
5
+
6
+ ```js
7
+ export default {
8
+ data() {
9
+ return {
10
+ greeting: "Hello World!",
11
+ }
12
+ },
13
+ }
14
+ ```
15
+
16
+ [lorem](https://loremipsum.com)
17
+ ````
18
+
19
+ ``` js hi.js
20
+ export default {
21
+ data () {
22
+ return {
23
+ greeting: " Hello World!" ,
24
+ }
25
+ },
26
+ }
27
+ ```
Original file line number Diff line number Diff line change 1
1
import fs from "fs"
2
2
import { remarkCodeHike } from "../src/index"
3
3
import { compile } from "@mdx-js/mdx"
4
- import theme from "shiki/themes/nord .json"
4
+ import theme from "shiki/themes/rose-pine-moon .json"
5
5
import { withDebugger } from "mdx-debugger"
6
6
7
7
export async function getFiles ( ) {
Original file line number Diff line number Diff line change 34
34
"scripts" : {
35
35
"dev" : " next" ,
36
36
"build" : " rollup -c rollup.config.js" ,
37
+ "watch" : " rollup --watch -c rollup.config.js" ,
37
38
"test" : " vitest" ,
38
39
"coverage" : " vitest run --coverage"
39
40
},
71
72
"react-json-view" : " ^1.21.3" ,
72
73
"rollup" : " ^2.41.2" ,
73
74
"rollup-plugin-delete" : " ^2.0.0" ,
75
+ "rollup-plugin-dts" : " ^4.2.1" ,
74
76
"rollup-plugin-postcss" : " ^4.0.0" ,
75
77
"rollup-plugin-typescript2" : " ^0.27.1" ,
76
78
"sass" : " ^1.49.9" ,
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import path from "path"
8
8
import json from "@rollup/plugin-json"
9
9
import del from "rollup-plugin-delete"
10
10
import replace from "@rollup/plugin-replace"
11
+ import dts from "rollup-plugin-dts"
11
12
import { nodeResolve } from "@rollup/plugin-node-resolve"
12
13
// import { terser } from "rollup-plugin-terser"
13
14
import commonjs from "@rollup/plugin-commonjs"
@@ -72,6 +73,12 @@ export default function makeConfig(commandOptions) {
72
73
} ) ,
73
74
] ,
74
75
} ,
76
+ {
77
+ input : `src/index.tsx` ,
78
+ output : [ { file : `./dist/index.d.ts` , format : "es" } ] ,
79
+ external : [ ...remarkExternal , "shiki" ] ,
80
+ plugins : [ dts ( ) ] ,
81
+ } ,
75
82
// for the browser esm we need to replace shiki with shiki/dist/index.browser.mjs
76
83
// https://github.com/shikijs/shiki/issues/131#issuecomment-1094281851
77
84
{
@@ -125,5 +132,13 @@ export default function makeConfig(commandOptions) {
125
132
} ) ,
126
133
] ,
127
134
} ,
135
+ {
136
+ input : `src/components.tsx` ,
137
+ output : [
138
+ { file : `./dist/components.d.ts` , format : "es" } ,
139
+ ] ,
140
+ external : clientExternal ,
141
+ plugins : [ dts ( ) ] ,
142
+ } ,
128
143
]
129
144
}
Original file line number Diff line number Diff line change @@ -33,11 +33,17 @@ export async function highlight({
33
33
}
34
34
}
35
35
if ( highlighterPromise === null ) {
36
+ const isBrowser = typeof window !== "undefined"
37
+ // if we are on the server we load all the languages
38
+ // if we are on the browser just load the first language
39
+ // subsequent calls with different languages will lazy load
40
+ const langs = isBrowser ? [ lang as Lang ] : undefined
41
+
36
42
// TODO add version
37
43
setCDN ( "https://unpkg.com/shiki/" )
38
44
highlighterPromise = getHighlighter ( {
39
45
theme : theme as IShikiTheme ,
40
- // langs: [lang as Lang], // TODO change lang from string to Lang
46
+ langs,
41
47
} )
42
48
}
43
49
Original file line number Diff line number Diff line change 5
5
EditorProps ,
6
6
EditorStep ,
7
7
} from "../mini-editor"
8
- import { CodeHikeConfig } from "remark/config"
8
+ import { CodeHikeConfig } from "../ remark/config"
9
9
10
10
export function Code (
11
11
props : EditorProps & Partial < CodeHikeConfig >
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ export const EditorFrame = React.forwardRef<
63
63
style = { {
64
64
background : getColor (
65
65
theme ,
66
- ColorName . EditorGroupHeaderBackground
66
+ ColorName . EditorBackground
67
67
) ,
68
68
...style ,
69
69
} }
@@ -72,6 +72,10 @@ export const EditorFrame = React.forwardRef<
72
72
className = { "ch-frame-title-bar" }
73
73
style = { {
74
74
color : getColor ( theme , ColorName . IconForeground ) ,
75
+ background : getColor (
76
+ theme ,
77
+ ColorName . EditorGroupHeaderBackground
78
+ ) ,
75
79
} }
76
80
>
77
81
< TabsContainer
@@ -98,6 +102,10 @@ export const EditorFrame = React.forwardRef<
98
102
theme ,
99
103
ColorName . IconForeground
100
104
) ,
105
+ background : getColor (
106
+ theme ,
107
+ ColorName . EditorGroupHeaderBackground
108
+ ) ,
101
109
} }
102
110
>
103
111
< TabsContainer
Original file line number Diff line number Diff line change @@ -28,11 +28,25 @@ export function getCommentData(
28
28
}
29
29
}
30
30
31
+ function getTextAfter (
32
+ line : Code [ "lines" ] [ 0 ] ,
33
+ prefix : string
34
+ ) {
35
+ const firstIndex = line . tokens . findIndex ( t =>
36
+ t . content . trim ( ) . startsWith ( prefix )
37
+ )
38
+ if ( firstIndex === - 1 ) {
39
+ return undefined
40
+ }
41
+ return line . tokens
42
+ . slice ( firstIndex )
43
+ . map ( t => t . content )
44
+ . join ( "" )
45
+ }
46
+
31
47
const commentRegex = / \/ \/ \s + ( \w + ) ( \S * ) \s * ( .* ) /
32
48
function otherComment ( line : Code [ "lines" ] [ 0 ] ) {
33
- const comment = line . tokens . find ( t =>
34
- t . content . trim ( ) . startsWith ( "//" )
35
- ) ?. content
49
+ const comment = getTextAfter ( line , "//" )
36
50
37
51
if ( ! comment ) {
38
52
return [ ]
@@ -56,9 +70,7 @@ const bashLikeLangs = [
56
70
]
57
71
const bashLikeCommentRegex = / # \s + ( \w + ) ( \S * ) \s * ( .* ) /
58
72
function bashLikeComment ( line : Code [ "lines" ] [ 0 ] ) {
59
- const comment = line . tokens . find ( t =>
60
- t . content . trim ( ) . startsWith ( "#" )
61
- ) ?. content
73
+ const comment = getTextAfter ( line , "#" )
62
74
63
75
if ( ! comment ) {
64
76
return [ ]
Original file line number Diff line number Diff line change 1
- import fetch from "node-fetch"
2
1
import { visitAsync , toJSX } from "./unist-utils"
3
2
import { JsxNode , SuperNode } from "./nodes"
4
3
@@ -14,6 +13,7 @@ export async function getPresetConfig(
14
13
const prefix = "https://codesandbox.io/s/"
15
14
const csbid = url . slice ( prefix . length )
16
15
const configUrl = `https://codesandbox.io/api/v1/sandboxes/${ csbid } /sandpack`
16
+ const { default : fetch } = await import ( "node-fetch" )
17
17
const res = await fetch ( configUrl )
18
18
return await res . json ( )
19
19
}
Original file line number Diff line number Diff line change 12
12
" esnext"
13
13
],
14
14
"importHelpers" : true ,
15
- "declaration" : true ,
15
+ "declaration" : false ,
16
16
"sourceMap" : true ,
17
17
"strict" : false ,
18
18
"noUnusedLocals" : false ,
39
39
"forceConsistentCasingInFileNames" : true ,
40
40
"noEmit" : true ,
41
41
"isolatedModules" : true ,
42
- "incremental" : true
42
+ "incremental" : true ,
43
+ "tsBuildInfoFile" : " ./dist/tsbuildinfo.json"
43
44
},
44
45
"exclude" : [
45
46
" node_modules"
Original file line number Diff line number Diff line change
1
+ # Logs
2
+ logs
3
+ * .log
4
+ npm-debug.log *
5
+ yarn-debug.log *
6
+ yarn-error.log *
7
+ pnpm-debug.log *
8
+ lerna-debug.log *
9
+
10
+ node_modules
11
+ dist
12
+ dist-ssr
13
+ * .local
14
+
15
+ # Editor directories and files
16
+ .vscode /*
17
+ ! .vscode /extensions.json
18
+ .idea
19
+ .DS_Store
20
+ * .suo
21
+ * .ntvs *
22
+ * .njsproj
23
+ * .sln
24
+ * .sw ?
25
+
26
+
27
+ # Contentlayer
28
+ .contentlayer
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 " />
5
+ < link rel ="icon " type ="image/svg+xml " href ="/src/favicon.ico " />
6
+ < link rel ="icon " type ="image/png " sizes ="32x32 " href ="/favicon-32x32.png " />
7
+ < link rel ="icon " type ="image/png " sizes ="16x16 " href ="/favicon-16x16.png " />
8
+ < meta
9
+ property ="description "
10
+ content ="Try Code Hike directly in your browser "
11
+ />
12
+ < meta property ="og:title " content ="Code Hike Playground " />
13
+ < meta
14
+ property ="og:description "
15
+ content ="Try Code Hike directly in your browser "
16
+ />
17
+ < meta name ="twitter:site " content ="@codehike_ " />
18
+ <!-- <meta name="twitter:card" content="summary_large_image" />
19
+ <meta name="image" content="{imageUrl}" />
20
+ <meta itemprop="image" content="{imageUrl}" />
21
+ <meta name="twitter:image" content="{imageUrl}" />
22
+ <meta property="og:image" content="{imageUrl}" /> -->
23
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
24
+ < title > Code Hike Playground</ title >
25
+ </ head >
26
+ < body >
27
+ < div id ="root "> </ div >
28
+ < script type ="module " src ="/src/main.jsx "> </ script >
29
+ </ body >
30
+ </ html >
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " playground" ,
3
+ "private" : true ,
4
+ "version" : " 0.0.0" ,
5
+ "scripts" : {
6
+ "dev" : " vite" ,
7
+ "build" : " vite build" ,
8
+ "preview" : " vite preview"
9
+ },
10
+ "dependencies" : {
11
+ "@code-hike/mdx" : " ^0.5.1" ,
12
+ "@mdx-js/mdx" : " ^2.1.1" ,
13
+ "@monaco-editor/react" : " ^4.4.5" ,
14
+ "lz-string" : " ^1.4.4" ,
15
+ "react" : " ^17.0.2" ,
16
+ "react-dom" : " ^17.0.2" ,
17
+ "react-error-boundary" : " ^3.1.4" ,
18
+ "react-split-pane" : " ^0.1.92"
19
+ },
20
+ "devDependencies" : {
21
+ "@types/react" : " ^17.0.2" ,
22
+ "@types/react-dom" : " ^17.0.2" ,
23
+ "@vitejs/plugin-react" : " ^1.3.0" ,
24
+ "vite" : " ^2.9.9"
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments