refactor: use shared unescapeHtml in CodeBlock (#23553)
This commit is contained in:
1 parent
69b3ec3511
commit
bf49358185
1 file changed
+3
-15
@@ -10,7 +10,8 @@
|
|||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
initMermaid,
|
initMermaid,
|
||||||
renderMermaidDiagram,
|
renderMermaidDiagram,
|
||||||
renderVegaVisualization
|
renderVegaVisualization,
|
||||||
|
unescapeHtml
|
||||||
} from '$lib/utils';
|
} from '$lib/utils';
|
||||||
|
|
||||||
import 'highlight.js/styles/github-dark.min.css';
|
import 'highlight.js/styles/github-dark.min.css';
|
||||||
@@ -405,21 +406,8 @@
|
|||||||
|
|
||||||
const onAttributesUpdate = () => {
|
const onAttributesUpdate = () => {
|
||||||
if (attributes?.output) {
|
if (attributes?.output) {
|
||||||
// Create a helper function to unescape HTML entities
|
|
||||||
const unescapeHtml = (html) => {
|
|
||||||
const textArea = document.createElement('textarea');
|
|
||||||
textArea.innerHTML = html;
|
|
||||||
return textArea.value;
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Unescape the HTML-encoded string
|
const output = JSON.parse(unescapeHtml(attributes.output));
|
||||||
const unescapedOutput = unescapeHtml(attributes.output);
|
|
||||||
|
|
||||||
// Parse the unescaped string into JSON
|
|
||||||
const output = JSON.parse(unescapedOutput);
|
|
||||||
|
|
||||||
// Assign the parsed values to variables
|
|
||||||
stdout = output.stdout;
|
stdout = output.stdout;
|
||||||
stderr = output.stderr;
|
stderr = output.stderr;
|
||||||
result = output.result;
|
result = output.result;
|
||||||
|
|||||||
Reference in new issue
Block a user