Refactor: use a div for each line

This commit is contained in:
quenousimporte 2023-10-06 17:47:27 +02:00
parent 11add81bf8
commit 37b996e4bc
1 changed files with 28 additions and 7 deletions

35
main.js
View File

@ -2108,10 +2108,12 @@ function applycolors()
var lines = md.value.split("\n"); var lines = md.value.split("\n");
var header = false; var header = false;
var code = false; var code = false;
var comment = false;
var language = ""; var language = "";
var result = []; var resulthtml = "";
lines.every( (line, i) => lines.every( (line, i) =>
{ {
resulthtml += "<div id='line" + i + "'>";
line = escapeHtml(line); line = escapeHtml(line);
// headings // headings
@ -2190,21 +2192,40 @@ function applycolors()
} }
// internal links // internal links
line = line.replace(/(\[\[.*\]\])/g, "<u><span style='cursor:pointer'>$1</span></u>"); line = line.replace(/(\[\[.*\]\])/g, "<u>$1</u>");
// comments // comments
line = line.replace(/&lt;\!/g, "<span style='color:lightgrey'>&lt;!"); line = line.replace(/&lt;\!--(.*)/g, "<span style='color:lightgrey'>&lt;!--$1</span>");
line = line.replace(/\-\-&gt;/g, "--></span>");
if (line.includes("&lt;!--") && !line.includes("--&gt;"))
{
comment = true;
}
else if (comment)
{
console.log("comment: " + line);
line = "<span style='color:lightgrey'>" + line
if (line.includes("--&gt;"))
{
comment = false;
}
else
{
line += "</span>";
}
}
line = line.replace(/\-\-&gt;/g, "--&gt;</span>");
if (line.startsWith("// ")) if (line.startsWith("// "))
{ {
line = "<span style='color:lightgrey'>" + line + "</span>"; line = "<span style='color:lightgrey'>" + line + "</span>";
} }
resulthtml += (line || "&nbsp;") + "</div>";
result.push(line);
return true; return true;
}); });
colored.innerHTML = result.join("<br>"); colored.innerHTML = resulthtml;
} }
function datachanged() function datachanged()