Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependency loop with statustracker and markdown #8821

Merged
merged 6 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix loop
  • Loading branch information
aliabd committed Jul 17, 2024
commit 4e7cb68783ab5c73e2323b3d53544fc8054717dd
2 changes: 1 addition & 1 deletion js/statustracker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@gradio/atoms": "workspace:^",
"@gradio/icons": "workspace:^",
"@gradio/utils": "workspace:^",
"@gradio/markdown": "workspace:^"
"dompurify": "^3.0.3"
},
"devDependencies": {
"@gradio/preview": "workspace:^"
Expand Down
24 changes: 22 additions & 2 deletions js/statustracker/static/ToastContent.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { Error, Info, Warning } from "@gradio/icons";
import { MarkdownCode } from "@gradio/markdown";
import DOMPurify from "dompurify";
import { createEventDispatcher, onMount } from "svelte";
import { fade } from "svelte/transition";
import type { ToastMessage } from "./types";
Expand All @@ -11,6 +11,26 @@
export let duration: number | null = 10;
export let visible = true;

const is_external_url = (link: string | null): boolean => {
try {
return !!link && new URL(link, location.href).origin !== location.origin;
} catch (e) {
return false;
}
};

DOMPurify.addHook("afterSanitizeAttributes", function (node) {
if ("target" in node) {
if (is_external_url(node.getAttribute("href"))) {
node.setAttribute("target", "_blank");
node.setAttribute("rel", "noopener noreferrer");
}
}
});

$: message = DOMPurify.sanitize(message);


$: display = visible;
$: duration = duration || null;

Expand Down Expand Up @@ -56,7 +76,7 @@
<div class="toast-details {type}">
<div class="toast-title {type}">{type}</div>
<div class="toast-text {type}">
<MarkdownCode {message} chatbot={false} render_markdown={false} />
{@html message}
</div>
</div>

Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.