Path: blob/main/extensions/markdown-language-features/src/util/file.ts
3292 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as vscode from 'vscode';6import * as URI from 'vscode-uri';7import { Schemes } from './schemes';89export const markdownFileExtensions = Object.freeze<string[]>([10'md',11'mkd',12'mdwn',13'mdown',14'markdown',15'markdn',16'mdtxt',17'mdtext',18'workbook',19]);2021export const markdownLanguageIds = ['markdown', 'prompt', 'instructions', 'chatmode'];2223export function isMarkdownFile(document: vscode.TextDocument) {24return markdownLanguageIds.indexOf(document.languageId) !== -1;25}2627export function looksLikeMarkdownPath(resolvedHrefPath: vscode.Uri): boolean {28const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === resolvedHrefPath.toString());29if (doc) {30return isMarkdownFile(doc);31}3233if (resolvedHrefPath.scheme === Schemes.notebookCell) {34for (const notebook of vscode.workspace.notebookDocuments) {35for (const cell of notebook.getCells()) {36if (cell.kind === vscode.NotebookCellKind.Markup && isMarkdownFile(cell.document)) {37return true;38}39}40}41return false;42}4344return markdownFileExtensions.includes(URI.Utils.extname(resolvedHrefPath).toLowerCase().replace('.', ''));45}464748