From d3bcbfb77942345bab502457eee50199df833721 Mon Sep 17 00:00:00 2001 From: Thakee Nathees Date: Thu, 7 Apr 2022 16:47:22 +0530 Subject: [PATCH] try-online output changed to
 tag

---
 docs/static/codejar/linenumbers.js | 5 ++++-
 docs/static/css/try_online.css     | 2 +-
 docs/static/js/try_online.js       | 6 ++++++
 docs/wasm/io_api.js                | 4 ++--
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/docs/static/codejar/linenumbers.js b/docs/static/codejar/linenumbers.js
index e27bdd4..20647d9 100644
--- a/docs/static/codejar/linenumbers.js
+++ b/docs/static/codejar/linenumbers.js
@@ -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`;
diff --git a/docs/static/css/try_online.css b/docs/static/css/try_online.css
index e055aa0..e494ad0 100644
--- a/docs/static/css/try_online.css
+++ b/docs/static/css/try_online.css
@@ -130,7 +130,7 @@ body {
   padding: 16px 32px;
 }
 
-#code-output.has-error {
+#code-output span.error-line {
   color: var(--color-output-error);
 }
 
diff --git a/docs/static/js/try_online.js b/docs/static/js/try_online.js
index 18fefd7..825f322 100644
--- a/docs/static/js/try_online.js
+++ b/docs/static/js/try_online.js
@@ -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;
 });
 
diff --git a/docs/wasm/io_api.js b/docs/wasm/io_api.js
index 727f785..c0d8569 100644
--- a/docs/wasm/io_api.js
+++ b/docs/wasm/io_api.js
@@ -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 += `${err_text}\n`;
   },
 
   js_writeFunction : function(message) {
     var out = document.getElementById("code-output");
-    out.innerText += AsciiToString(message)
+    out.innerText += AsciiToString(message);
   },
 });