Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/src/util/file.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
import * as URI from 'vscode-uri';
8
import { Schemes } from './schemes';
9
10
export const markdownFileExtensions = Object.freeze<string[]>([
11
'md',
12
'mkd',
13
'mdwn',
14
'mdown',
15
'markdown',
16
'markdn',
17
'mdtxt',
18
'mdtext',
19
'workbook',
20
]);
21
22
export const markdownLanguageIds = ['markdown', 'prompt', 'instructions', 'chatmode'];
23
24
export function isMarkdownFile(document: vscode.TextDocument) {
25
return markdownLanguageIds.indexOf(document.languageId) !== -1;
26
}
27
28
export function looksLikeMarkdownPath(resolvedHrefPath: vscode.Uri): boolean {
29
const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === resolvedHrefPath.toString());
30
if (doc) {
31
return isMarkdownFile(doc);
32
}
33
34
if (resolvedHrefPath.scheme === Schemes.notebookCell) {
35
for (const notebook of vscode.workspace.notebookDocuments) {
36
for (const cell of notebook.getCells()) {
37
if (cell.kind === vscode.NotebookCellKind.Markup && isMarkdownFile(cell.document)) {
38
return true;
39
}
40
}
41
}
42
return false;
43
}
44
45
return markdownFileExtensions.includes(URI.Utils.extname(resolvedHrefPath).toLowerCase().replace('.', ''));
46
}
47
48