@mdgate/ipynb 0.6.8 → 0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +142 -8
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  # @mdgate/ipynb
2
2
 
3
- Convert Jupyter notebooks to Markdown. Outputs GitHub-Flavored Markdown. Works in Node, Edge, and
4
- browsers. No native addons.
3
+ **Convert Jupyter notebooks to Markdown in TypeScript.**
5
4
 
6
- Handles: `.ipynb` (nbformat JSON)
5
+ [`@mdgate/ipynb`](https://github.com/mdgate/converters/tree/main/packages/ipynb) reads `.ipynb` files directly in JavaScript and converts cells into GitHub-Flavored Markdown, without Python, native addons, WASM, or Jupyter.
7
6
 
8
- ## Usage
7
+ Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
8
+
9
+ ```bash
10
+ npm install @mdgate/ipynb
11
+ ```
9
12
 
10
13
  ```ts
11
14
  import { toMarkdown } from '@mdgate/ipynb';
@@ -13,14 +16,145 @@ import { toMarkdown } from '@mdgate/ipynb';
13
16
  const markdown = await toMarkdown(bytes);
14
17
  ```
15
18
 
16
- Compose with other converters:
19
+ `bytes` is a `Uint8Array`, so the notebook can come from a file upload, object storage, a git checkout, a browser file picker, or anywhere else your application gets bytes.
20
+
21
+ ---
22
+
23
+ ## Why [`@mdgate/ipynb`](https://github.com/mdgate/converters/tree/main/packages/ipynb)
24
+
25
+ Notebooks mix prose, code, and outputs. Dumping the raw JSON is a poor input for search, RAG, or an agent.
26
+
27
+ [`@mdgate/ipynb`](https://github.com/mdgate/converters/tree/main/packages/ipynb) is a notebook reader written for the same runtime as your application:
28
+
29
+ * **Pure TypeScript**
30
+ * **Notebook → Markdown locally**
31
+ * **No Python runtime**
32
+ * **No native addons**
33
+ * **No WASM runtime**
34
+ * **Zero third-party runtime dependencies**
35
+ * **Works with raw `Uint8Array` input**
36
+ * **Detects nbformat JSON from its contents, not only the filename**
37
+
38
+ ---
39
+
40
+ ## What it extracts
41
+
42
+ [`@mdgate/ipynb`](https://github.com/mdgate/converters/tree/main/packages/ipynb) parses nbformat JSON and rebuilds a shared document model.
43
+
44
+ The converter handles notebook-specific concerns including:
45
+
46
+ * markdown cells as Markdown
47
+ * code cells as fenced code blocks
48
+ * cell outputs that can be represented as text
49
+ * cell order
50
+
51
+ The output is Markdown that can be searched, indexed, chunked, cached, or passed directly to an AI agent.
52
+
53
+ ---
54
+
55
+ ## Node.js
56
+
57
+ ```ts
58
+ import { readFile } from 'node:fs/promises';
59
+ import { toMarkdown } from '@mdgate/ipynb';
60
+
61
+ const bytes = new Uint8Array(await readFile('analysis.ipynb'));
62
+ const markdown = await toMarkdown(bytes);
63
+
64
+ console.log(markdown);
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Browser
70
+
71
+ ```ts
72
+ import { toMarkdown } from '@mdgate/ipynb';
73
+
74
+ const file = input.files![0];
75
+ const bytes = new Uint8Array(await file.arrayBuffer());
76
+
77
+ const markdown = await toMarkdown(bytes);
78
+ ```
79
+
80
+ ---
81
+
82
+ ## Cloudflare Workers and Edge runtimes
83
+
84
+ ```ts
85
+ import { toMarkdown } from '@mdgate/ipynb';
86
+
87
+ export default {
88
+ async fetch(request: Request) {
89
+ const bytes = new Uint8Array(await request.arrayBuffer());
90
+ const markdown = await toMarkdown(bytes);
91
+
92
+ return new Response(markdown, {
93
+ headers: {
94
+ 'content-type': 'text/markdown; charset=utf-8',
95
+ },
96
+ });
97
+ },
98
+ };
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Format detection
104
+
105
+ You do not need to trust the file extension.
106
+
107
+ [`@mdgate/ipynb`](https://github.com/mdgate/converters/tree/main/packages/ipynb) recognizes Jupyter notebooks from nbformat JSON.
108
+
109
+ ```ts
110
+ const markdown = await toMarkdown(bytes);
111
+ ```
112
+
113
+ A path can still be supplied as a format hint when [`@mdgate/ipynb`](https://github.com/mdgate/converters/tree/main/packages/ipynb) is used through [`@mdgate/converters`](https://github.com/mdgate/converters/tree/main/packages/converters) or a reader composed with [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core), but the path is never used to read a file from disk.
114
+
115
+ ---
116
+
117
+ ## Compose it with other file readers
118
+
119
+ [`@mdgate/ipynb`](https://github.com/mdgate/converters/tree/main/packages/ipynb) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
17
120
 
18
121
  ```ts
19
122
  import { create } from '@mdgate/core';
20
123
  import { ipynb } from '@mdgate/ipynb';
124
+ import { html } from '@mdgate/html';
125
+
126
+ const read = create([
127
+ ipynb(),
128
+ html(),
129
+ ]);
130
+ ```
131
+
132
+ The application still uses one reading interface while each format remains independently installable.
133
+
134
+ ---
135
+
136
+ ## Need more than notebooks?
137
+
138
+ If your application needs to read many different file types, use the complete converter set:
21
139
 
22
- const convert = create([ipynb()]);
140
+ ```bash
141
+ npm install @mdgate/converters
23
142
  ```
24
143
 
25
- Part of [mdgate converters](https://github.com/mdgate/converters); install
26
- `@mdgate/converters` for every format at once.
144
+ ```ts
145
+ import { toMarkdown } from '@mdgate/converters';
146
+
147
+ const markdown = await toMarkdown(bytes, {
148
+ path: filename,
149
+ });
150
+ ```
151
+
152
+ [`@mdgate/ipynb`](https://github.com/mdgate/converters/tree/main/packages/ipynb) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
153
+
154
+ For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
155
+
156
+ ---
157
+
158
+ ## License
159
+
160
+ MIT
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mdgate/ipynb",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "mdgate Jupyter notebook converter",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "homepage": "https://demo.mdgate.dev",
7
+ "homepage": "https://convert.mdgate.dev",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/mdgate/converters.git",
@@ -28,9 +28,9 @@
28
28
  "prepublishOnly": "bun run build"
29
29
  },
30
30
  "dependencies": {
31
- "@mdgate/core": "0.6.8",
32
- "@mdgate/document": "0.6.8",
33
- "@mdgate/utils": "0.6.8"
31
+ "@mdgate/core": "0.6.10",
32
+ "@mdgate/document": "0.6.10",
33
+ "@mdgate/utils": "0.6.10"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"