Files
luma-editor/render.js
T
2026-06-30 20:23:53 +02:00

14 lines
517 B
JavaScript

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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}