From d410d07e45bf2d01da06c90ddf68ac89ce7e2fc0 Mon Sep 17 00:00:00 2001 From: adevezin Date: Mon, 20 Mar 2023 10:44:37 -0400 Subject: [PATCH] Allow markdown for success and failure messages --- .../swiftplugin/static/js/src/swiftplugin.js | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/swiftplugin/swiftplugin/static/js/src/swiftplugin.js b/swiftplugin/swiftplugin/static/js/src/swiftplugin.js index 103b53e..0b04040 100644 --- a/swiftplugin/swiftplugin/static/js/src/swiftplugin.js +++ b/swiftplugin/swiftplugin/static/js/src/swiftplugin.js @@ -88,14 +88,15 @@ function SwiftPluginXBlock(runtime, element) { } function setOutput(response) { - const compilation_response = response.response.output + const compilationResponse = response.response.output let color = response.response.success ? "#33691E" : "#B00020" + const html = getMarkdownHtml(compilationResponse); if (response.response.success) { - document.getElementById('response-txt').innerHTML = compilation_response; + document.getElementById('response-txt').innerHTML = html; } else if (response.response.diff) { document.getElementById('response-txt').innerHTML = response.response.diff; } else { - document.getElementById('response-txt').innerHTML = compilation_response; + document.getElementById('response-txt').innerHTML = html; } document.getElementById('response-title').style.color = color; @@ -162,17 +163,22 @@ function SwiftPluginXBlock(runtime, element) { response_title.hidden = is_submit_hidden && is_run_hidden } + function getMarkdownHtml(response) { + const converter = new showdown.Converter(showdownOptions); + let html = converter.makeHtml(response); + const regex = //g; + html = html.replace(regex, '
'); + return `
${html}
` + } + function updateProblemDescription(response) { if (!response.problem_description) { console.log('No problem description') return } const myAssigmentTextArea = document.getElementById("assigment-instructions-text"); - const converter = new showdown.Converter(showdownOptions); - let html = converter.makeHtml(response.problem_description); - const regex = /
/g; - html = html.replace(regex, '
'); - myAssigmentTextArea.innerHTML = `
${html}
`; + const html = getMarkdownHtml(response.problem_description); + myAssigmentTextArea.innerHTML = html; } function updateProblemTitle(response) {