How to use the @jupyterlab/coreutils.PathExt.extname function in @jupyterlab/coreutils

To help you get started, we’ve selected a few @jupyterlab/coreutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / fileeditor-extension / src / commands.ts View on Github external
execute: () => {
        // Run the appropriate code, taking into account a ```fenced``` code block.
        const widget = tracker.currentWidget.content;

        if (!widget) {
          return;
        }

        let code = '';
        const editor = widget.editor;
        const path = widget.context.path;
        const extension = PathExt.extname(path);
        const selection = editor.getSelection();
        const { start, end } = selection;
        let selected = start.column !== end.column || start.line !== end.line;

        if (selected) {
          // Get the selected code from the editor.
          const start = editor.getOffsetAt(selection.start);
          const end = editor.getOffsetAt(selection.end);

          code = editor.model.value.text.substring(start, end);
        } else if (MarkdownCodeBlocks.isMarkdown(extension)) {
          const { text } = editor.model.value;
          const blocks = MarkdownCodeBlocks.findMarkdownCodeBlocks(text);

          for (let block of blocks) {
            if (block.startLine <= start.line && start.line <= block.endLine) {
github jupyterlab / jupyterlab / tests / test-coreutils / src / path.spec.ts View on Github external
it('should get the file extension of the path', () => {
        expect(PathExt.extname(TESTPATH)).to.equal('.js');
      });
github jupyterlab / jupyterlab / tests / test-coreutils / src / path.spec.ts View on Github external
it('should only take the last occurrence of a dot', () => {
        expect(PathExt.extname('foo.tar.gz')).to.equal('.gz');
      });
    });
github jupyterlab / jupyterlab-google-drive / src / contents.ts View on Github external
async copy(fromFile: string, toDir: string): Promise {
    let fileBasename = PathExt.basename(fromFile).split('.')[0];
    fileBasename += '-Copy';
    const ext = PathExt.extname(fromFile);

    const name = await this._getNewFilename(toDir, ext, fileBasename);
    const contents = await drive.copyFile(
      fromFile,
      PathExt.join(toDir, name),
      this._fileTypeForPath
    );
    try {
      Contents.validateContentsModel(contents);
    } catch (error) {
      throw makeError(201, error.message);
    }
    this._fileChanged.emit({
      type: 'new',
      oldValue: null,
      newValue: contents
github jupyterlab / jupyterlab / packages / codemirror / src / mimetype.ts View on Github external
getMimeTypeByFilePath(path: string): string {
    const ext = PathExt.extname(path);
    if (ext === '.ipy') {
      return 'text/x-python';
    } else if (ext === '.md') {
      return 'text/x-ipythongfm';
    }
    let mode = Mode.findByFileName(path) || Mode.findBest('');
    return mode.mime;
  }
}
github jupyterlab / jupyterlab-latex / src / index.ts View on Github external
isVisible: () => {
      let widget = editorTracker.currentWidget;
      return (
        (widget && PathExt.extname(widget.context.path) === '.tex') || false
      );
    },
    label: 'Show LaTeX Preview'
github yuvipanda / simplest-notebook / packages / filebrowser / src / listing.ts View on Github external
parseFileExtension(path: string): string {
      var fileExtension = PathExt.extname(path).toLocaleLowerCase();
      switch (fileExtension) {
        case '.md':
          return MARKDOWN_ICON_CLASS;
        case '.py':
          return PYTHON_ICON_CLASS;
        case '.json':
          return JSON_ICON_CLASS;
        case '.csv':
          return SPREADSHEET_ICON_CLASS;
        case '.xls':
          return SPREADSHEET_ICON_CLASS;
        case '.r':
          return RKERNEL_ICON_CLASS;
        case '.yml':
          return YAML_ICON_CLASS;
        case '.yaml':
github jupyterlab / jupyterlab / packages / docregistry / src / context.ts View on Github external
let lang = this._factory.preferredLanguage(PathExt.basename(localPath));

    let dbFactory = options.modelDBFactory;
    if (dbFactory) {
      const localPath = manager.contents.localPath(this._path);
      this._modelDB = dbFactory.createNew(localPath);
      this._model = this._factory.createNew(lang, this._modelDB);
    } else {
      this._model = this._factory.createNew(lang);
    }

    this._readyPromise = manager.ready.then(() => {
      return this._populatedPromise.promise;
    });

    let ext = PathExt.extname(this._path);
    this.session = new ClientSession({
      manager: manager.sessions,
      path: this._path,
      type: ext === '.ipynb' ? 'notebook' : 'file',
      name: PathExt.basename(localPath),
      kernelPreference: options.kernelPreference || { shouldStart: false },
      setBusy: options.setBusy
    });
    this.session.propertyChanged.connect(this._onSessionChanged, this);
    manager.contents.fileChanged.connect(this._onFileChanged, this);

    this.urlResolver = new RenderMimeRegistry.UrlResolver({
      session: this.session,
      contents: manager.contents
    });
  }
github altair-viz / jupyterlab_voyager / src / voyagerpanel.ts View on Github external
docManager.services.contents.get(wholePath).then(src => {
              let local_filetype = PathExt.extname(DATA["url"]).substring(1);
              let local_values = read(src.content, { type: local_filetype });
              this.voyager_cur = CreateVoyager(
                this.voyager_widget.node,
                VoyagerPanel.config,
                { values: local_values }
              );
            });
          } else {
github jupyterlab / jupyterlab / packages / fileeditor-extension / src / index.ts View on Github external
isVisible: () => {
      let widget = tracker.currentWidget;
      return (
        (widget && PathExt.extname(widget.context.path) === '.md') || false
      );
    },
    label: 'Show Markdown Preview'