/* ----------------------------------------------------------------------------- | Copyright (c) Jupyter Development Team. | Distributed under the terms of the Modified BSD License. |----------------------------------------------------------------------------*/ import { URLExt } from '@jupyterlab/coreutils'; import { IRenderMime } from '@jupyterlab/rendermime-interfaces'; import { ITranslator, nullTranslator } from '@jupyterlab/translation'; import escape from 'lodash.escape'; import { removeMath, replaceMath } from './latex'; /** * Render HTML into a host node. * * @param options - The options for rendering. * * @returns A promise which resolves when rendering is complete. */ export async function renderHTML(options: renderHTML.IOptions): Promise { // Unpack the options. let { host, source, trusted, sanitizer, resolver, linkHandler, shouldTypeset, latexTypesetter, translator } = options; translator = translator || nullTranslator; const trans = translator?.load('jupyterlab'); let originalSource = source; // Bail early if the source is empty. if (!source) { host.textContent = ''; return; } // Sanitize the source if it is not trusted. This removes all // `