try-online output changed to <pre> tag

This commit is contained in:
Thakee Nathees 2022-04-07 16:47:22 +05:30
parent bdd619c859
commit d3bcbfb779
4 changed files with 13 additions and 4 deletions

View File

@ -8,7 +8,10 @@ function withLineNumbers(highlight, options = {}) {
editor.addEventListener("scroll", () => lineNumbers.style.top = `-${editor.scrollTop}px`);
}
const code = editor.textContent || "";
const linesCount = code.replace(/\n+$/, "\n").split("\n").length + 1;
//const linesCount = code.replace(/\n+$/, "\n").split("\n").length + 1;
const linesCount = code.split("\n").length;
let text = "";
for (let i = 1; i < linesCount; i++) {
text += `${i}\n`;

View File

@ -130,7 +130,7 @@ body {
padding: 16px 32px;
}
#code-output.has-error {
#code-output span.error-line {
color: var(--color-output-error);
}

View File

@ -58,6 +58,12 @@ let code_example_titles = $$(".code-example-title");
let code_highlight_fn = withLineNumbers(function(editor) {
editor.textContent = editor.textContent;
html = hljs.highlight(editor.textContent, {language : 'ruby'}).value;
// https://github.com/antonmedv/codejar/issues/22#issuecomment-773894139
if (html.length > 2 && html.substring(html.length - 2, html.length) != '\n\n') {
html += '\n'
}
editor.innerHTML = html;
});

View File

@ -24,11 +24,11 @@ mergeInto(LibraryManager.library, {
var out = document.getElementById("code-output");
// To Indicate error (should be removed before each run request).
out.classList.add("has-error");
out.innerText += err_text + '\n';
out.innerHTML += `<span class="error-line">${err_text}</span>\n`;
},
js_writeFunction : function(message) {
var out = document.getElementById("code-output");
out.innerText += AsciiToString(message)
out.innerText += AsciiToString(message);
},
});