Skip to content

Commit af16ec8

Browse files
committed
refactor: use shared unescapeHtml in CodeBlock
1 parent a9c7d68 commit af16ec8

1 file changed

Lines changed: 3 additions & 15 deletions

File tree

src/lib/components/chat/Messages/CodeBlock.svelte

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
copyToClipboard,
1111
initMermaid,
1212
renderMermaidDiagram,
13-
renderVegaVisualization
13+
renderVegaVisualization,
14+
unescapeHtml
1415
} from '$lib/utils';
1516
1617
import 'highlight.js/styles/github-dark.min.css';
@@ -405,21 +406,8 @@
405406
406407
const onAttributesUpdate = () => {
407408
if (attributes?.output) {
408-
// Create a helper function to unescape HTML entities
409-
const unescapeHtml = (html) => {
410-
const textArea = document.createElement('textarea');
411-
textArea.innerHTML = html;
412-
return textArea.value;
413-
};
414-
415409
try {
416-
// Unescape the HTML-encoded string
417-
const unescapedOutput = unescapeHtml(attributes.output);
418-
419-
// Parse the unescaped string into JSON
420-
const output = JSON.parse(unescapedOutput);
421-
422-
// Assign the parsed values to variables
410+
const output = JSON.parse(unescapeHtml(attributes.output));
423411
stdout = output.stdout;
424412
stderr = output.stderr;
425413
result = output.result;

0 commit comments

Comments
 (0)