Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
it('should get the file extension of the path', () => {
expect(PathExt.extname(TESTPATH)).to.equal('.js');
});
it('should only take the last occurrence of a dot', () => {
expect(PathExt.extname('foo.tar.gz')).to.equal('.gz');
});
});
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
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;
}
}
isVisible: () => {
let widget = editorTracker.currentWidget;
return (
(widget && PathExt.extname(widget.context.path) === '.tex') || false
);
},
label: 'Show LaTeX Preview'
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':
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
});
}
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 {
isVisible: () => {
let widget = tracker.currentWidget;
return (
(widget && PathExt.extname(widget.context.path) === '.md') || false
);
},
label: 'Show Markdown Preview'