mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
re #142429. javascript renderer
This commit is contained in:
parent
ac308c3e03
commit
88e5c12d3d
|
@ -26,7 +26,8 @@
|
|||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/svg+xml",
|
||||
"text/html"
|
||||
"text/html",
|
||||
"application/javascript"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -65,6 +65,16 @@ function renderHTML(outputInfo: OutputItem, container: HTMLElement): void {
|
|||
domEval(element);
|
||||
}
|
||||
|
||||
function renderJavascript(outputInfo: OutputItem, container: HTMLElement): void {
|
||||
const str = outputInfo.text();
|
||||
const scriptVal = `<script type="application/javascript">${str}</script>`;
|
||||
const element = document.createElement('div');
|
||||
const trustedHtml = ttPolicy?.createHTML(scriptVal) ?? scriptVal;
|
||||
element.innerHTML = trustedHtml as string;
|
||||
container.appendChild(element);
|
||||
domEval(element);
|
||||
}
|
||||
|
||||
export const activate: ActivationFunction<void> = (ctx) => {
|
||||
const disposables = new Map<string, IDisposable>();
|
||||
|
||||
|
@ -81,6 +91,15 @@ export const activate: ActivationFunction<void> = (ctx) => {
|
|||
renderHTML(outputInfo, element);
|
||||
}
|
||||
break;
|
||||
case 'application/javascript':
|
||||
{
|
||||
if (!ctx.workspace.isTrusted) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderJavascript(outputInfo, element);
|
||||
}
|
||||
break;
|
||||
case 'image/gif':
|
||||
case 'image/png':
|
||||
case 'image/jpeg':
|
||||
|
|
|
@ -20,33 +20,6 @@ import { OutputRendererRegistry } from 'vs/workbench/contrib/notebook/browser/vi
|
|||
import { truncatedArrayOfString } from 'vs/workbench/contrib/notebook/browser/view/output/transforms/textHelper';
|
||||
import { IOutputItemDto, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
||||
class JavaScriptRendererContrib extends Disposable implements IOutputTransformContribution {
|
||||
getType() {
|
||||
return RenderOutputType.Html;
|
||||
}
|
||||
|
||||
getMimetypes() {
|
||||
return ['application/javascript'];
|
||||
}
|
||||
|
||||
constructor(
|
||||
public notebookEditor: INotebookDelegateForOutput,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
render(output: ICellOutputViewModel, item: IOutputItemDto, container: HTMLElement, notebookUri: URI): IRenderOutput {
|
||||
|
||||
const str = getStringValue(item);
|
||||
const scriptVal = `<script type="application/javascript">${str}</script>`;
|
||||
|
||||
return {
|
||||
type: RenderOutputType.Html,
|
||||
source: output,
|
||||
htmlContent: scriptVal
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class StreamRendererContrib extends Disposable implements IOutputTransformContribution {
|
||||
getType() {
|
||||
|
@ -185,7 +158,6 @@ class PlainTextRendererContrib extends Disposable implements IOutputTransformCon
|
|||
}
|
||||
}
|
||||
|
||||
OutputRendererRegistry.registerOutputTransform(JavaScriptRendererContrib);
|
||||
OutputRendererRegistry.registerOutputTransform(PlainTextRendererContrib);
|
||||
OutputRendererRegistry.registerOutputTransform(JSErrorRendererContrib);
|
||||
OutputRendererRegistry.registerOutputTransform(StreamRendererContrib);
|
||||
|
|
|
@ -597,9 +597,7 @@ type MimeTypeInfo = {
|
|||
};
|
||||
|
||||
const _mimeTypeInfo = new Map<string, MimeTypeInfo>([
|
||||
['application/javascript', { supportedByCore: true }],
|
||||
['image/git', { alwaysSecure: true, supportedByCore: true }],
|
||||
['image/svg+xml', { supportedByCore: true }],
|
||||
['application/json', { alwaysSecure: true, supportedByCore: true }],
|
||||
[Mimes.text, { alwaysSecure: true, supportedByCore: true }],
|
||||
['text/x-javascript', { alwaysSecure: true, supportedByCore: true }], // secure because rendered as text, not executed
|
||||
|
|
Loading…
Reference in a new issue