src/vs/workbench/contrib/markdown/browser/markdownDocumentRenderer.ts/renderMarkdownDocument
export async function renderMarkdownDocument(
	text: string,
	extensionService: IExtensionService,
	languageService: ILanguageService,
	shouldSanitize: boolean = true,
	allowUnknownProtocols: boolean = false,
	token?: CancellationToken,
): Promise<string> {

	const highlight = (code: string, lang: string | undefined, callback: ((error: any, code: string) => void) | undefined): any => {
		if (!callback) {
			return code;
		}

		if (typeof lang !== 'string') {
			callback(null, `<code>${code}</code>`);
			return '';
		}

		extensionService.whenInstalledExtensionsRegistered().then(async () => {
			if (token?.isCancellationRequested) {
				callback(null, '');
				return;
			}

			const languageId = languageService.getLanguageIdByLanguageName(lang);
			const html = await tokenizeToString(languageService, code, languageId);
			callback(null, `<code>${html}</code>`);
		});
		return '';
	};

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