@@ -12,6 +12,7 @@ import {
1212import {
1313 DOMUtils ,
1414 ICommandPalette ,
15+ ISanitizer ,
1516 IToolbarWidgetRegistry ,
1617} from '@jupyterlab/apputils' ;
1718
@@ -25,9 +26,18 @@ import { DocumentWidget } from '@jupyterlab/docregistry';
2526
2627import { IMainMenu } from '@jupyterlab/mainmenu' ;
2728
29+ import {
30+ ILatexTypesetter ,
31+ IMarkdownParser ,
32+ IRenderMime ,
33+ IRenderMimeRegistry ,
34+ RenderMimeRegistry ,
35+ standardRendererFactories ,
36+ } from '@jupyterlab/rendermime' ;
37+
2838import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
2939
30- import { ITranslator } from '@jupyterlab/translation' ;
40+ import { ITranslator , nullTranslator } from '@jupyterlab/translation' ;
3141
3242import {
3343 NotebookApp ,
@@ -64,6 +74,11 @@ const STRIP_IPYNB = /\.ipynb$/;
6474 * The command IDs used by the application plugin.
6575 */
6676namespace CommandIDs {
77+ /**
78+ * Handle local links
79+ */
80+ export const handleLink = 'application:handle-local-link' ;
81+
6782 /**
6883 * Toggle Top Bar visibility
6984 */
@@ -295,6 +310,74 @@ const paths: JupyterFrontEndPlugin<JupyterFrontEnd.IPaths> = {
295310 } ,
296311} ;
297312
313+ /**
314+ * A plugin providing a rendermime registry.
315+ */
316+ const rendermime : JupyterFrontEndPlugin < IRenderMimeRegistry > = {
317+ id : '@jupyter-notebook/application-extension:rendermime' ,
318+ autoStart : true ,
319+ provides : IRenderMimeRegistry ,
320+ description : 'Provides the render mime registry.' ,
321+ optional : [
322+ IDocumentManager ,
323+ ILatexTypesetter ,
324+ ISanitizer ,
325+ IMarkdownParser ,
326+ ITranslator ,
327+ ] ,
328+ activate : (
329+ app : JupyterFrontEnd ,
330+ docManager : IDocumentManager | null ,
331+ latexTypesetter : ILatexTypesetter | null ,
332+ sanitizer : IRenderMime . ISanitizer | null ,
333+ markdownParser : IMarkdownParser | null ,
334+ translator : ITranslator | null
335+ ) => {
336+ const trans = ( translator ?? nullTranslator ) . load ( 'jupyterlab' ) ;
337+ if ( docManager ) {
338+ app . commands . addCommand ( CommandIDs . handleLink , {
339+ label : trans . __ ( 'Handle Local Link' ) ,
340+ execute : ( args ) => {
341+ const path = args [ 'path' ] as string | undefined | null ;
342+ if ( path === undefined || path === null ) {
343+ return ;
344+ }
345+ return docManager . services . contents
346+ . get ( path , { content : false } )
347+ . then ( ( model ) => {
348+ // Open in a new browser tab
349+ const url = PageConfig . getBaseUrl ( ) ;
350+ const treeUrl = URLExt . join ( url , 'tree' , model . path ) ;
351+ window . open ( treeUrl , '_blank' ) ;
352+ } ) ;
353+ } ,
354+ } ) ;
355+ }
356+ return new RenderMimeRegistry ( {
357+ initialFactories : standardRendererFactories ,
358+ linkHandler : ! docManager
359+ ? undefined
360+ : {
361+ handleLink : ( node : HTMLElement , path : string , id ?: string ) => {
362+ // If node has the download attribute explicitly set, use the
363+ // default browser downloading behavior.
364+ if ( node . tagName === 'A' && node . hasAttribute ( 'download' ) ) {
365+ return ;
366+ }
367+ app . commandLinker . connectNode ( node , CommandIDs . handleLink , {
368+ path,
369+ id,
370+ } ) ;
371+ } ,
372+ } ,
373+ latexTypesetter : latexTypesetter ?? undefined ,
374+ markdownParser : markdownParser ?? undefined ,
375+ translator : translator ?? undefined ,
376+ sanitizer : sanitizer ?? undefined ,
377+ } ) ;
378+ } ,
379+ } ;
380+
298381/**
299382 * The default Jupyter Notebook application shell.
300383 */
@@ -919,6 +1002,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
9191002 opener ,
9201003 pages ,
9211004 paths ,
1005+ rendermime ,
9221006 shell ,
9231007 sidePanelVisibility ,
9241008 status ,
0 commit comments