jupyterlab/jupyterlab

Associate file type to an existing text editor syntax highlight or a custom one.

Open

#7 427 ouverte le 28 oct. 2019

Voir sur GitHub
 (7 commentaires) (1 réaction) (0 assignés)TypeScript (13 454 stars) (2 937 forks)batch import
documentationgood first issue

Description

There already issue #4223 (and all those related one: #5064, #4005, #3858, #4048, #6442, #6813) that is talking about this, but none of them seem to be giving a working solution. I have already try what @BoPeng suggest in issue #4423 but it's not working and I kind of have to figure a solution quickly for this. So that's why I'm re-posting this issue, to have some feedback and have a clear solution, because all those issue are kind of dated and it's not clear what is available in the curent 1.1 version.

I have a file format that I want to open with the text editor (codemirror) and the syntax highlighter mathematica that is already there. So I did an application plugins and used the @jupyterlab/application.JupyterFrontEnd.docRegistry.addFileType(), but it's not working like I want it to. It's opening the text editor but it's not setting the language (syntaxe highlighter) correctly. I tough that the "mimeTypes" was the thing that specified to the text editor what syntax highlight to use, but apparently it's not the case. I tried many type of mimeTypes but it's not changing the result.

Here's my code:

import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import "../style/index.css";


// const MIME_TYPE = 'application/vdn.reactivecore.trd';
// const TRD_MIME_TYPE = 'application/vnd.wolfram.mathematica';
const TRD_MIME_TYPE = 'application/json';
// const OWL_MIME_TYPE = 'text/xml';


/**
 * Add the ReactiveCore file type into Jupyterlab document registery.
 */
const registerReactiveCoreFileType = (app: JupyterFrontEnd) => {
    app.docRegistry.addFileType({
        name: "TRD",
        displayName: "TRD File",
        extensions: [".trd", ".rrx", ".rrl", ".rrd", ".rr"],
        mimeTypes: [TRD_MIME_TYPE],
        iconClass: "jp-MaterialIcon reactivecore_icon"
    });
}

/**
 * Initialization data for the jupyterlab-ext-reactivecore-filetype extension.
 */
const extension: JupyterFrontEndPlugin<void> = {
    id: 'jupyterlab-ext-reactivecore-filetype',
    autoStart: true,
    activate: (app: JupyterFrontEnd) => {
        console.log('JupyterLab extension jupyterlab-ext-reactivecore-filetype is activated!');
        registerReactiveCoreFileType(app)
    }
};

export default extension;

I also tried to do a Mime Renderer Extensions, but it's seem to only give you the possibility to do your own render, where I would simply like to use the already existing jupyterlab code editor (codemirror) with a specific syntax highlight.

So what can I did to have the behaviour I'm locking for?

Also, when I have this working, I would like to tried to add a codemirror mode to have my own syntaxe highlighter, but again I see a lot of issue open on that mater, like #5504 and #5829 but no good documentation on the subject, so some help would also be appreciated for this to.

Guide contributeur