@jupyterlab/markedparser-extension 4.0.0-alpha.5
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/index.d.ts +14 -0
- package/lib/index.js +92 -0
- package/lib/index.js.map +1 -0
- package/package.json +54 -0
- package/style/index.css +9 -0
- package/style/index.js +9 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module markedparser-extension
|
|
4
|
+
*/
|
|
5
|
+
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
|
|
6
|
+
import { IMarkdownParser } from '@jupyterlab/rendermime';
|
|
7
|
+
/**
|
|
8
|
+
* The markdown parser plugin.
|
|
9
|
+
*/
|
|
10
|
+
declare const plugin: JupyterFrontEndPlugin<IMarkdownParser>;
|
|
11
|
+
/**
|
|
12
|
+
* Export the plugin as default.
|
|
13
|
+
*/
|
|
14
|
+
export default plugin;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/* -----------------------------------------------------------------------------
|
|
2
|
+
| Copyright (c) Jupyter Development Team.
|
|
3
|
+
| Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|----------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module markedparser-extension
|
|
8
|
+
*/
|
|
9
|
+
import { CodeMirrorEditor, Mode } from '@jupyterlab/codemirror';
|
|
10
|
+
import { IMarkdownParser } from '@jupyterlab/rendermime';
|
|
11
|
+
import { marked } from 'marked';
|
|
12
|
+
/**
|
|
13
|
+
* The markdown parser plugin.
|
|
14
|
+
*/
|
|
15
|
+
const plugin = {
|
|
16
|
+
id: '@jupyterlab/markedparser-extension:plugin',
|
|
17
|
+
autoStart: true,
|
|
18
|
+
provides: IMarkdownParser,
|
|
19
|
+
activate: () => {
|
|
20
|
+
Private.initializeMarked();
|
|
21
|
+
return {
|
|
22
|
+
render: (content) => new Promise((resolve, reject) => {
|
|
23
|
+
marked(content, (err, content) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
reject(err);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
resolve(content);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Export the plugin as default.
|
|
37
|
+
*/
|
|
38
|
+
export default plugin;
|
|
39
|
+
var Private;
|
|
40
|
+
(function (Private) {
|
|
41
|
+
let markedInitialized = false;
|
|
42
|
+
function initializeMarked() {
|
|
43
|
+
if (markedInitialized) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
markedInitialized = true;
|
|
48
|
+
}
|
|
49
|
+
marked.setOptions({
|
|
50
|
+
gfm: true,
|
|
51
|
+
sanitize: false,
|
|
52
|
+
// breaks: true; We can't use GFM breaks as it causes problems with tables
|
|
53
|
+
langPrefix: `cm-s-${CodeMirrorEditor.defaultConfig.theme} language-`,
|
|
54
|
+
highlight: (code, lang, callback) => {
|
|
55
|
+
const cb = (err, code) => {
|
|
56
|
+
if (callback) {
|
|
57
|
+
callback(err, code);
|
|
58
|
+
}
|
|
59
|
+
return code;
|
|
60
|
+
};
|
|
61
|
+
if (!lang) {
|
|
62
|
+
// no language, no highlight
|
|
63
|
+
return cb(null, code);
|
|
64
|
+
}
|
|
65
|
+
Mode.ensure(lang)
|
|
66
|
+
.then(spec => {
|
|
67
|
+
const el = document.createElement('div');
|
|
68
|
+
if (!spec) {
|
|
69
|
+
console.error(`No CodeMirror mode: ${lang}`);
|
|
70
|
+
return cb(null, code);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
Mode.run(code, spec.mime, el);
|
|
74
|
+
return cb(null, el.innerHTML);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error(`Failed to highlight ${lang} code`, err);
|
|
78
|
+
return cb(err, code);
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
.catch(err => {
|
|
82
|
+
console.error(`No CodeMirror mode: ${lang}`);
|
|
83
|
+
console.error(`Require CodeMirror mode error: ${err}`);
|
|
84
|
+
return cb(null, code);
|
|
85
|
+
});
|
|
86
|
+
return code;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
Private.initializeMarked = initializeMarked;
|
|
91
|
+
})(Private || (Private = {}));
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;+EAG+E;AAC/E;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,GAA2C;IACrD,EAAE,EAAE,2CAA2C;IAC/C,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,eAAe;IACzB,QAAQ,EAAE,GAAG,EAAE;QACb,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC3B,OAAO;YACL,MAAM,EAAE,CAAC,OAAe,EAAmB,EAAE,CAC3C,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACtC,MAAM,CAAC,OAAO,EAAE,CAAC,GAAQ,EAAE,OAAe,EAAE,EAAE;oBAC5C,IAAI,GAAG,EAAE;wBACP,MAAM,CAAC,GAAG,CAAC,CAAC;qBACb;yBAAM;wBACL,OAAO,CAAC,OAAO,CAAC,CAAC;qBAClB;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC;SACL,CAAC;IACJ,CAAC;CACF,CAAC;AA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C,OAAO,GAAG,EAAE;wBACZ,OAAO,CAAC,KAAK,CAAC,uBAAuB,IAAI,OAAO,EAAE,GAAG,CAAC,CAAC;wBACvD,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;qBACtB;gBACH,CAAC,CAAC;qBACD,KAAK,CAAC,GAAG,CAAC,EAAE;oBACX,OAAO,CAAC,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;oBAC7C,OAAO,CAAC,KAAK,CAAC,kCAAkC,GAAG,EAAE,CAAC,CAAC;oBACvD,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACxB,CAAC,CAAC,CAAC;gBACL,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IA9Ce,wBAAgB,mBA8C/B,CAAA;AACH,CAAC,EAjDS,OAAO,KAAP,OAAO,QAiDhB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jupyterlab/markedparser-extension",
|
|
3
|
+
"version": "4.0.0-alpha.5",
|
|
4
|
+
"description": "JupyterLab - Markdown parser provider",
|
|
5
|
+
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/jupyterlab/jupyterlab/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/jupyterlab/jupyterlab.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "BSD-3-Clause",
|
|
14
|
+
"author": "Project Jupyter",
|
|
15
|
+
"sideEffects": [
|
|
16
|
+
"style/**/*.css",
|
|
17
|
+
"style/index.js"
|
|
18
|
+
],
|
|
19
|
+
"main": "lib/index.js",
|
|
20
|
+
"types": "lib/index.d.ts",
|
|
21
|
+
"style": "style/index.css",
|
|
22
|
+
"directories": {
|
|
23
|
+
"lib": "lib/"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
|
|
27
|
+
"style/index.css",
|
|
28
|
+
"style/index.js"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -b",
|
|
32
|
+
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
|
|
33
|
+
"docs": "typedoc src",
|
|
34
|
+
"watch": "tsc -b --watch"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@jupyterlab/application": "^4.0.0-alpha.6",
|
|
38
|
+
"@jupyterlab/codemirror": "^4.0.0-alpha.6",
|
|
39
|
+
"@jupyterlab/rendermime": "^4.0.0-alpha.6",
|
|
40
|
+
"marked": "^4.0.10"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/marked": "^4.0.1",
|
|
44
|
+
"rimraf": "~3.0.0",
|
|
45
|
+
"typescript": "~4.5.2"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"jupyterlab": {
|
|
51
|
+
"extension": true
|
|
52
|
+
},
|
|
53
|
+
"styleModule": "style/index.js"
|
|
54
|
+
}
|
package/style/index.css
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*-----------------------------------------------------------------------------
|
|
2
|
+
| Copyright (c) Jupyter Development Team.
|
|
3
|
+
| Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|----------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
/* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
|
|
7
|
+
@import url('~@jupyterlab/codemirror/style/index.css');
|
|
8
|
+
@import url('~@jupyterlab/rendermime/style/index.css');
|
|
9
|
+
@import url('~@jupyterlab/application/style/index.css');
|
package/style/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*-----------------------------------------------------------------------------
|
|
2
|
+
| Copyright (c) Jupyter Development Team.
|
|
3
|
+
| Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|----------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
/* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
|
|
7
|
+
import '@jupyterlab/codemirror/style/index.js';
|
|
8
|
+
import '@jupyterlab/rendermime/style/index.js';
|
|
9
|
+
import '@jupyterlab/application/style/index.js';
|