Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
up elm_highlighte
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Sep 15, 2024
1 parent 52e202b commit 3551183
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions script/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Elements
const elm_code = document.querySelector('.code');
const elm_highlighte = document.querySelector('.highlighted-code');
// const elm_highlighte = document.querySelector('.highlighted-code');
const elm_execute = document.querySelector('.execute');
const elm_output = document.querySelector('.output');
const elm_error = document.querySelector('.error');
Expand Down Expand Up @@ -272,7 +272,7 @@ const runSalam = (showOutput) => {
return;
}

const rawCode = elm_code.textContent || elm_code.innerText;
const rawCode = elm_code.value;
if (!rawCode) {
elm_error.innerHTML = '';
elm_output.innerHTML = '';
Expand Down Expand Up @@ -370,15 +370,15 @@ const save_code = () => {
});
};

const highlightCode = (code) => {
const highlightedText = code.replace(
new RegExp(`\\b(${keywords.join('|')})\\b`, 'g'),
'<span style="background-color: yellow;">$1</span>'
);
console.log("highlightCode", code, keywords, highlightedText);

elm_highlighte.innerHTML = highlightedText;
};
// const highlightCode = (code) => {
// const highlightedText = code.replace(
// new RegExp(`\\b(${keywords.join('|')})\\b`, 'g'),
// '<span style="background-color: yellow;">$1</span>'
// );
// console.log("highlightCode", code, keywords, highlightedText);
//
// elm_highlighte.innerHTML = highlightedText;
// };

// Events
elm_execute.addEventListener('click', () => {
Expand All @@ -401,7 +401,7 @@ elm_code.addEventListener('keydown', (event) => {
elm_code.addEventListener("input", () => {
const inputText = elm_code.value.toString().trim();

highlightCode(inputText);
// highlightCode(inputText);

localStorage.setItem("cache-code", inputText);

Expand Down

0 comments on commit 3551183

Please sign in to comment.