@jupyterlite/services 0.1.0 → 0.7.0-rc.0
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.
- package/lib/contents/drive.d.ts +277 -0
- package/lib/contents/drive.js +888 -0
- package/lib/contents/drive.js.map +1 -0
- package/lib/contents/drivecontents.d.ts +92 -0
- package/lib/contents/drivecontents.js +132 -0
- package/lib/contents/drivecontents.js.map +1 -0
- package/lib/contents/drivefs.d.ts +245 -0
- package/lib/contents/drivefs.js +481 -0
- package/lib/contents/drivefs.js.map +1 -0
- package/lib/contents/emscripten.d.ts +96 -0
- package/lib/contents/emscripten.js +10 -0
- package/lib/contents/emscripten.js.map +1 -0
- package/lib/contents/index.d.ts +5 -0
- package/lib/contents/index.js +8 -0
- package/lib/contents/index.js.map +1 -0
- package/lib/contents/tokens.d.ts +21 -0
- package/lib/contents/tokens.js +55 -0
- package/lib/contents/tokens.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/lib/kernel/base.d.ts +245 -0
- package/lib/kernel/base.js +457 -0
- package/lib/kernel/base.js.map +1 -0
- package/lib/kernel/client.d.ts +114 -0
- package/lib/kernel/client.js +375 -0
- package/lib/kernel/client.js.map +1 -0
- package/lib/kernel/index.d.ts +5 -0
- package/lib/kernel/index.js +8 -0
- package/lib/kernel/index.js.map +1 -0
- package/lib/kernel/kernelspecclient.d.ts +39 -0
- package/lib/kernel/kernelspecclient.js +37 -0
- package/lib/kernel/kernelspecclient.js.map +1 -0
- package/lib/kernel/kernelspecs.d.ts +59 -0
- package/lib/kernel/kernelspecs.js +62 -0
- package/lib/kernel/kernelspecs.js.map +1 -0
- package/lib/kernel/tokens.d.ts +163 -0
- package/lib/kernel/tokens.js +20 -0
- package/lib/kernel/tokens.js.map +1 -0
- package/lib/nbconvert/exporters.d.ts +80 -0
- package/lib/nbconvert/exporters.js +154 -0
- package/lib/nbconvert/exporters.js.map +1 -0
- package/lib/nbconvert/index.d.ts +3 -0
- package/lib/nbconvert/index.js +6 -0
- package/lib/nbconvert/index.js.map +1 -0
- package/lib/nbconvert/manager.d.ts +66 -0
- package/lib/nbconvert/manager.js +77 -0
- package/lib/nbconvert/manager.js.map +1 -0
- package/lib/nbconvert/tokens.d.ts +49 -0
- package/lib/nbconvert/tokens.js +8 -0
- package/lib/nbconvert/tokens.js.map +1 -0
- package/lib/session/client.d.ts +85 -0
- package/lib/session/client.js +200 -0
- package/lib/session/client.js.map +1 -0
- package/lib/session/index.d.ts +1 -0
- package/lib/session/index.js +4 -0
- package/lib/session/index.js.map +1 -0
- package/lib/settings/index.d.ts +1 -0
- package/lib/settings/index.js +4 -0
- package/lib/settings/index.js.map +1 -0
- package/lib/settings/settings.d.ts +91 -0
- package/lib/settings/settings.js +185 -0
- package/lib/settings/settings.js.map +1 -0
- package/package.json +67 -8
- package/src/contents/drive.ts +1030 -0
- package/src/contents/drivecontents.ts +253 -0
- package/src/contents/drivefs.ts +824 -0
- package/src/contents/emscripten.ts +148 -0
- package/src/contents/index.ts +8 -0
- package/src/contents/tokens.ts +61 -0
- package/src/index.ts +13 -0
- package/src/kernel/base.ts +637 -0
- package/src/kernel/client.ts +483 -0
- package/src/kernel/index.ts +8 -0
- package/src/kernel/kernelspecclient.ts +64 -0
- package/src/kernel/kernelspecs.ts +103 -0
- package/src/kernel/tokens.ts +222 -0
- package/src/nbconvert/exporters.ts +177 -0
- package/src/nbconvert/index.ts +6 -0
- package/src/nbconvert/manager.ts +105 -0
- package/src/nbconvert/tokens.ts +60 -0
- package/src/session/client.ts +251 -0
- package/src/session/index.ts +4 -0
- package/src/settings/index.ts +4 -0
- package/src/settings/settings.ts +236 -0
- package/style/index.css +6 -0
- package/style/index.js +6 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { Remote } from 'comlink';
|
|
2
|
+
import { IObservableMap } from '@jupyterlab/observables';
|
|
3
|
+
import { Kernel, KernelMessage, KernelSpec } from '@jupyterlab/services';
|
|
4
|
+
import { Token } from '@lumino/coreutils';
|
|
5
|
+
import { IObservableDisposable } from '@lumino/disposable';
|
|
6
|
+
import { ISignal } from '@lumino/signaling';
|
|
7
|
+
import { KernelSpecs } from './kernelspecs';
|
|
8
|
+
/**
|
|
9
|
+
* The kernel name of last resort.
|
|
10
|
+
*/
|
|
11
|
+
export declare const FALLBACK_KERNEL = "javascript";
|
|
12
|
+
/**
|
|
13
|
+
* The token for the kernel client.
|
|
14
|
+
*/
|
|
15
|
+
export declare const IKernelClient: Token<IKernelClient>;
|
|
16
|
+
/**
|
|
17
|
+
* An interface for the Kernels service.
|
|
18
|
+
*/
|
|
19
|
+
export interface IKernelClient extends Kernel.IKernelAPIClient {
|
|
20
|
+
/**
|
|
21
|
+
* Signal emitted when the kernels map changes
|
|
22
|
+
*/
|
|
23
|
+
readonly changed: ISignal<IKernelClient, IObservableMap.IChangedArgs<IKernel>>;
|
|
24
|
+
/**
|
|
25
|
+
* Handle stdin request received from Service Worker.
|
|
26
|
+
*/
|
|
27
|
+
handleStdin(inputRequest: KernelMessage.IInputRequestMsg): Promise<KernelMessage.IInputReplyMsg>;
|
|
28
|
+
/**
|
|
29
|
+
* Shut down all kernels.
|
|
30
|
+
*/
|
|
31
|
+
shutdownAll: () => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The token for the kernel spec client.
|
|
35
|
+
*/
|
|
36
|
+
export declare const IKernelSpecClient: Token<IKernelSpecClient>;
|
|
37
|
+
/**
|
|
38
|
+
* An interface for the kernel spec client.
|
|
39
|
+
*/
|
|
40
|
+
export interface IKernelSpecClient extends KernelSpec.IKernelSpecAPIClient {
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An interface for a kernel running in the browser.
|
|
44
|
+
*/
|
|
45
|
+
export interface IKernel extends IObservableDisposable {
|
|
46
|
+
/**
|
|
47
|
+
* The id of the server-side kernel.
|
|
48
|
+
*/
|
|
49
|
+
readonly id: string;
|
|
50
|
+
/**
|
|
51
|
+
* The name of the server-side kernel.
|
|
52
|
+
*/
|
|
53
|
+
readonly name: string;
|
|
54
|
+
/**
|
|
55
|
+
* The location in the virtual filesystem from which the kernel was started.
|
|
56
|
+
*/
|
|
57
|
+
readonly location: string;
|
|
58
|
+
/**
|
|
59
|
+
* A promise that is fulfilled when the kernel is ready.
|
|
60
|
+
*/
|
|
61
|
+
readonly ready: Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Handle an incoming message from the client.
|
|
64
|
+
*
|
|
65
|
+
* @param msg The message to handle
|
|
66
|
+
*/
|
|
67
|
+
handleMessage(msg: KernelMessage.IMessage): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A namespace for IKernel statics.
|
|
71
|
+
*/
|
|
72
|
+
export declare namespace IKernel {
|
|
73
|
+
/**
|
|
74
|
+
* The type for the send message function.
|
|
75
|
+
*/
|
|
76
|
+
type SendMessage = (msg: KernelMessage.IMessage) => void;
|
|
77
|
+
/**
|
|
78
|
+
* The instantiation options for an IKernel.
|
|
79
|
+
*/
|
|
80
|
+
interface IOptions {
|
|
81
|
+
/**
|
|
82
|
+
* The kernel id.
|
|
83
|
+
*/
|
|
84
|
+
id: string;
|
|
85
|
+
/**
|
|
86
|
+
* The name of the kernel.
|
|
87
|
+
*/
|
|
88
|
+
name: string;
|
|
89
|
+
/**
|
|
90
|
+
* The location in the virtual filesystem from which the kernel was started.
|
|
91
|
+
*/
|
|
92
|
+
location: string;
|
|
93
|
+
/**
|
|
94
|
+
* The method to send messages back to the server.
|
|
95
|
+
*/
|
|
96
|
+
sendMessage: SendMessage;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The token for the kernel spec service.
|
|
101
|
+
*/
|
|
102
|
+
export declare const IKernelSpecs: Token<IKernelSpecs>;
|
|
103
|
+
/**
|
|
104
|
+
* The interface for the kernel specs service.
|
|
105
|
+
*/
|
|
106
|
+
export interface IKernelSpecs {
|
|
107
|
+
/**
|
|
108
|
+
* Get the kernel specs.
|
|
109
|
+
*/
|
|
110
|
+
readonly specs: KernelSpec.ISpecModels | null;
|
|
111
|
+
/**
|
|
112
|
+
* Get the default kernel name.
|
|
113
|
+
*/
|
|
114
|
+
readonly defaultKernelName: string;
|
|
115
|
+
/**
|
|
116
|
+
* Get the kernel factories for the current kernels.
|
|
117
|
+
*/
|
|
118
|
+
readonly factories: KernelSpecs.KernelFactories;
|
|
119
|
+
/**
|
|
120
|
+
* Signal emitted when the specs change.
|
|
121
|
+
*/
|
|
122
|
+
readonly changed: ISignal<IKernelSpecs, KernelSpec.ISpecModels | null>;
|
|
123
|
+
/**
|
|
124
|
+
* Register a new kernel spec
|
|
125
|
+
*
|
|
126
|
+
* @param options The kernel spec options.
|
|
127
|
+
*/
|
|
128
|
+
register: (options: KernelSpecs.IKernelOptions) => void;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* An interface for a comlink-based worker kernel
|
|
132
|
+
*/
|
|
133
|
+
export interface IWorkerKernel {
|
|
134
|
+
/**
|
|
135
|
+
* Handle any lazy setup activities.
|
|
136
|
+
*/
|
|
137
|
+
initialize(options: IWorkerKernel.IOptions): Promise<void>;
|
|
138
|
+
execute(content: KernelMessage.IExecuteRequestMsg['content'], parent: any): Promise<KernelMessage.IExecuteReplyMsg['content']>;
|
|
139
|
+
complete(content: KernelMessage.ICompleteRequestMsg['content'], parent: any): Promise<KernelMessage.ICompleteReplyMsg['content']>;
|
|
140
|
+
inspect(content: KernelMessage.IInspectRequestMsg['content'], parent: any): Promise<KernelMessage.IInspectReplyMsg['content']>;
|
|
141
|
+
isComplete(content: KernelMessage.IIsCompleteRequestMsg['content'], parent: any): Promise<KernelMessage.IIsCompleteReplyMsg['content']>;
|
|
142
|
+
commInfo(content: KernelMessage.ICommInfoRequestMsg['content'], parent: any): Promise<KernelMessage.ICommInfoReplyMsg['content']>;
|
|
143
|
+
commOpen(content: KernelMessage.ICommOpenMsg, parent: any): Promise<void>;
|
|
144
|
+
commMsg(content: KernelMessage.ICommMsgMsg, parent: any): Promise<void>;
|
|
145
|
+
commClose(content: KernelMessage.ICommCloseMsg, parent: any): Promise<void>;
|
|
146
|
+
inputReply(content: KernelMessage.IInputReplyMsg['content'], parent: any): Promise<void>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A namespace for worker kernels.
|
|
150
|
+
**/
|
|
151
|
+
export declare namespace IWorkerKernel {
|
|
152
|
+
/**
|
|
153
|
+
* Common values likely to be required by all kernels.
|
|
154
|
+
*/
|
|
155
|
+
interface IOptions {
|
|
156
|
+
/**
|
|
157
|
+
* The base URL of the kernel server.
|
|
158
|
+
*/
|
|
159
|
+
baseUrl: string;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export interface IRemoteKernel extends Remote<IWorkerKernel> {
|
|
163
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { Token } from '@lumino/coreutils';
|
|
4
|
+
/**
|
|
5
|
+
* The kernel name of last resort.
|
|
6
|
+
*/
|
|
7
|
+
export const FALLBACK_KERNEL = 'javascript';
|
|
8
|
+
/**
|
|
9
|
+
* The token for the kernel client.
|
|
10
|
+
*/
|
|
11
|
+
export const IKernelClient = new Token('@jupyterlite/services:IKernelClient');
|
|
12
|
+
/**
|
|
13
|
+
* The token for the kernel spec client.
|
|
14
|
+
*/
|
|
15
|
+
export const IKernelSpecClient = new Token('@jupyterlite/services:IKernelSpecClient');
|
|
16
|
+
/**
|
|
17
|
+
* The token for the kernel spec service.
|
|
18
|
+
*/
|
|
19
|
+
export const IKernelSpecs = new Token('@jupyterlite/services:IKernelSpecs');
|
|
20
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/kernel/tokens.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAQ3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAQ1C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,KAAK,CACpC,qCAAqC,CACtC,CAAC;AAwBF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,KAAK,CACxC,yCAAyC,CAC1C,CAAC;AA0EF;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,KAAK,CACnC,oCAAoC,CACrC,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Contents } from '@jupyterlab/services';
|
|
2
|
+
import { IExporter } from './tokens';
|
|
3
|
+
/**
|
|
4
|
+
* Base class for notebook exporters.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseExporter implements IExporter {
|
|
7
|
+
/**
|
|
8
|
+
* The MIME type of the exported format.
|
|
9
|
+
*/
|
|
10
|
+
abstract readonly mimeType: string;
|
|
11
|
+
/**
|
|
12
|
+
* Export a notebook to this format.
|
|
13
|
+
*
|
|
14
|
+
* @param model The notebook model to export
|
|
15
|
+
* @param path The path to the notebook
|
|
16
|
+
*/
|
|
17
|
+
abstract export(model: Contents.IModel, path: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Trigger a browser download of the exported content.
|
|
20
|
+
*
|
|
21
|
+
* @param content The content to download
|
|
22
|
+
* @param mimeType The MIME type of the content
|
|
23
|
+
* @param filename The filename for the download
|
|
24
|
+
*/
|
|
25
|
+
protected triggerDownload(content: string, mimeType: string, filename: string): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Exporter for notebook format (.ipynb).
|
|
29
|
+
*/
|
|
30
|
+
export declare class NotebookExporter extends BaseExporter {
|
|
31
|
+
/**
|
|
32
|
+
* The MIME type of the exported format.
|
|
33
|
+
*/
|
|
34
|
+
readonly mimeType = "application/x-ipynb+json";
|
|
35
|
+
/**
|
|
36
|
+
* Export a notebook to .ipynb format.
|
|
37
|
+
*
|
|
38
|
+
* @param model The notebook model to export
|
|
39
|
+
* @param path The path to the notebook
|
|
40
|
+
*/
|
|
41
|
+
export(model: Contents.IModel, path: string): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Exporter for executable script format.
|
|
45
|
+
*/
|
|
46
|
+
export declare class ScriptExporter extends BaseExporter {
|
|
47
|
+
/**
|
|
48
|
+
* The MIME type of the exported format.
|
|
49
|
+
*/
|
|
50
|
+
readonly mimeType = "text/x-script";
|
|
51
|
+
/**
|
|
52
|
+
* Export a notebook to executable script format.
|
|
53
|
+
*
|
|
54
|
+
* @param model The notebook model to export
|
|
55
|
+
* @param path The path to the notebook
|
|
56
|
+
*/
|
|
57
|
+
export(model: Contents.IModel, path: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Convert a notebook to a script file.
|
|
60
|
+
*
|
|
61
|
+
* @param content The notebook content
|
|
62
|
+
* @returns The script content and file extension
|
|
63
|
+
*/
|
|
64
|
+
private convertToScript;
|
|
65
|
+
/**
|
|
66
|
+
* Comment out lines based on the language.
|
|
67
|
+
*
|
|
68
|
+
* @param text The text to comment
|
|
69
|
+
* @param language The programming language
|
|
70
|
+
* @returns The commented text
|
|
71
|
+
*/
|
|
72
|
+
private commentLines;
|
|
73
|
+
/**
|
|
74
|
+
* Get the comment character for a given language.
|
|
75
|
+
*
|
|
76
|
+
* @param language The programming language
|
|
77
|
+
* @returns The comment character(s) for that language
|
|
78
|
+
*/
|
|
79
|
+
private getCommentChar;
|
|
80
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
/**
|
|
4
|
+
* Base class for notebook exporters.
|
|
5
|
+
*/
|
|
6
|
+
export class BaseExporter {
|
|
7
|
+
/**
|
|
8
|
+
* Trigger a browser download of the exported content.
|
|
9
|
+
*
|
|
10
|
+
* @param content The content to download
|
|
11
|
+
* @param mimeType The MIME type of the content
|
|
12
|
+
* @param filename The filename for the download
|
|
13
|
+
*/
|
|
14
|
+
triggerDownload(content, mimeType, filename) {
|
|
15
|
+
const element = document.createElement('a');
|
|
16
|
+
element.href = `data:${mimeType};charset=utf-8,${encodeURIComponent(content)}`;
|
|
17
|
+
element.download = filename;
|
|
18
|
+
document.body.appendChild(element);
|
|
19
|
+
element.click();
|
|
20
|
+
document.body.removeChild(element);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Exporter for notebook format (.ipynb).
|
|
25
|
+
*/
|
|
26
|
+
export class NotebookExporter extends BaseExporter {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
/**
|
|
30
|
+
* The MIME type of the exported format.
|
|
31
|
+
*/
|
|
32
|
+
this.mimeType = 'application/x-ipynb+json';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Export a notebook to .ipynb format.
|
|
36
|
+
*
|
|
37
|
+
* @param model The notebook model to export
|
|
38
|
+
* @param path The path to the notebook
|
|
39
|
+
*/
|
|
40
|
+
async export(model, path) {
|
|
41
|
+
var _a;
|
|
42
|
+
const mime = (_a = model.mimetype) !== null && _a !== void 0 ? _a : 'application/json';
|
|
43
|
+
const content = JSON.stringify(model.content, null, 2);
|
|
44
|
+
this.triggerDownload(content, mime, path);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Exporter for executable script format.
|
|
49
|
+
*/
|
|
50
|
+
export class ScriptExporter extends BaseExporter {
|
|
51
|
+
constructor() {
|
|
52
|
+
super(...arguments);
|
|
53
|
+
/**
|
|
54
|
+
* The MIME type of the exported format.
|
|
55
|
+
*/
|
|
56
|
+
this.mimeType = 'text/x-script';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Export a notebook to executable script format.
|
|
60
|
+
*
|
|
61
|
+
* @param model The notebook model to export
|
|
62
|
+
* @param path The path to the notebook
|
|
63
|
+
*/
|
|
64
|
+
async export(model, path) {
|
|
65
|
+
const { content, extension } = this.convertToScript(model.content);
|
|
66
|
+
const filename = path.replace(/\.ipynb$/, extension);
|
|
67
|
+
this.triggerDownload(content, 'text/plain', filename);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Convert a notebook to a script file.
|
|
71
|
+
*
|
|
72
|
+
* @param content The notebook content
|
|
73
|
+
* @returns The script content and file extension
|
|
74
|
+
*/
|
|
75
|
+
convertToScript(content) {
|
|
76
|
+
var _a;
|
|
77
|
+
// Get the language from the notebook metadata
|
|
78
|
+
const languageInfo = (_a = content.metadata) === null || _a === void 0 ? void 0 : _a.language_info;
|
|
79
|
+
const language = (languageInfo === null || languageInfo === void 0 ? void 0 : languageInfo.name) || 'python';
|
|
80
|
+
const fileExtension = (languageInfo === null || languageInfo === void 0 ? void 0 : languageInfo.file_extension) || '.py';
|
|
81
|
+
// Extract code cells and convert to script
|
|
82
|
+
const cells = content.cells || [];
|
|
83
|
+
const scriptLines = [];
|
|
84
|
+
for (const cell of cells) {
|
|
85
|
+
if (cell.cell_type === 'code') {
|
|
86
|
+
// Add code cell content
|
|
87
|
+
const source = Array.isArray(cell.source) ? cell.source.join('') : cell.source;
|
|
88
|
+
scriptLines.push(source);
|
|
89
|
+
// Add blank line between cells
|
|
90
|
+
scriptLines.push('');
|
|
91
|
+
}
|
|
92
|
+
else if (cell.cell_type === 'markdown' || cell.cell_type === 'raw') {
|
|
93
|
+
// Add markdown and raw cells as comments
|
|
94
|
+
const source = Array.isArray(cell.source) ? cell.source.join('') : cell.source;
|
|
95
|
+
const commentedSource = this.commentLines(source, language);
|
|
96
|
+
scriptLines.push(commentedSource);
|
|
97
|
+
// Add blank line between cells
|
|
98
|
+
scriptLines.push('');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
content: scriptLines.join('\n') + '\n',
|
|
103
|
+
extension: fileExtension,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Comment out lines based on the language.
|
|
108
|
+
*
|
|
109
|
+
* @param text The text to comment
|
|
110
|
+
* @param language The programming language
|
|
111
|
+
* @returns The commented text
|
|
112
|
+
*/
|
|
113
|
+
commentLines(text, language) {
|
|
114
|
+
const lines = text.split('\n');
|
|
115
|
+
const commentChar = this.getCommentChar(language);
|
|
116
|
+
return lines.map((line) => `${commentChar} ${line}`).join('\n');
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get the comment character for a given language.
|
|
120
|
+
*
|
|
121
|
+
* @param language The programming language
|
|
122
|
+
* @returns The comment character(s) for that language
|
|
123
|
+
*/
|
|
124
|
+
getCommentChar(language) {
|
|
125
|
+
// Map of languages to their comment characters
|
|
126
|
+
const commentMap = {
|
|
127
|
+
python: '#',
|
|
128
|
+
r: '#',
|
|
129
|
+
julia: '#',
|
|
130
|
+
ruby: '#',
|
|
131
|
+
bash: '#',
|
|
132
|
+
shell: '#',
|
|
133
|
+
perl: '#',
|
|
134
|
+
javascript: '//',
|
|
135
|
+
typescript: '//',
|
|
136
|
+
java: '//',
|
|
137
|
+
c: '//',
|
|
138
|
+
cpp: '//',
|
|
139
|
+
'c++': '//',
|
|
140
|
+
scala: '//',
|
|
141
|
+
go: '//',
|
|
142
|
+
rust: '//',
|
|
143
|
+
swift: '//',
|
|
144
|
+
kotlin: '//',
|
|
145
|
+
matlab: '%',
|
|
146
|
+
octave: '%',
|
|
147
|
+
lua: '--',
|
|
148
|
+
sql: '--',
|
|
149
|
+
haskell: '--',
|
|
150
|
+
};
|
|
151
|
+
return commentMap[language.toLowerCase()] || '#';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=exporters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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,IAAI;YACX,KAAK,EAAE,IAAI;YACX,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,GAAG;YACX,GAAG,EAAE,IAAI;YACT,GAAG,EAAE,IAAI;YACT,OAAO,EAAE,IAAI;SACd,CAAC;QAEF,OAAO,UAAU,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC;IACnD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nbconvert/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Contents, NbConvert, NbConvertManager } from '@jupyterlab/services';
|
|
2
|
+
import { IExporter, INbConvertExporters } from './tokens';
|
|
3
|
+
/**
|
|
4
|
+
* Options for creating a LiteNbConvertManager.
|
|
5
|
+
*/
|
|
6
|
+
export interface ILiteNbConvertManagerOptions extends NbConvertManager.IOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The contents manager.
|
|
9
|
+
*/
|
|
10
|
+
contentsManager: Contents.IManager;
|
|
11
|
+
/**
|
|
12
|
+
* The exporter registry.
|
|
13
|
+
*/
|
|
14
|
+
exporters: INbConvertExporters;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Custom NbConvert manager for JupyterLite with client-side export.
|
|
18
|
+
*/
|
|
19
|
+
export declare class LiteNbConvertManager extends NbConvertManager {
|
|
20
|
+
/**
|
|
21
|
+
* Construct a new LiteNbConvertManager.
|
|
22
|
+
*
|
|
23
|
+
* @param options The manager options
|
|
24
|
+
*/
|
|
25
|
+
constructor(options: ILiteNbConvertManagerOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Get the list of export formats available.
|
|
28
|
+
*/
|
|
29
|
+
getExportFormats(): Promise<NbConvert.IExportFormats>;
|
|
30
|
+
/**
|
|
31
|
+
* Export a notebook to a given format.
|
|
32
|
+
*
|
|
33
|
+
* @param options The export options
|
|
34
|
+
*/
|
|
35
|
+
exportAs(options: NbConvert.IExportOptions): Promise<void>;
|
|
36
|
+
private _contentsManager;
|
|
37
|
+
private _exporters;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Implementation of the exporter registry.
|
|
41
|
+
*/
|
|
42
|
+
export declare class Exporters implements INbConvertExporters {
|
|
43
|
+
/**
|
|
44
|
+
* Register a new exporter.
|
|
45
|
+
*
|
|
46
|
+
* @param format The export format name
|
|
47
|
+
* @param exporter The exporter instance
|
|
48
|
+
*/
|
|
49
|
+
register(format: string, exporter: IExporter): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get an exporter by format.
|
|
52
|
+
*
|
|
53
|
+
* @param format The export format name
|
|
54
|
+
* @returns The exporter or undefined if not found
|
|
55
|
+
*/
|
|
56
|
+
get(format: string): IExporter | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Get all registered export formats.
|
|
59
|
+
*
|
|
60
|
+
* @returns A map of format names to their MIME types
|
|
61
|
+
*/
|
|
62
|
+
getExportFormats(): Record<string, {
|
|
63
|
+
output_mimetype: string;
|
|
64
|
+
}>;
|
|
65
|
+
private _exporters;
|
|
66
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { NbConvertManager } from '@jupyterlab/services';
|
|
4
|
+
/**
|
|
5
|
+
* Custom NbConvert manager for JupyterLite with client-side export.
|
|
6
|
+
*/
|
|
7
|
+
export class LiteNbConvertManager extends NbConvertManager {
|
|
8
|
+
/**
|
|
9
|
+
* Construct a new LiteNbConvertManager.
|
|
10
|
+
*
|
|
11
|
+
* @param options The manager options
|
|
12
|
+
*/
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options);
|
|
15
|
+
this._contentsManager = options.contentsManager;
|
|
16
|
+
this._exporters = options.exporters;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the list of export formats available.
|
|
20
|
+
*/
|
|
21
|
+
async getExportFormats() {
|
|
22
|
+
return this._exporters.getExportFormats();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Export a notebook to a given format.
|
|
26
|
+
*
|
|
27
|
+
* @param options The export options
|
|
28
|
+
*/
|
|
29
|
+
async exportAs(options) {
|
|
30
|
+
const { format, path } = options;
|
|
31
|
+
const model = await this._contentsManager.get(path, { content: true });
|
|
32
|
+
const exporter = this._exporters.get(format);
|
|
33
|
+
if (!exporter) {
|
|
34
|
+
throw new Error(`Unknown export format: ${format}`);
|
|
35
|
+
}
|
|
36
|
+
await exporter.export(model, path);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Implementation of the exporter registry.
|
|
41
|
+
*/
|
|
42
|
+
export class Exporters {
|
|
43
|
+
constructor() {
|
|
44
|
+
this._exporters = new Map();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register a new exporter.
|
|
48
|
+
*
|
|
49
|
+
* @param format The export format name
|
|
50
|
+
* @param exporter The exporter instance
|
|
51
|
+
*/
|
|
52
|
+
register(format, exporter) {
|
|
53
|
+
this._exporters.set(format, exporter);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get an exporter by format.
|
|
57
|
+
*
|
|
58
|
+
* @param format The export format name
|
|
59
|
+
* @returns The exporter or undefined if not found
|
|
60
|
+
*/
|
|
61
|
+
get(format) {
|
|
62
|
+
return this._exporters.get(format);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get all registered export formats.
|
|
66
|
+
*
|
|
67
|
+
* @returns A map of format names to their MIME types
|
|
68
|
+
*/
|
|
69
|
+
getExportFormats() {
|
|
70
|
+
const formats = {};
|
|
71
|
+
for (const [format, exporter] of this._exporters) {
|
|
72
|
+
formats[format] = { output_mimetype: exporter.mimeType };
|
|
73
|
+
}
|
|
74
|
+
return formats;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/nbconvert/manager.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAuB,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAmB7E;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IACxD;;;;OAIG;IACH,YAAY,OAAqC;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAiC;QAC9C,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAEjC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;CAIF;AAED;;GAEG;AACH,MAAM,OAAO,SAAS;IAAtB;QAoCU,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;IACpD,CAAC;IApCC;;;;;OAKG;IACH,QAAQ,CAAC,MAAc,EAAE,QAAmB;QAC1C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,MAAc;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACH,gBAAgB;QACd,MAAM,OAAO,GAAgD,EAAE,CAAC;QAEhE,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACjD,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC3D,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CAGF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Token } from '@lumino/coreutils';
|
|
2
|
+
import { Contents } from '@jupyterlab/services';
|
|
3
|
+
/**
|
|
4
|
+
* The token for the exporter registry.
|
|
5
|
+
*/
|
|
6
|
+
export declare const INbConvertExporters: Token<INbConvertExporters>;
|
|
7
|
+
/**
|
|
8
|
+
* Interface for the exporter registry.
|
|
9
|
+
*/
|
|
10
|
+
export interface INbConvertExporters {
|
|
11
|
+
/**
|
|
12
|
+
* Register a new exporter.
|
|
13
|
+
*
|
|
14
|
+
* @param format The export format name
|
|
15
|
+
* @param exporter The exporter instance
|
|
16
|
+
*/
|
|
17
|
+
register(format: string, exporter: IExporter): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get an exporter by format.
|
|
20
|
+
*
|
|
21
|
+
* @param format The export format name
|
|
22
|
+
* @returns The exporter or undefined if not found
|
|
23
|
+
*/
|
|
24
|
+
get(format: string): IExporter | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Get all registered export formats.
|
|
27
|
+
*
|
|
28
|
+
* @returns A map of format names to their MIME types
|
|
29
|
+
*/
|
|
30
|
+
getExportFormats(): Record<string, {
|
|
31
|
+
output_mimetype: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Interface for a notebook exporter.
|
|
36
|
+
*/
|
|
37
|
+
export interface IExporter {
|
|
38
|
+
/**
|
|
39
|
+
* The MIME type of the exported format.
|
|
40
|
+
*/
|
|
41
|
+
readonly mimeType: string;
|
|
42
|
+
/**
|
|
43
|
+
* Export a notebook to this format.
|
|
44
|
+
*
|
|
45
|
+
* @param model The notebook model to export
|
|
46
|
+
* @param path The path to the notebook
|
|
47
|
+
*/
|
|
48
|
+
export(model: Contents.IModel, path: string): Promise<void>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { Token } from '@lumino/coreutils';
|
|
4
|
+
/**
|
|
5
|
+
* The token for the exporter registry.
|
|
6
|
+
*/
|
|
7
|
+
export const INbConvertExporters = new Token('@jupyterlite/services:INbConvertExporters', 'A service for managing notebook exporters in JupyterLite');
|
|
8
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/nbconvert/tokens.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI1C;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,KAAK,CAC1C,2CAA2C,EAC3C,0DAA0D,CAC3D,CAAC"}
|