Skip to content

Commit 23350dc

Browse files
authored
Merge pull request #49 from sikepuri-algorithm/feature-jupyter-in-react
2 parents 0e2b869 + c644b0f commit 23350dc

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/components/ViewSource/ViewSource.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable react/prop-types */
22
import React, { useState, useEffect } from "react";
33
import usePathname from "../usePathname";
4+
import CodeBlock from "@theme/CodeBlock";
45
import JupyterViewer from "react-jupyter-notebook";
56
import OpenInColab from "../OpenInColab/OpenInColab";
7+
import "./styles.css";
68

79
/**
810
* ipynbファイルからソースコードと出力、OpenInColabへのリンクを生成
@@ -13,21 +15,36 @@ import OpenInColab from "../OpenInColab/OpenInColab";
1315

1416
export default function ViewSource({ path }) {
1517
const pathname = usePathname();
18+
const [sources, setSources] = useState<string[]>([]);
1619
const [content, setContent] = useState();
1720
useEffect(() => {
1821
async function tmp() {
1922
// 該当のipynbファイルをjson形式でとってくる
2023
const json = await import(
2124
`/docs/${pathname.slice(6)}${path.slice(0, -6)}.json`
2225
);
26+
setSources(
27+
json.cells
28+
.filter((cell) => cell.cell_type === "code")
29+
.map((cell) => cell.source.join(""))
30+
);
2331
setContent(json);
2432
}
2533
tmp();
2634
}, []);
2735
return (
2836
<>
37+
{sources.map((source, i) => (
38+
<React.Fragment key={i}>
39+
<CodeBlock language="python">{source}</CodeBlock>
40+
</React.Fragment>
41+
))}
2942
{content !== undefined && (
30-
<JupyterViewer rawIpynb={content} language="python" />
43+
<JupyterViewer
44+
rawIpynb={content}
45+
language="python"
46+
displaySource="hide"
47+
/>
3148
)}
3249
<OpenInColab path={path} />
3350
</>

src/components/ViewSource/styles.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.block-light {
2+
display: none;
3+
}
4+
5+
.block-hidden {
6+
display: none;
7+
}
8+
9+
.cell-header {
10+
display: none;
11+
}
12+
13+
.block-light-selected {
14+
display: none;
15+
}

0 commit comments

Comments
 (0)