mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 04:53:33 +01:00
- Update `looksLikeMarkdownPath` to look at open documents and notebooks, not just the uri - Register custom command for document links
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as vscode from 'vscode';
|
|
import * as URI from 'vscode-uri';
|
|
import { Schemes } from './schemes';
|
|
|
|
export const markdownFileExtensions = Object.freeze<string[]>([
|
|
'md',
|
|
'mkd',
|
|
'mdwn',
|
|
'mdown',
|
|
'markdown',
|
|
'markdn',
|
|
'mdtxt',
|
|
'mdtext',
|
|
'workbook',
|
|
]);
|
|
|
|
export function isMarkdownFile(document: vscode.TextDocument) {
|
|
return document.languageId === 'markdown';
|
|
}
|
|
|
|
export function looksLikeMarkdownPath(resolvedHrefPath: vscode.Uri): boolean {
|
|
const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === resolvedHrefPath.toString());
|
|
if (doc) {
|
|
return isMarkdownFile(doc);
|
|
}
|
|
|
|
if (resolvedHrefPath.scheme === Schemes.notebookCell) {
|
|
for (const notebook of vscode.workspace.notebookDocuments) {
|
|
for (const cell of notebook.getCells()) {
|
|
if (cell.kind === vscode.NotebookCellKind.Markup && isMarkdownFile(cell.document)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return markdownFileExtensions.includes(URI.Utils.extname(resolvedHrefPath).toLowerCase().replace('.', ''));
|
|
}
|