mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 01:28:26 -05:00
Merge from vscode merge-base (#22780)
* Revert "Revert "Merge from vscode merge-base (#22769)" (#22779)"
This reverts commit 47a1745180.
* Fix notebook download task
* Remove done call from extensions-ci
This commit is contained in:
@@ -10,13 +10,21 @@ interface IDisposable {
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
interface HtmlRenderingHook {
|
||||
/**
|
||||
* Invoked after the output item has been rendered but before it has been appended to the document.
|
||||
*
|
||||
* @return A new `HTMLElement` or `undefined` to continue using the provided element.
|
||||
*/
|
||||
postRender(outputItem: OutputItem, element: HTMLElement): HTMLElement | undefined;
|
||||
}
|
||||
|
||||
function clearContainer(container: HTMLElement) {
|
||||
while (container.firstChild) {
|
||||
container.removeChild(container.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function renderImage(outputInfo: OutputItem, element: HTMLElement): IDisposable {
|
||||
const blob = new Blob([outputInfo.data()], { type: outputInfo.mime });
|
||||
const src = URL.createObjectURL(blob);
|
||||
@@ -64,12 +72,17 @@ const domEval = (container: Element) => {
|
||||
}
|
||||
};
|
||||
|
||||
function renderHTML(outputInfo: OutputItem, container: HTMLElement): void {
|
||||
function renderHTML(outputInfo: OutputItem, container: HTMLElement, hooks: Iterable<HtmlRenderingHook>): void {
|
||||
clearContainer(container);
|
||||
let element: HTMLElement = document.createElement('div');
|
||||
const htmlContent = outputInfo.text();
|
||||
const element = document.createElement('div');
|
||||
const trustedHtml = ttPolicy?.createHTML(htmlContent) ?? htmlContent;
|
||||
element.innerHTML = trustedHtml as string;
|
||||
|
||||
for (const hook of hooks) {
|
||||
element = hook.postRender(outputInfo, element) ?? element;
|
||||
}
|
||||
|
||||
container.appendChild(element);
|
||||
domEval(element);
|
||||
}
|
||||
@@ -167,6 +180,8 @@ function renderText(outputInfo: OutputItem, container: HTMLElement, ctx: Rendere
|
||||
|
||||
export const activate: ActivationFunction<void> = (ctx) => {
|
||||
const disposables = new Map<string, IDisposable>();
|
||||
const htmlHooks = new Set<HtmlRenderingHook>();
|
||||
|
||||
const latestContext = ctx as (RendererContext<void> & { readonly settings: { readonly lineLimit: number } });
|
||||
|
||||
const style = document.createElement('style');
|
||||
@@ -210,6 +225,7 @@ export const activate: ActivationFunction<void> = (ctx) => {
|
||||
}
|
||||
`;
|
||||
document.body.appendChild(style);
|
||||
|
||||
return {
|
||||
renderOutputItem: (outputInfo, element) => {
|
||||
switch (outputInfo.mime) {
|
||||
@@ -220,7 +236,7 @@ export const activate: ActivationFunction<void> = (ctx) => {
|
||||
return;
|
||||
}
|
||||
|
||||
renderHTML(outputInfo, element);
|
||||
renderHTML(outputInfo, element, htmlHooks);
|
||||
}
|
||||
break;
|
||||
case 'application/javascript':
|
||||
@@ -267,8 +283,6 @@ export const activate: ActivationFunction<void> = (ctx) => {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
disposeOutputItem: (id: string | undefined) => {
|
||||
if (id) {
|
||||
@@ -276,6 +290,14 @@ export const activate: ActivationFunction<void> = (ctx) => {
|
||||
} else {
|
||||
disposables.forEach(d => d.dispose());
|
||||
}
|
||||
},
|
||||
experimental_registerHtmlRenderingHook: (hook: HtmlRenderingHook): IDisposable => {
|
||||
htmlHooks.add(hook);
|
||||
return {
|
||||
dispose: () => {
|
||||
htmlHooks.delete(hook);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user