@jupyterlab/markdownviewer-extension 4.7.0-alpha.1 → 4.7.0-alpha.2
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.js +45 -5
- package/lib/index.js.map +1 -1
- package/lib/searchprovider.d.ts +23 -0
- package/lib/searchprovider.js +34 -0
- package/lib/searchprovider.js.map +1 -0
- package/package.json +10 -9
- package/schema/plugin.json +6 -1
- package/src/index.ts +60 -4
- package/src/searchprovider.ts +41 -0
- package/style/index.css +1 -0
- package/style/index.js +1 -0
package/lib/index.js
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* @module markdownviewer-extension
|
|
6
6
|
*/
|
|
7
7
|
import { ILayoutRestorer } from '@jupyterlab/application';
|
|
8
|
-
import { ISanitizer, WidgetTracker } from '@jupyterlab/apputils';
|
|
8
|
+
import { Clipboard, CommandLinker, ISanitizer, WidgetTracker } from '@jupyterlab/apputils';
|
|
9
9
|
import { PathExt } from '@jupyterlab/coreutils';
|
|
10
|
+
import { ISearchProviderRegistry } from '@jupyterlab/documentsearch';
|
|
10
11
|
import { IMarkdownViewerTracker, MarkdownViewer, MarkdownViewerFactory, MarkdownViewerTableOfContentsFactory } from '@jupyterlab/markdownviewer';
|
|
11
12
|
import { IRenderMimeRegistry, markdownRendererFactory } from '@jupyterlab/rendermime';
|
|
12
13
|
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
13
14
|
import { ITableOfContentsRegistry } from '@jupyterlab/toc';
|
|
14
15
|
import { ITranslator } from '@jupyterlab/translation';
|
|
16
|
+
import { markdownViewerSearchProviderFactory } from './searchprovider';
|
|
15
17
|
/**
|
|
16
18
|
* The command IDs used by the markdownviewer plugin.
|
|
17
19
|
*/
|
|
@@ -20,6 +22,7 @@ var CommandIDs;
|
|
|
20
22
|
CommandIDs.markdownPreview = 'markdownviewer:open';
|
|
21
23
|
CommandIDs.markdownEditor = 'markdownviewer:edit';
|
|
22
24
|
CommandIDs.trust = 'markdownviewer:trust';
|
|
25
|
+
CommandIDs.copy = 'markdownviewer:copy';
|
|
23
26
|
})(CommandIDs || (CommandIDs = {}));
|
|
24
27
|
/**
|
|
25
28
|
* The name of the factory that creates markdown viewer widgets.
|
|
@@ -38,6 +41,7 @@ const plugin = {
|
|
|
38
41
|
ILayoutRestorer,
|
|
39
42
|
ISettingRegistry,
|
|
40
43
|
ITableOfContentsRegistry,
|
|
44
|
+
ISearchProviderRegistry,
|
|
41
45
|
ISanitizer
|
|
42
46
|
],
|
|
43
47
|
autoStart: true
|
|
@@ -45,7 +49,7 @@ const plugin = {
|
|
|
45
49
|
/**
|
|
46
50
|
* Activate the markdown viewer plugin.
|
|
47
51
|
*/
|
|
48
|
-
function activate(app, rendermime, translator, restorer, settingRegistry, tocRegistry, sanitizer) {
|
|
52
|
+
function activate(app, rendermime, translator, restorer, settingRegistry, tocRegistry, searchRegistry, sanitizer) {
|
|
49
53
|
const trans = translator.load('jupyterlab');
|
|
50
54
|
const { commands, docRegistry } = app;
|
|
51
55
|
// Add the markdown renderer factory.
|
|
@@ -54,6 +58,10 @@ function activate(app, rendermime, translator, restorer, settingRegistry, tocReg
|
|
|
54
58
|
const tracker = new WidgetTracker({
|
|
55
59
|
namespace
|
|
56
60
|
});
|
|
61
|
+
// Register the search provider for the rendered markdown.
|
|
62
|
+
if (searchRegistry) {
|
|
63
|
+
searchRegistry.add('jp-markdownViewerSearchProvider', markdownViewerSearchProviderFactory);
|
|
64
|
+
}
|
|
57
65
|
let config = {
|
|
58
66
|
...MarkdownViewer.defaultConfig
|
|
59
67
|
};
|
|
@@ -174,15 +182,47 @@ function activate(app, rendermime, translator, restorer, settingRegistry, tocReg
|
|
|
174
182
|
});
|
|
175
183
|
commands.addCommand(CommandIDs.trust, {
|
|
176
184
|
label: trans.__('Trust Markdown Preview'),
|
|
177
|
-
execute:
|
|
178
|
-
|
|
179
|
-
|
|
185
|
+
execute: args => {
|
|
186
|
+
var _a;
|
|
187
|
+
const trustBoundaryId = args[CommandLinker.TRUST_BOUNDARY_ID_ARG];
|
|
188
|
+
const widget = typeof trustBoundaryId === 'string'
|
|
189
|
+
? ((_a = tracker.find(widget => widget.content.node.id === trustBoundaryId)) !== null && _a !== void 0 ? _a : null)
|
|
190
|
+
: tracker.currentWidget;
|
|
191
|
+
if (widget && !widget.isDisposed) {
|
|
180
192
|
widget.content.node.classList.add('jp-mod-trusted');
|
|
181
193
|
app.commandLinker.markTrusted(widget.content.node);
|
|
182
194
|
return { trusted: true };
|
|
183
195
|
}
|
|
184
196
|
return { trusted: false };
|
|
185
197
|
},
|
|
198
|
+
describedBy: {
|
|
199
|
+
args: {
|
|
200
|
+
type: 'object',
|
|
201
|
+
properties: {
|
|
202
|
+
[CommandLinker.TRUST_BOUNDARY_ID_ARG]: {
|
|
203
|
+
type: 'string',
|
|
204
|
+
description: trans.__('The Markdown preview trust boundary ID')
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
commands.addCommand(CommandIDs.copy, {
|
|
211
|
+
label: trans.__('Copy'),
|
|
212
|
+
isEnabled: () => {
|
|
213
|
+
const selection = document.getSelection();
|
|
214
|
+
const widget = tracker.currentWidget;
|
|
215
|
+
return (widget !== null &&
|
|
216
|
+
selection !== null &&
|
|
217
|
+
selection.toString().length > 0 &&
|
|
218
|
+
widget.content.node.contains(selection.anchorNode));
|
|
219
|
+
},
|
|
220
|
+
execute: () => {
|
|
221
|
+
const selection = document.getSelection();
|
|
222
|
+
if (selection !== null && selection.toString().length > 0) {
|
|
223
|
+
Clipboard.copyToSystem(selection.toString());
|
|
224
|
+
}
|
|
225
|
+
},
|
|
186
226
|
describedBy: {
|
|
187
227
|
args: {
|
|
188
228
|
type: 'object',
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CA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M,SAAS,GAAG,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC1C,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1D,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,WAAW,EAAE;YACX,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,EAAE;aACf;SACF;KACF,CAAC,CAAC;IAEH,IAAI,WAAW,EAAE,CAAC;QAChB,WAAW,CAAC,GAAG,CACb,IAAI,oCAAoC,CACtC,OAAO,EACP,UAAU,CAAC,cAAc,EACzB,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,UAAU,CAAC,SAAS,CAClC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ISearchProviderFactory } from '@jupyterlab/documentsearch';
|
|
2
|
+
import { GenericSearchProvider } from '@jupyterlab/documentsearch';
|
|
3
|
+
import { MarkdownDocument } from '@jupyterlab/markdownviewer';
|
|
4
|
+
/**
|
|
5
|
+
* Search provider for the rendered markdown of a markdown viewer.
|
|
6
|
+
*
|
|
7
|
+
* #### Notes
|
|
8
|
+
* It is built over the inner `MarkdownViewer`, so the toolbar, the content
|
|
9
|
+
* header and the search overlay itself are left out of the search.
|
|
10
|
+
*/
|
|
11
|
+
export declare class MarkdownViewerSearchProvider extends GenericSearchProvider {
|
|
12
|
+
/**
|
|
13
|
+
* Get an initial query value if applicable so that it can be entered
|
|
14
|
+
* into the search box as an initial query
|
|
15
|
+
*
|
|
16
|
+
* @returns Initial value used to populate the search box.
|
|
17
|
+
*/
|
|
18
|
+
getInitialQuery(): string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Factory registering `MarkdownViewerSearchProvider` for markdown documents.
|
|
22
|
+
*/
|
|
23
|
+
export declare const markdownViewerSearchProviderFactory: ISearchProviderFactory<MarkdownDocument>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { GenericSearchProvider } from '@jupyterlab/documentsearch';
|
|
2
|
+
import { MarkdownDocument } from '@jupyterlab/markdownviewer';
|
|
3
|
+
/**
|
|
4
|
+
* Search provider for the rendered markdown of a markdown viewer.
|
|
5
|
+
*
|
|
6
|
+
* #### Notes
|
|
7
|
+
* It is built over the inner `MarkdownViewer`, so the toolbar, the content
|
|
8
|
+
* header and the search overlay itself are left out of the search.
|
|
9
|
+
*/
|
|
10
|
+
export class MarkdownViewerSearchProvider extends GenericSearchProvider {
|
|
11
|
+
/**
|
|
12
|
+
* Get an initial query value if applicable so that it can be entered
|
|
13
|
+
* into the search box as an initial query
|
|
14
|
+
*
|
|
15
|
+
* @returns Initial value used to populate the search box.
|
|
16
|
+
*/
|
|
17
|
+
getInitialQuery() {
|
|
18
|
+
const selection = window.getSelection();
|
|
19
|
+
// Ignore a selection made outside of the rendered markdown, for example
|
|
20
|
+
// in another document or in the file browser.
|
|
21
|
+
if (!selection || !this.widget.node.contains(selection.anchorNode)) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
return selection.toString();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Factory registering `MarkdownViewerSearchProvider` for markdown documents.
|
|
29
|
+
*/
|
|
30
|
+
export const markdownViewerSearchProviderFactory = {
|
|
31
|
+
isApplicable: (domain) => domain instanceof MarkdownDocument,
|
|
32
|
+
createNew: (widget) => new MarkdownViewerSearchProvider(widget.content)
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=searchprovider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchprovider.js","sourceRoot":"","sources":["../src/searchprovider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,OAAO,4BAA6B,SAAQ,qBAAqB;IACrE;;;;;OAKG;IACH,eAAe;QACb,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;QACxC,wEAAwE;QACxE,8CAA8C;QAC9C,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;YACnE,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAC9C;IACE,YAAY,EAAE,CAAC,MAAM,EAA8B,EAAE,CACnD,MAAM,YAAY,gBAAgB;IACpC,SAAS,EAAE,CAAC,MAAwB,EAAE,EAAE,CACtC,IAAI,4BAA4B,CAAC,MAAM,CAAC,OAAO,CAAC;CACnD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/markdownviewer-extension",
|
|
3
|
-
"version": "4.7.0-alpha.
|
|
3
|
+
"version": "4.7.0-alpha.2",
|
|
4
4
|
"description": "JupyterLab - Markdown Renderer Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -37,14 +37,15 @@
|
|
|
37
37
|
"watch": "tsc -b --watch"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jupyterlab/application": "^4.7.0-alpha.
|
|
41
|
-
"@jupyterlab/apputils": "^4.8.0-alpha.
|
|
42
|
-
"@jupyterlab/coreutils": "^6.7.0-alpha.
|
|
43
|
-
"@jupyterlab/
|
|
44
|
-
"@jupyterlab/
|
|
45
|
-
"@jupyterlab/
|
|
46
|
-
"@jupyterlab/
|
|
47
|
-
"@jupyterlab/
|
|
40
|
+
"@jupyterlab/application": "^4.7.0-alpha.2",
|
|
41
|
+
"@jupyterlab/apputils": "^4.8.0-alpha.2",
|
|
42
|
+
"@jupyterlab/coreutils": "^6.7.0-alpha.2",
|
|
43
|
+
"@jupyterlab/documentsearch": "^4.7.0-alpha.2",
|
|
44
|
+
"@jupyterlab/markdownviewer": "^4.7.0-alpha.2",
|
|
45
|
+
"@jupyterlab/rendermime": "^4.7.0-alpha.2",
|
|
46
|
+
"@jupyterlab/settingregistry": "^4.7.0-alpha.2",
|
|
47
|
+
"@jupyterlab/toc": "^6.7.0-alpha.2",
|
|
48
|
+
"@jupyterlab/translation": "^4.7.0-alpha.2"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"rimraf": "~5.0.5",
|
package/schema/plugin.json
CHANGED
|
@@ -5,9 +5,14 @@
|
|
|
5
5
|
"description": "Markdown viewer settings.",
|
|
6
6
|
"jupyter.lab.menus": {
|
|
7
7
|
"context": [
|
|
8
|
+
{
|
|
9
|
+
"command": "markdownviewer:copy",
|
|
10
|
+
"selector": ".jp-MarkdownViewer",
|
|
11
|
+
"rank": 0
|
|
12
|
+
},
|
|
8
13
|
{
|
|
9
14
|
"command": "markdownviewer:edit",
|
|
10
|
-
"selector": ".jp-
|
|
15
|
+
"selector": ".jp-MarkdownViewer"
|
|
11
16
|
}
|
|
12
17
|
]
|
|
13
18
|
},
|
package/src/index.ts
CHANGED
|
@@ -10,8 +10,14 @@ import type {
|
|
|
10
10
|
JupyterFrontEndPlugin
|
|
11
11
|
} from '@jupyterlab/application';
|
|
12
12
|
import { ILayoutRestorer } from '@jupyterlab/application';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Clipboard,
|
|
15
|
+
CommandLinker,
|
|
16
|
+
ISanitizer,
|
|
17
|
+
WidgetTracker
|
|
18
|
+
} from '@jupyterlab/apputils';
|
|
14
19
|
import { PathExt } from '@jupyterlab/coreutils';
|
|
20
|
+
import { ISearchProviderRegistry } from '@jupyterlab/documentsearch';
|
|
15
21
|
import type { MarkdownDocument } from '@jupyterlab/markdownviewer';
|
|
16
22
|
import {
|
|
17
23
|
IMarkdownViewerTracker,
|
|
@@ -28,6 +34,8 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
|
28
34
|
import { ITableOfContentsRegistry } from '@jupyterlab/toc';
|
|
29
35
|
import { ITranslator } from '@jupyterlab/translation';
|
|
30
36
|
|
|
37
|
+
import { markdownViewerSearchProviderFactory } from './searchprovider';
|
|
38
|
+
|
|
31
39
|
/**
|
|
32
40
|
* The command IDs used by the markdownviewer plugin.
|
|
33
41
|
*/
|
|
@@ -35,6 +43,7 @@ namespace CommandIDs {
|
|
|
35
43
|
export const markdownPreview = 'markdownviewer:open';
|
|
36
44
|
export const markdownEditor = 'markdownviewer:edit';
|
|
37
45
|
export const trust = 'markdownviewer:trust';
|
|
46
|
+
export const copy = 'markdownviewer:copy';
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
/**
|
|
@@ -55,6 +64,7 @@ const plugin: JupyterFrontEndPlugin<IMarkdownViewerTracker> = {
|
|
|
55
64
|
ILayoutRestorer,
|
|
56
65
|
ISettingRegistry,
|
|
57
66
|
ITableOfContentsRegistry,
|
|
67
|
+
ISearchProviderRegistry,
|
|
58
68
|
ISanitizer
|
|
59
69
|
],
|
|
60
70
|
autoStart: true
|
|
@@ -70,6 +80,7 @@ function activate(
|
|
|
70
80
|
restorer: ILayoutRestorer | null,
|
|
71
81
|
settingRegistry: ISettingRegistry | null,
|
|
72
82
|
tocRegistry: ITableOfContentsRegistry | null,
|
|
83
|
+
searchRegistry: ISearchProviderRegistry | null,
|
|
73
84
|
sanitizer: IRenderMime.ISanitizer | null
|
|
74
85
|
): IMarkdownViewerTracker {
|
|
75
86
|
const trans = translator.load('jupyterlab');
|
|
@@ -83,6 +94,14 @@ function activate(
|
|
|
83
94
|
namespace
|
|
84
95
|
});
|
|
85
96
|
|
|
97
|
+
// Register the search provider for the rendered markdown.
|
|
98
|
+
if (searchRegistry) {
|
|
99
|
+
searchRegistry.add(
|
|
100
|
+
'jp-markdownViewerSearchProvider',
|
|
101
|
+
markdownViewerSearchProviderFactory
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
86
105
|
let config: Partial<MarkdownViewer.IConfig> = {
|
|
87
106
|
...MarkdownViewer.defaultConfig
|
|
88
107
|
};
|
|
@@ -212,15 +231,52 @@ function activate(
|
|
|
212
231
|
|
|
213
232
|
commands.addCommand(CommandIDs.trust, {
|
|
214
233
|
label: trans.__('Trust Markdown Preview'),
|
|
215
|
-
execute:
|
|
216
|
-
const
|
|
217
|
-
|
|
234
|
+
execute: args => {
|
|
235
|
+
const trustBoundaryId = args[CommandLinker.TRUST_BOUNDARY_ID_ARG];
|
|
236
|
+
const widget =
|
|
237
|
+
typeof trustBoundaryId === 'string'
|
|
238
|
+
? (tracker.find(
|
|
239
|
+
widget => widget.content.node.id === trustBoundaryId
|
|
240
|
+
) ?? null)
|
|
241
|
+
: tracker.currentWidget;
|
|
242
|
+
if (widget && !widget.isDisposed) {
|
|
218
243
|
widget.content.node.classList.add('jp-mod-trusted');
|
|
219
244
|
app.commandLinker.markTrusted(widget.content.node);
|
|
220
245
|
return { trusted: true };
|
|
221
246
|
}
|
|
222
247
|
return { trusted: false };
|
|
223
248
|
},
|
|
249
|
+
describedBy: {
|
|
250
|
+
args: {
|
|
251
|
+
type: 'object',
|
|
252
|
+
properties: {
|
|
253
|
+
[CommandLinker.TRUST_BOUNDARY_ID_ARG]: {
|
|
254
|
+
type: 'string',
|
|
255
|
+
description: trans.__('The Markdown preview trust boundary ID')
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
commands.addCommand(CommandIDs.copy, {
|
|
263
|
+
label: trans.__('Copy'),
|
|
264
|
+
isEnabled: () => {
|
|
265
|
+
const selection = document.getSelection();
|
|
266
|
+
const widget = tracker.currentWidget;
|
|
267
|
+
return (
|
|
268
|
+
widget !== null &&
|
|
269
|
+
selection !== null &&
|
|
270
|
+
selection.toString().length > 0 &&
|
|
271
|
+
widget.content.node.contains(selection.anchorNode)
|
|
272
|
+
);
|
|
273
|
+
},
|
|
274
|
+
execute: () => {
|
|
275
|
+
const selection = document.getSelection();
|
|
276
|
+
if (selection !== null && selection.toString().length > 0) {
|
|
277
|
+
Clipboard.copyToSystem(selection.toString());
|
|
278
|
+
}
|
|
279
|
+
},
|
|
224
280
|
describedBy: {
|
|
225
281
|
args: {
|
|
226
282
|
type: 'object',
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import type { ISearchProviderFactory } from '@jupyterlab/documentsearch';
|
|
4
|
+
import { GenericSearchProvider } from '@jupyterlab/documentsearch';
|
|
5
|
+
import { MarkdownDocument } from '@jupyterlab/markdownviewer';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Search provider for the rendered markdown of a markdown viewer.
|
|
9
|
+
*
|
|
10
|
+
* #### Notes
|
|
11
|
+
* It is built over the inner `MarkdownViewer`, so the toolbar, the content
|
|
12
|
+
* header and the search overlay itself are left out of the search.
|
|
13
|
+
*/
|
|
14
|
+
export class MarkdownViewerSearchProvider extends GenericSearchProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Get an initial query value if applicable so that it can be entered
|
|
17
|
+
* into the search box as an initial query
|
|
18
|
+
*
|
|
19
|
+
* @returns Initial value used to populate the search box.
|
|
20
|
+
*/
|
|
21
|
+
getInitialQuery(): string {
|
|
22
|
+
const selection = window.getSelection();
|
|
23
|
+
// Ignore a selection made outside of the rendered markdown, for example
|
|
24
|
+
// in another document or in the file browser.
|
|
25
|
+
if (!selection || !this.widget.node.contains(selection.anchorNode)) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
return selection.toString();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Factory registering `MarkdownViewerSearchProvider` for markdown documents.
|
|
34
|
+
*/
|
|
35
|
+
export const markdownViewerSearchProviderFactory: ISearchProviderFactory<MarkdownDocument> =
|
|
36
|
+
{
|
|
37
|
+
isApplicable: (domain): domain is MarkdownDocument =>
|
|
38
|
+
domain instanceof MarkdownDocument,
|
|
39
|
+
createNew: (widget: MarkdownDocument) =>
|
|
40
|
+
new MarkdownViewerSearchProvider(widget.content)
|
|
41
|
+
};
|
package/style/index.css
CHANGED
|
@@ -7,5 +7,6 @@
|
|
|
7
7
|
@import url('~@jupyterlab/apputils/style/index.css');
|
|
8
8
|
@import url('~@jupyterlab/rendermime/style/index.css');
|
|
9
9
|
@import url('~@jupyterlab/application/style/index.css');
|
|
10
|
+
@import url('~@jupyterlab/documentsearch/style/index.css');
|
|
10
11
|
@import url('~@jupyterlab/toc/style/index.css');
|
|
11
12
|
@import url('~@jupyterlab/markdownviewer/style/index.css');
|
package/style/index.js
CHANGED
|
@@ -7,5 +7,6 @@
|
|
|
7
7
|
import '@jupyterlab/apputils/style/index.js';
|
|
8
8
|
import '@jupyterlab/rendermime/style/index.js';
|
|
9
9
|
import '@jupyterlab/application/style/index.js';
|
|
10
|
+
import '@jupyterlab/documentsearch/style/index.js';
|
|
10
11
|
import '@jupyterlab/toc/style/index.js';
|
|
11
12
|
import '@jupyterlab/markdownviewer/style/index.js';
|