Skip to content

Commit 127df87

Browse files
authored
Merge pull request #219 from code-hike/next
v0.6.2
2 parents a1cfc6c + 8030656 commit 127df87

26 files changed

+318
-72
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("hello foo")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello foo")

packages/mdx/dev/content/external.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```js foo.js
2+
// from ./assets/foo.js
3+
```
4+
5+
```py foo.py
6+
# from ./assets/foo.py
7+
```
8+
9+
```py foo.py
10+
print("not external")
11+
# from ./assets/foo.py
12+
```
13+
14+
<CH.Code>
15+
16+
```js foo.js
17+
// from ./assets/foo.js
18+
```
19+
20+
```py foo.py
21+
# from ./assets/foo.py
22+
```
23+
24+
```html index.html
25+
<h1>Hello</h1>
26+
```
27+
28+
---
29+
30+
```py another.py
31+
# from ./assets/foo.py
32+
```
33+
34+
</CH.Code>

packages/mdx/dev/content/test.mdx

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,79 @@
1+
### with width
2+
3+
<CH.Code debug >
4+
15
```js
2-
foo
3-
// link(1:2) https://codehike.org
4-
const hi = 'hi'
5-
const hi = 'hi'
6-
const hi = 'hi'
7-
// link[2:18] https://codehike.org
8-
hello world
9-
hello
6+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
7+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
108
```
9+
10+
</CH.Code>
11+
12+
<CH.Code>
13+
14+
```js
15+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
16+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
17+
```
18+
19+
</CH.Code>
20+
21+
### with width
22+
23+
<CH.Code debug style={{width: 400}}>
24+
25+
```js
26+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
27+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
28+
```
29+
30+
</CH.Code>
31+
32+
<CH.Code style={{width: 400}}>
33+
34+
```js
35+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
36+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
37+
```
38+
39+
</CH.Code>
40+
41+
### with zoom
42+
43+
<CH.Code debug maxZoom={0.7} minZoom={0.7}>
44+
45+
```js
46+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
47+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
48+
```
49+
50+
</CH.Code>
51+
52+
<CH.Code maxZoom={0.7} minZoom={0.7}>
53+
54+
```js
55+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
56+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
57+
```
58+
59+
</CH.Code>
60+
61+
### with line numbers
62+
63+
<CH.Code debug lineNumbers>
64+
65+
```js
66+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
67+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
68+
```
69+
70+
</CH.Code>
71+
72+
<CH.Code lineNumbers>
73+
74+
```js
75+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
76+
const = "hello" + "hello" + "hello" + "hello" + "hello" + "hello"+ "hello" + "goodbye"
77+
```
78+
79+
</CH.Code>

packages/mdx/dev/files.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ export async function getFiles() {
1010
.filter(file => file.endsWith(".mdx"))
1111
.map(filename => filename.slice(0, -4))
1212
}
13-
export async function getContent(filename: string) {
14-
const file = await fs.promises.readFile(
15-
`./dev/content/${filename}.mdx`,
16-
"utf8"
17-
)
13+
export async function getFile(filename: string) {
14+
const path = `./dev/content/${filename}.mdx`
15+
const file = await fs.promises.readFile(path, "utf8")
1816

19-
return file
17+
return { value: file, path }
2018
}
2119

22-
export async function getCode(file: string, config = {}) {
20+
export async function getCode(file: any, config = {}) {
2321
let debugLink = ""
2422

2523
const debugCompile = withDebugger(compile, {
@@ -36,6 +34,7 @@ export async function getCode(file: string, config = {}) {
3634
remarkCodeHike,
3735
{
3836
autoImport: false,
37+
skipLanguages: ["", "mermaid"],
3938
showCopyButton: true,
4039
theme,
4140
...config,

packages/mdx/pages/[name].tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { runSync } from "@mdx-js/mdx"
22
import * as runtime from "react/jsx-runtime.js"
33
import { CH } from "../src/components"
4-
import { getCode, getContent, getFiles } from "../dev/files"
4+
import { getCode, getFile, getFiles } from "../dev/files"
55
import { ClickToComponent } from "click-to-react-component"
66
import { Layout } from "../dev/layout"
77

@@ -17,8 +17,8 @@ export async function getStaticProps({ params }) {
1717
const { name = "test" } = params
1818

1919
const files = await getFiles()
20-
const content = await getContent(name)
21-
const { code, debugLink } = await getCode(content)
20+
const file = await getFile(name)
21+
const { code, debugLink } = await getCode(file)
2222
return {
2323
props: {
2424
tests: files,

packages/mdx/src/mdx-client/code.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function mergeCodeConfig<T>(
5555
showExpandButton == null
5656
? props.codeConfig?.showExpandButton
5757
: showExpandButton,
58+
debug: props.debug ?? props.codeConfig?.debug,
5859
}
5960
return { ...rest, codeConfig }
6061
}

packages/mdx/src/mdx-client/scrollycoding.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
display: flex;
33
position: relative;
44
margin: 1rem 0;
5+
gap: 1rem;
56
}
67

78
.ch-scrollycoding-content {
89
box-sizing: border-box;
9-
padding-right: 16px;
1010
flex: 1;
1111
}
1212

packages/mdx/src/mdx-client/scrollycoding.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ export function Scrollycoding({
1111
codeConfig,
1212
presetConfig,
1313
start = 0,
14+
className,
15+
style,
1416
...rest
1517
}: {
1618
children: React.ReactNode
1719
editorSteps: EditorStep[]
1820
codeConfig: EditorProps["codeConfig"]
1921
start?: number
2022
presetConfig?: PresetConfig
23+
className?: string
24+
style?: React.CSSProperties
2125
}) {
2226
const stepsChildren = React.Children.toArray(children)
2327

@@ -58,7 +62,8 @@ export function Scrollycoding({
5862
<section
5963
className={`ch-scrollycoding ${
6064
presetConfig ? "ch-scrollycoding-with-preview" : ""
61-
}`}
65+
} ${className || ""}`}
66+
style={style}
6267
>
6368
<div className="ch-scrollycoding-content">
6469
<Scroller onStepChange={onStepChange}>

packages/mdx/src/mdx-client/section.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ const SectionContext = React.createContext<{
1616

1717
export function Section({
1818
children,
19+
className,
20+
style,
1921
...props
2022
}: {
2123
children: React.ReactNode
24+
className?: string
25+
style?: React.CSSProperties
2226
}) {
2327
const [state, setState] = React.useState<any>(props)
2428

@@ -45,7 +49,10 @@ export function Section({
4549
const { selectedId, ...rest } = state
4650

4751
return (
48-
<section>
52+
<section
53+
className={`ch-section ${className || ""}`}
54+
style={style}
55+
>
4956
<SectionContext.Provider
5057
value={{
5158
props: rest,

packages/mdx/src/mdx-client/slideshow.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ export function Slideshow({
99
codeConfig,
1010
presetConfig,
1111
code,
12+
className,
13+
style,
1214
...rest
1315
}: {
1416
children: React.ReactNode
1517
editorSteps: EditorStep[]
1618
codeConfig: EditorProps["codeConfig"]
1719
presetConfig?: PresetConfig
1820
code?: EditorProps["codeConfig"]
21+
className?: string
22+
style?: React.CSSProperties
1923
}) {
2024
const stepsChildren = React.Children.toArray(children)
2125

@@ -42,7 +46,8 @@ export function Slideshow({
4246
<div
4347
className={`ch-slideshow ${
4448
presetConfig ? "ch-slideshow-with-preview" : ""
45-
}`}
49+
} ${className || ""}`}
50+
style={style}
4651
>
4752
<div className="ch-slideshow-slide">
4853
<InnerCode

packages/mdx/src/mdx-client/spotlight.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
.ch-spotlight {
22
display: flex;
3-
gap: 0.5rem;
3+
gap: 1.1rem;
44
margin: 1rem 0;
55
}
66

77
.ch-spotlight-tabs {
88
display: flex;
99
flex-flow: column;
10-
margin-right: 10px;
1110
flex: 1;
1211
gap: 0.5rem;
1312
align-items: stretch;

packages/mdx/src/mdx-client/spotlight.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ export function Spotlight({
99
codeConfig,
1010
start = 0,
1111
presetConfig,
12+
className,
13+
style,
1214
...rest
1315
}: {
1416
children: React.ReactNode
1517
editorSteps: EditorStep[]
1618
codeConfig: EditorProps["codeConfig"]
1719
start?: number
1820
presetConfig?: PresetConfig
21+
className?: string
22+
style?: React.CSSProperties
1923
}) {
2024
const stepsChildren = React.Children.toArray(children)
2125

@@ -38,10 +42,11 @@ export function Spotlight({
3842
stepsChildren[0] as React.ReactElement
3943

4044
return (
41-
<div
45+
<section
4246
className={`ch-spotlight ${
4347
presetConfig ? "ch-spotlight-with-preview" : ""
44-
}`}
48+
} ${className || ""}`}
49+
style={style}
4550
>
4651
<div className="ch-spotlight-tabs">
4752
{headerElement?.props?.children ? (
@@ -83,6 +88,6 @@ export function Spotlight({
8388
/>
8489
)}
8590
</div>
86-
</div>
91+
</section>
8792
)
8893
}

packages/mdx/src/mini-editor/code-browser.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CodeFile } from "./editor-shift"
22
import { IRawTheme } from "vscode-textmate"
3-
import { ColorName, getColor } from "utils"
3+
import { ColorName, getColor, getColorScheme } from "utils"
44
import React from "react"
55

66
export function CodeBrowser({
@@ -189,15 +189,20 @@ function Content({
189189
theme,
190190
ColorName.SelectionBackground
191191
),
192+
colorScheme: getColorScheme(theme),
192193
}}
193194
>
194195
{file.code.lines.map((line, i) => (
195196
<div key={i}>
196-
{line.tokens.map((token, i) => (
197-
<span key={i} {...token.props}>
198-
{token.content}
199-
</span>
200-
))}
197+
{line.tokens.length === 0 ? (
198+
<br />
199+
) : (
200+
line.tokens.map((token, i) => (
201+
<span key={i} {...token.props}>
202+
{token.content}
203+
</span>
204+
))
205+
)}
201206
</div>
202207
))}
203208
</div>

0 commit comments

Comments
 (0)