提交 21c8f52d 编写于 作者: M Matt Bierner

codeBlockRenderer only used to return thenables

上级 b28eec68
......@@ -11,13 +11,12 @@ import { escape } from 'vs/base/common/strings';
import { removeMarkdownEscapes, IMarkdownString } from 'vs/base/common/htmlContent';
import { marked } from 'vs/base/common/marked/marked';
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
import { isThenable } from 'vs/base/common/async';
export interface RenderOptions {
className?: string;
inline?: boolean;
actionCallback?: (content: string, event?: IMouseEvent) => void;
codeBlockRenderer?: (modeId: string, value: string) => string | Thenable<string>;
codeBlockRenderer?: (modeId: string, value: string) => Thenable<string>;
codeBlockRenderCallback?: () => void;
}
......@@ -119,32 +118,24 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
if (options.codeBlockRenderer) {
renderer.code = (code, lang) => {
const value = options.codeBlockRenderer(lang, code);
if (typeof value === 'string') {
return value;
}
if (isThenable(value)) {
// when code-block rendering is async we return sync
// but update the node with the real result later.
const id = defaultGenerator.nextId();
const promise = Promise.all([value, withInnerHTML]).then(values => {
const strValue = values[0] as string;
const span = element.querySelector(`div[data-code="${id}"]`);
if (span) {
span.innerHTML = strValue;
}
}).catch(err => {
// ignore
});
if (options.codeBlockRenderCallback) {
promise.then(options.codeBlockRenderCallback);
// when code-block rendering is async we return sync
// but update the node with the real result later.
const id = defaultGenerator.nextId();
const promise = Promise.all([value, withInnerHTML]).then(values => {
const strValue = values[0];
const span = element.querySelector(`div[data-code="${id}"]`);
if (span) {
span.innerHTML = strValue;
}
}).catch(err => {
// ignore
});
return `<div class="code" data-code="${id}">${escape(code)}</div>`;
if (options.codeBlockRenderCallback) {
promise.then(options.codeBlockRenderCallback);
}
return code;
return `<div class="code" data-code="${id}">${escape(code)}</div>`;
};
}
......
......@@ -33,7 +33,7 @@ export class MarkdownRenderer {
actionCallback: (content) => {
this._openerService.open(URI.parse(content)).then(void 0, onUnexpectedError);
},
codeBlockRenderer: (languageAlias, value): string | TPromise<string> => {
codeBlockRenderer: (languageAlias, value): TPromise<string> => {
// In markdown,
// it is possible that we stumble upon language aliases (e.g.js instead of javascript)
// it is possible no alias is given in which case we fall back to the current editor lang
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册