Refactor: use a div for each line
This commit is contained in:
parent
11add81bf8
commit
37b996e4bc
35
main.js
35
main.js
|
@ -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(/<\!/g, "<span style='color:lightgrey'><!");
|
line = line.replace(/<\!--(.*)/g, "<span style='color:lightgrey'><!--$1</span>");
|
||||||
line = line.replace(/\-\->/g, "--></span>");
|
|
||||||
|
if (line.includes("<!--") && !line.includes("-->"))
|
||||||
|
{
|
||||||
|
comment = true;
|
||||||
|
}
|
||||||
|
else if (comment)
|
||||||
|
{
|
||||||
|
console.log("comment: " + line);
|
||||||
|
line = "<span style='color:lightgrey'>" + line
|
||||||
|
if (line.includes("-->"))
|
||||||
|
{
|
||||||
|
comment = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
line += "</span>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line = line.replace(/\-\->/g, "--></span>");
|
||||||
|
|
||||||
if (line.startsWith("// "))
|
if (line.startsWith("// "))
|
||||||
{
|
{
|
||||||
line = "<span style='color:lightgrey'>" + line + "</span>";
|
line = "<span style='color:lightgrey'>" + line + "</span>";
|
||||||
}
|
}
|
||||||
|
resulthtml += (line || " ") + "</div>";
|
||||||
result.push(line);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
colored.innerHTML = result.join("<br>");
|
colored.innerHTML = resulthtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
function datachanged()
|
function datachanged()
|
||||||
|
|
Loading…
Reference in New Issue