Merge pull request #235880 from RedCMD/extensionCodeblockLangFix

Fix extension preview codeblock language getter
pull/236406/head
Matt Bierner 2024-12-17 11:45:09 -08:00 committed by GitHub
commit fbc4b86553
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 9 deletions

View File

@ -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<string> }): marked.MarkedExtension {
export function markedHighlight(options: marked.MarkedOptions & { highlight: (code: string, lang: string) => string | Promise<string> }): 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) {