src/vs/workbench/contrib/markdown/common/markdownDocumentRenderer.ts/highlight
export async function renderMarkdownDocument(
	text: string,
	extensionService: IExtensionService,
	modeService: IModeService,
	shouldRemoveEmbeddedSVGs: boolean = true,
): Promise<string> {

	const highlight = (code: string, lang: string, callback: ((error: any, code: string) => void) | undefined): any => {
		if (!callback) {
			return code;
		}
		extensionService.whenInstalledExtensionsRegistered().then(async () => {
			let support: ITokenizationSupport | undefined;
			const modeId = modeService.getModeIdForLanguageName(lang);
			if (modeId) {
				modeService.triggerMode(modeId);
				support = await TokenizationRegistry.getPromise(modeId) ?? undefined;
			}
			callback(null, `<code>${tokenizeToString(code, support)}</code>`);
		});
		return '';
	};

	return new Promise<string>((resolve, reject) => {
		marked(text, { highlight }, (err, value) => err ? reject(err) : resolve(value));
	}).then(raw => {
		if (shouldRemoveEmbeddedSVGs) {
			return removeEmbeddedSVGs(raw);
		}
		else {
			return raw;
		}
	});
}