@jupyterlab/toc 6.0.10 → 6.0.12
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/utils/markdown.d.ts +3 -1
- package/lib/utils/markdown.js +17 -9
- package/lib/utils/markdown.js.map +1 -1
- package/package.json +10 -9
- package/src/utils/markdown.ts +20 -10
package/lib/utils/markdown.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IMarkdownParser } from '@jupyterlab/rendermime';
|
|
2
|
+
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
|
|
2
3
|
import { TableOfContents } from '../tokens';
|
|
3
4
|
/**
|
|
4
5
|
* Markdown heading
|
|
@@ -18,8 +19,9 @@ export interface IMarkdownHeading extends TableOfContents.IHeading {
|
|
|
18
19
|
*
|
|
19
20
|
* @param raw Raw markdown heading
|
|
20
21
|
* @param level Heading level
|
|
22
|
+
* @param sanitizer HTML sanitizer
|
|
21
23
|
*/
|
|
22
|
-
export declare function getHeadingId(
|
|
24
|
+
export declare function getHeadingId(markdownParser: IMarkdownParser, raw: string, level: number, sanitizer?: IRenderMime.ISanitizer): Promise<string | null>;
|
|
23
25
|
/**
|
|
24
26
|
* Parses the provided string and returns a list of headings.
|
|
25
27
|
*
|
package/lib/utils/markdown.js
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { Sanitizer } from '@jupyterlab/apputils';
|
|
3
4
|
import { renderMarkdown } from '@jupyterlab/rendermime';
|
|
4
5
|
/**
|
|
5
6
|
* Build the heading html id.
|
|
6
7
|
*
|
|
7
8
|
* @param raw Raw markdown heading
|
|
8
9
|
* @param level Heading level
|
|
10
|
+
* @param sanitizer HTML sanitizer
|
|
9
11
|
*/
|
|
10
|
-
export async function getHeadingId(
|
|
12
|
+
export async function getHeadingId(markdownParser, raw, level, sanitizer) {
|
|
11
13
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const host = document.createElement('div');
|
|
15
|
+
await renderMarkdown({
|
|
16
|
+
markdownParser,
|
|
17
|
+
host,
|
|
18
|
+
source: raw,
|
|
19
|
+
trusted: false,
|
|
20
|
+
sanitizer: sanitizer !== null && sanitizer !== void 0 ? sanitizer : new Sanitizer(),
|
|
21
|
+
shouldTypeset: false,
|
|
22
|
+
resolver: null,
|
|
23
|
+
linkHandler: null,
|
|
24
|
+
latexTypesetter: null
|
|
25
|
+
});
|
|
26
|
+
const header = host.querySelector(`h${level}`);
|
|
19
27
|
if (!header) {
|
|
20
28
|
return null;
|
|
21
29
|
}
|
|
22
|
-
return
|
|
30
|
+
return header.id;
|
|
23
31
|
}
|
|
24
32
|
catch (reason) {
|
|
25
33
|
console.error('Failed to parse a heading.', reason);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/utils/markdown.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAmB,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/utils/markdown.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAmB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAmBzE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,cAA+B,EAC/B,GAAW,EACX,KAAa,EACb,SAAkC;IAElC,IAAI;QACF,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAE3C,MAAM,cAAc,CAAC;YACnB,cAAc;YACd,IAAI;YACJ,MAAM,EAA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IAAI,QAAQ,EAAE;QACZ,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACvD,IAAI,KAAK,EAAE;YACT,OAAO;gBACL,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC;gBACtB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,GAAG,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;gBAChC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;aAC7B,CAAC;SACH;KACF;IACD,0GAA0G;IAC1G,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC/C,IAAI,KAAK,EAAE;QACT,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;YACd,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;YAC7B,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAChC,GAAG,EAAE,IAAI;SACV,CAAC;KACH;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,UAAU,CAAC,OAAe;IACjC,0DAA0D;IAC1D,OAAO,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,WAAW,GACf,wEAAwE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/toc",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.12",
|
|
4
4
|
"description": "JupyterLab - Table of Contents widget",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyterlab"
|
|
@@ -41,13 +41,14 @@
|
|
|
41
41
|
"watch": "tsc -b --watch"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@jupyterlab/apputils": "^4.1.
|
|
45
|
-
"@jupyterlab/coreutils": "^6.0.
|
|
46
|
-
"@jupyterlab/docregistry": "^4.0.
|
|
47
|
-
"@jupyterlab/observables": "^5.0.
|
|
48
|
-
"@jupyterlab/rendermime": "^4.0.
|
|
49
|
-
"@jupyterlab/
|
|
50
|
-
"@jupyterlab/
|
|
44
|
+
"@jupyterlab/apputils": "^4.1.12",
|
|
45
|
+
"@jupyterlab/coreutils": "^6.0.12",
|
|
46
|
+
"@jupyterlab/docregistry": "^4.0.12",
|
|
47
|
+
"@jupyterlab/observables": "^5.0.12",
|
|
48
|
+
"@jupyterlab/rendermime": "^4.0.12",
|
|
49
|
+
"@jupyterlab/rendermime-interfaces": "^3.8.12",
|
|
50
|
+
"@jupyterlab/translation": "^4.0.12",
|
|
51
|
+
"@jupyterlab/ui-components": "^4.0.12",
|
|
51
52
|
"@lumino/coreutils": "^2.1.2",
|
|
52
53
|
"@lumino/disposable": "^2.1.2",
|
|
53
54
|
"@lumino/messaging": "^2.0.1",
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
"react": "^18.2.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
|
-
"@jupyterlab/testing": "^4.0.
|
|
60
|
+
"@jupyterlab/testing": "^4.0.12",
|
|
60
61
|
"@types/jest": "^29.2.0",
|
|
61
62
|
"@types/react": "^18.0.26",
|
|
62
63
|
"jest": "^29.2.0",
|
package/src/utils/markdown.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
|
|
4
|
+
import { Sanitizer } from '@jupyterlab/apputils';
|
|
4
5
|
import { IMarkdownParser, renderMarkdown } from '@jupyterlab/rendermime';
|
|
6
|
+
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
|
|
5
7
|
import { TableOfContents } from '../tokens';
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -24,27 +26,35 @@ export interface IMarkdownHeading extends TableOfContents.IHeading {
|
|
|
24
26
|
*
|
|
25
27
|
* @param raw Raw markdown heading
|
|
26
28
|
* @param level Heading level
|
|
29
|
+
* @param sanitizer HTML sanitizer
|
|
27
30
|
*/
|
|
28
31
|
export async function getHeadingId(
|
|
29
|
-
|
|
32
|
+
markdownParser: IMarkdownParser,
|
|
30
33
|
raw: string,
|
|
31
|
-
level: number
|
|
34
|
+
level: number,
|
|
35
|
+
sanitizer?: IRenderMime.ISanitizer
|
|
32
36
|
): Promise<string | null> {
|
|
33
37
|
try {
|
|
34
|
-
const
|
|
38
|
+
const host = document.createElement('div');
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
await renderMarkdown({
|
|
41
|
+
markdownParser,
|
|
42
|
+
host,
|
|
43
|
+
source: raw,
|
|
44
|
+
trusted: false,
|
|
45
|
+
sanitizer: sanitizer ?? new Sanitizer(),
|
|
46
|
+
shouldTypeset: false,
|
|
47
|
+
resolver: null,
|
|
48
|
+
linkHandler: null,
|
|
49
|
+
latexTypesetter: null
|
|
50
|
+
});
|
|
39
51
|
|
|
40
|
-
const
|
|
41
|
-
container.innerHTML = innerHTML;
|
|
42
|
-
const header = container.querySelector(`h${level}`);
|
|
52
|
+
const header = host.querySelector(`h${level}`);
|
|
43
53
|
if (!header) {
|
|
44
54
|
return null;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
return
|
|
57
|
+
return header.id;
|
|
48
58
|
} catch (reason) {
|
|
49
59
|
console.error('Failed to parse a heading.', reason);
|
|
50
60
|
}
|