-
Notifications
You must be signed in to change notification settings - Fork 131
Complete ipynb export support #1915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
35d4e45
9820179
7d8218a
2747ecc
1975f85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,25 +12,43 @@ function sourceToStringList(src: string): string[] { | |
| return lines; | ||
| } | ||
|
|
||
| function markdownString(file: VFile, md_cells: Block[]) { | ||
| const md = writeMd(file, { type: 'root', children: md_cells }).result as string; | ||
| return { | ||
| cell_type: 'markdown', | ||
| metadata: {}, | ||
| source: sourceToStringList(md), | ||
| }; | ||
| } | ||
|
|
||
| export function writeIpynb(file: VFile, node: Root, frontmatter?: PageFrontmatter) { | ||
| const cells = (node.children as Block[]).map((block: Block) => { | ||
| const cells = []; | ||
| const md_cells: Block[] = []; | ||
|
|
||
| for (const block of node.children as Block[]) { | ||
| if (block.type === 'block' && block.kind === 'notebook-code') { | ||
| if (md_cells.length != 0) { | ||
| cells.push(markdownString(file, md_cells)); | ||
| md_cells.length = 0; | ||
| } | ||
| const code = select('code', block) as Code; | ||
| return { | ||
| cells.push({ | ||
| cell_type: 'code', | ||
| execution_count: null, | ||
| metadata: {}, | ||
| outputs: [], | ||
| source: sourceToStringList(code.value), | ||
| }; | ||
| }); | ||
| } else { | ||
| md_cells.push(block); | ||
| } | ||
| const md = writeMd(file, { type: 'root', children: block.children as any }).result as string; | ||
| return { | ||
| cell_type: 'markdown', | ||
| metadata: {}, | ||
| source: sourceToStringList(md), | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| if (md_cells.length != 0) { | ||
| cells.push(markdownString(file, md_cells)); | ||
|
||
| md_cells.length = 0; | ||
| } | ||
|
|
||
| const ipynb = { | ||
| cells, | ||
| metadata: { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.