@jupyterlab/toc 6.2.1 → 6.2.3
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.js +26 -2
- package/lib/utils/markdown.js.map +1 -1
- package/package.json +10 -10
- package/src/utils/markdown.ts +23 -2
package/lib/utils/markdown.js
CHANGED
|
@@ -46,6 +46,8 @@ export function getHeadings(text) {
|
|
|
46
46
|
// Iterate over the lines to get the header level and text for each line:
|
|
47
47
|
const headings = new Array();
|
|
48
48
|
let isCodeBlock;
|
|
49
|
+
let openingFence = 0;
|
|
50
|
+
let fenceType;
|
|
49
51
|
let lineIdx = 0;
|
|
50
52
|
// Don't check for Markdown headings if in a YAML frontmatter block.
|
|
51
53
|
// We can only start a frontmatter block on the first line of the file.
|
|
@@ -67,8 +69,21 @@ export function getHeadings(text) {
|
|
|
67
69
|
continue;
|
|
68
70
|
}
|
|
69
71
|
// Don't check for Markdown headings if in a code block
|
|
70
|
-
if (line.startsWith('```')) {
|
|
71
|
-
|
|
72
|
+
if (line.startsWith('```') || line.startsWith('~~~')) {
|
|
73
|
+
const closingFence = extractLeadingFences(line);
|
|
74
|
+
if (closingFence === 0)
|
|
75
|
+
continue;
|
|
76
|
+
if (openingFence === 0) {
|
|
77
|
+
fenceType = line.charAt(0);
|
|
78
|
+
isCodeBlock = !isCodeBlock;
|
|
79
|
+
openingFence = closingFence;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
else if (fenceType === line.charAt(0) && closingFence >= openingFence) {
|
|
83
|
+
isCodeBlock = !isCodeBlock;
|
|
84
|
+
openingFence = 0;
|
|
85
|
+
fenceType = '';
|
|
86
|
+
}
|
|
72
87
|
}
|
|
73
88
|
if (isCodeBlock) {
|
|
74
89
|
continue;
|
|
@@ -83,6 +98,15 @@ export function getHeadings(text) {
|
|
|
83
98
|
}
|
|
84
99
|
return headings;
|
|
85
100
|
}
|
|
101
|
+
// Returns the length of ``` or ~~~ fences.
|
|
102
|
+
function extractLeadingFences(line) {
|
|
103
|
+
let match;
|
|
104
|
+
if (line.startsWith('`'))
|
|
105
|
+
match = line.match(/^(`{3,})/);
|
|
106
|
+
else
|
|
107
|
+
match = line.match(/^(~{3,})/);
|
|
108
|
+
return match ? match[0].length : 0;
|
|
109
|
+
}
|
|
86
110
|
const MARKDOWN_MIME_TYPE = [
|
|
87
111
|
'text/x-ipythongfm',
|
|
88
112
|
'text/x-markdown',
|
|
@@ -1 +1 @@
|
|
|
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,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,SAAS,EAAE,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,SAAS,EAAE;YACvC,aAAa,EAAE,KAAK;YACpB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,IAAI;YACjB,eAAe,EAAE,IAAI;SACtB,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,IAAI,CAAC;SACb;QAED,OAAO,MAAM,CAAC,EAAE,CAAC;KAClB;IAAC,OAAO,MAAM,EAAE;QACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,MAAM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,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.2.
|
|
3
|
+
"version": "6.2.3",
|
|
4
4
|
"description": "JupyterLab - Table of Contents widget",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyterlab"
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"watch": "tsc -b --watch"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@jupyterlab/apputils": "^4.3.
|
|
44
|
-
"@jupyterlab/coreutils": "^6.2.
|
|
45
|
-
"@jupyterlab/docregistry": "^4.2.
|
|
46
|
-
"@jupyterlab/observables": "^5.2.
|
|
47
|
-
"@jupyterlab/rendermime": "^4.2.
|
|
48
|
-
"@jupyterlab/rendermime-interfaces": "^3.10.
|
|
49
|
-
"@jupyterlab/translation": "^4.2.
|
|
50
|
-
"@jupyterlab/ui-components": "^4.2.
|
|
43
|
+
"@jupyterlab/apputils": "^4.3.3",
|
|
44
|
+
"@jupyterlab/coreutils": "^6.2.3",
|
|
45
|
+
"@jupyterlab/docregistry": "^4.2.3",
|
|
46
|
+
"@jupyterlab/observables": "^5.2.3",
|
|
47
|
+
"@jupyterlab/rendermime": "^4.2.3",
|
|
48
|
+
"@jupyterlab/rendermime-interfaces": "^3.10.3",
|
|
49
|
+
"@jupyterlab/translation": "^4.2.3",
|
|
50
|
+
"@jupyterlab/ui-components": "^4.2.3",
|
|
51
51
|
"@lumino/coreutils": "^2.1.2",
|
|
52
52
|
"@lumino/disposable": "^2.1.2",
|
|
53
53
|
"@lumino/messaging": "^2.0.1",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"react": "^18.2.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@jupyterlab/testing": "^4.2.
|
|
59
|
+
"@jupyterlab/testing": "^4.2.3",
|
|
60
60
|
"@types/jest": "^29.2.0",
|
|
61
61
|
"@types/react": "^18.0.26",
|
|
62
62
|
"jest": "^29.2.0",
|
package/src/utils/markdown.ts
CHANGED
|
@@ -75,6 +75,8 @@ export function getHeadings(text: string): IMarkdownHeading[] {
|
|
|
75
75
|
// Iterate over the lines to get the header level and text for each line:
|
|
76
76
|
const headings = new Array<IMarkdownHeading>();
|
|
77
77
|
let isCodeBlock;
|
|
78
|
+
let openingFence = 0;
|
|
79
|
+
let fenceType;
|
|
78
80
|
let lineIdx = 0;
|
|
79
81
|
|
|
80
82
|
// Don't check for Markdown headings if in a YAML frontmatter block.
|
|
@@ -104,8 +106,19 @@ export function getHeadings(text: string): IMarkdownHeading[] {
|
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
// Don't check for Markdown headings if in a code block
|
|
107
|
-
if (line.startsWith('```')) {
|
|
108
|
-
|
|
109
|
+
if (line.startsWith('```') || line.startsWith('~~~')) {
|
|
110
|
+
const closingFence = extractLeadingFences(line);
|
|
111
|
+
if (closingFence === 0) continue;
|
|
112
|
+
if (openingFence === 0) {
|
|
113
|
+
fenceType = line.charAt(0);
|
|
114
|
+
isCodeBlock = !isCodeBlock;
|
|
115
|
+
openingFence = closingFence;
|
|
116
|
+
continue;
|
|
117
|
+
} else if (fenceType === line.charAt(0) && closingFence >= openingFence) {
|
|
118
|
+
isCodeBlock = !isCodeBlock;
|
|
119
|
+
openingFence = 0;
|
|
120
|
+
fenceType = '';
|
|
121
|
+
}
|
|
109
122
|
}
|
|
110
123
|
if (isCodeBlock) {
|
|
111
124
|
continue;
|
|
@@ -123,6 +136,14 @@ export function getHeadings(text: string): IMarkdownHeading[] {
|
|
|
123
136
|
return headings;
|
|
124
137
|
}
|
|
125
138
|
|
|
139
|
+
// Returns the length of ``` or ~~~ fences.
|
|
140
|
+
function extractLeadingFences(line: string) {
|
|
141
|
+
let match;
|
|
142
|
+
if (line.startsWith('`')) match = line.match(/^(`{3,})/);
|
|
143
|
+
else match = line.match(/^(~{3,})/);
|
|
144
|
+
return match ? match[0].length : 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
126
147
|
const MARKDOWN_MIME_TYPE = [
|
|
127
148
|
'text/x-ipythongfm',
|
|
128
149
|
'text/x-markdown',
|