mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-12 10:34:32 +08:00
1419538ea7
* asd * changes * fix everything * cleanup * add changeset * fix casing * lockfile * fix casing * fix ci, enable linting * fix test * add changeset * add changeset * delete changeset * fix dirs * fix casing * fix notebooks * fix casing * fix casing * fix casing * fix casing * fix casing * fix casing * fix casing * fix casing --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
55 lines
1.2 KiB
Svelte
55 lines
1.2 KiB
Svelte
<script lang="ts">
|
|
import { afterUpdate, tick, createEventDispatcher } from "svelte";
|
|
import DOMPurify from "dompurify";
|
|
import render_math_in_element from "katex/dist/contrib/auto-render.js";
|
|
import { marked } from "../utils";
|
|
const dispatch = createEventDispatcher();
|
|
|
|
export let message: string;
|
|
let old_message = "";
|
|
export let latex_delimiters: {
|
|
left: string;
|
|
right: string;
|
|
display: boolean;
|
|
}[];
|
|
|
|
let el: HTMLSpanElement;
|
|
let mounted = false;
|
|
|
|
DOMPurify.addHook("afterSanitizeAttributes", function (node) {
|
|
if ("target" in node) {
|
|
node.setAttribute("target", "_blank");
|
|
node.setAttribute("rel", "noopener noreferrer");
|
|
}
|
|
});
|
|
|
|
afterUpdate(() => {
|
|
tick().then(() => {
|
|
if (message !== old_message) {
|
|
requestAnimationFrame(() => {
|
|
el.innerHTML = DOMPurify.sanitize(marked.parse(message));
|
|
mounted = true;
|
|
old_message = message;
|
|
dispatch("load");
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
$: mounted &&
|
|
latex_delimiters.length > 0 &&
|
|
render_math_in_element(el, {
|
|
delimiters: latex_delimiters,
|
|
throwOnError: false
|
|
});
|
|
</script>
|
|
|
|
<span bind:this={el} />
|
|
|
|
<style>
|
|
span :global(code[class*="language-"]),
|
|
span :global(pre[class*="language-"]) {
|
|
font-size: var(--text-md);
|
|
}
|
|
</style>
|