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(pipeline-editor): fix not sanitized html for use-instill-form issue #1327

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@types/react-avatar-editor": "^13.0.2",
"@types/react-dom": "18.2.0",
"@types/react-syntax-highlighter": "^15.5.7",
"@types/sanitize-html": "^2.11.0",
"@types/semver": "^7.5.3",
"@types/testing-library__jest-dom": "^5.14.5",
"@types/uuid": "^9.0.1",
Expand Down Expand Up @@ -142,6 +143,7 @@
"react-syntax-highlighter": "^15.5.0",
"reactflow": "^11.10.0",
"recharts": "2.12.7",
"sanitize-html": "^2.13.0",
"semver": "^7.5.4",
"server-only": "^0.0.1",
"unique-names-generator": "^4.7.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as React from "react";
import cn from "clsx";
import Markdown from "markdown-to-jsx";
import sanitizeHtml from "sanitize-html";

import { Switch } from "@instill-ai/design-system";

Expand All @@ -12,6 +13,8 @@ import { CopyButton } from "./CopyButton";
export const MDTextViewer = ({ text }: { text: Nullable<string> }) => {
const [enableFormattedText, setEnableFormattedText] = React.useState(false);

const sanitizedHtmlText = sanitizeHtml(text ?? "");

return (
<React.Fragment>
{/* The anchor, code, paragraph in the MD viewer will overflow */}
Expand Down Expand Up @@ -62,7 +65,7 @@ export const MDTextViewer = ({ text }: { text: Nullable<string> }) => {
</div>
</div>
<div className="ml-auto flex flex-row">
<CopyButton className="my-auto" text={text ?? ""} />
<CopyButton className="my-auto" text={sanitizedHtmlText} />
</div>
</div>
<div>
Expand All @@ -72,15 +75,15 @@ export const MDTextViewer = ({ text }: { text: Nullable<string> }) => {
enableFormattedText ? "" : "hidden",
)}
>
<Markdown>{text ?? ""}</Markdown>
<Markdown>{sanitizedHtmlText}</Markdown>
</div>
<pre
className={cn(
"flex w-full flex-1 items-center whitespace-pre-line break-all px-1.5 py-1 text-semantic-fg-primary product-body-text-4-regular",
enableFormattedText ? "hidden" : "",
)}
>
{text}
{sanitizedHtmlText}
</pre>
</div>
</div>
Expand Down
15 changes: 14 additions & 1 deletion pnpm-lock.yaml

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

Loading