Revert "ongoing refactor to update colors by line"

This reverts commit cbac831768.
This commit is contained in:
quenousimporte 2023-10-19 14:15:50 +02:00
parent 24046d9f23
commit fa2afdeab5
1 changed files with 8 additions and 36 deletions

44
main.js
View File

@ -1966,46 +1966,17 @@ function rawline(index)
return md.value.split("\n")[index]; return md.value.split("\n")[index];
} }
function applycolorsonline(line, linediv, index, options) function applycolorsonline(line, index, options)
{ {
line = escapeHtml(line); line = escapeHtml(line);
while (linediv.hasChildNodes())
{
linediv.removeChild(linediv.lastChild);
}
// headings // headings
if (line.startsWith("#")) if (line.startsWith("#"))
{ {
var level = line.indexOf(" "); line = line.replace(/(#* )/, "<span style='color:" + settings.accentcolor + "'>$1</span>"); // to check!
if (level == -1) line = "<span style='font-weight: bold;'>" + line + "</span>";
{
level = line.length;
} }
var span = document.createElement("span");
span.setAttribute("style", `font-weight: bold;color:${settings.accentcolor};`);
span.appendChild(document.createTextNode("#".repeat(level)));
linediv.appendChild(span);
if (level < line.length)
{
var headingtext = line.substring(level);
span = document.createElement("span");
span.setAttribute("style", "font-weight: bold;");
span.appendChild(document.createTextNode(headingtext));
linediv.appendChild(span);
}
return;
}
// fallback
//linediv.appendChild(document.createTextNode(line || " "));
//return;
/* -----TODO------ */
// bold and italics // bold and italics
var temp = line; var temp = line;
if (line.startsWith("* ")) if (line.startsWith("* "))
@ -2129,8 +2100,7 @@ function applycolorsonline(line, linediv, index, options)
} }
} }
} }
return line;
linediv.innerHTML = line || "&nbsp;";
} }
function applycolors(currentonly) function applycolors(currentonly)
@ -2153,7 +2123,9 @@ function applycolors(currentonly)
var index = currentline(); var index = currentline();
var linediv = document.getElementById("line" + index); var linediv = document.getElementById("line" + index);
options = JSON.parse(linediv.getAttribute("tag")); options = JSON.parse(linediv.getAttribute("tag"));
applycolorsonline(rawline(index), linediv, index, options); var line = rawline(index);
line = applycolorsonline(line, index, options);
linediv.innerHTML = line || "&nbsp;";
} }
else else
{ {
@ -2170,7 +2142,7 @@ function applycolors(currentonly)
} }
linediv.setAttribute("id", "line" + i); linediv.setAttribute("id", "line" + i);
linediv.setAttribute("tag", JSON.stringify(options)); linediv.setAttribute("tag", JSON.stringify(options));
applycolorsonline(lines[i], linediv, i, options); linediv.innerHTML = applycolorsonline(lines[i], i, options) || "&nbsp;";
}; };
// remove remanining // remove remanining