init
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
export function render(buffer, cursor) {
|
||||
const html = buffer.map((line, i) => {
|
||||
if (i !== cursor.line) return `<span>${escapeHtml(line)}</span>`;
|
||||
const before = escapeHtml(line.slice(0, cursor.col));
|
||||
const after = escapeHtml(line.slice(cursor.col));
|
||||
return `<span>${before}<span class="cursor"></span>${after}</span>`;
|
||||
});
|
||||
document.getElementById("text").innerHTML = html.join("<br>");
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||
}
|
||||
Reference in New Issue
Block a user