Clean up HtmlRenderingHook (#154961)

- Pass `HtmlRenderingHook` to hook
-  Rename register function to make it clear it is experimental
- Add docs
This commit is contained in:
Matt Bierner 2022-07-12 11:27:47 -07:00 committed by GitHub
parent f86174be34
commit 8f4d1a97f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,7 +11,12 @@ interface IDisposable {
}
interface HtmlRenderingHook {
postRender(element: HTMLElement): HTMLElement | undefined;
/**
* 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) {
@ -75,7 +80,7 @@ function renderHTML(outputInfo: OutputItem, container: HTMLElement, hooks: Itera
element.innerHTML = trustedHtml as string;
for (const hook of hooks) {
element = hook.postRender(element) ?? element;
element = hook.postRender(outputInfo, element) ?? element;
}
container.appendChild(element);
@ -286,7 +291,7 @@ export const activate: ActivationFunction<void> = (ctx) => {
disposables.forEach(d => d.dispose());
}
},
registerHtmlRenderingHook: (hook: HtmlRenderingHook): IDisposable => {
experimental_registerHtmlRenderingHook: (hook: HtmlRenderingHook): IDisposable => {
htmlHooks.add(hook);
return {
dispose: () => {