From e38f760f3d66339120c9665e27e168c44a84e2ff Mon Sep 17 00:00:00 2001 From: RedCMD Date: Thu, 12 Dec 2024 14:04:59 +1300 Subject: [PATCH] Fix extension preview codeblock language getter --- .../markdown/browser/markdownDocumentRenderer.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/markdown/browser/markdownDocumentRenderer.ts b/src/vs/workbench/contrib/markdown/browser/markdownDocumentRenderer.ts index 30f5fd50407..e80722d7993 100644 --- a/src/vs/workbench/contrib/markdown/browser/markdownDocumentRenderer.ts +++ b/src/vs/workbench/contrib/markdown/browser/markdownDocumentRenderer.ts @@ -234,7 +234,7 @@ export async function renderMarkdownDocument( namespace MarkedHighlight { // Copied from https://github.com/markedjs/marked-highlight/blob/main/src/index.js - export function markedHighlight(options: marked.MarkedOptions & { highlight: (code: string, lang: string, info: string) => string | Promise }): marked.MarkedExtension { + export function markedHighlight(options: marked.MarkedOptions & { highlight: (code: string, lang: string) => string | Promise }): marked.MarkedExtension { if (typeof options === 'function') { options = { highlight: options, @@ -252,13 +252,11 @@ namespace MarkedHighlight { return; } - const lang = getLang(token.lang); - if (options.async) { - return Promise.resolve(options.highlight(token.text, lang, token.lang || '')).then(updateToken(token)); + return Promise.resolve(options.highlight(token.text, token.lang)).then(updateToken(token)); } - const code = options.highlight(token.text, lang, token.lang || ''); + const code = options.highlight(token.text, token.lang); if (code instanceof Promise) { throw new Error('markedHighlight is not set to async but the highlight function is async. Set the async option to true on markedHighlight to await the async highlight function.'); } @@ -276,10 +274,6 @@ namespace MarkedHighlight { }; } - function getLang(lang: string) { - return (lang || '').match(/\S*/)![0]; - } - function updateToken(token: any) { return (code: string) => { if (typeof code === 'string' && code !== token.text) {