Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,30 @@ if (isIndexPage) {
document.body.style.overflow = "";
}

// Render code string as a list of DOM rows where each row contains a
// line-number gutter cell and a code cell. Returning DOM nodes instead
// of an HTML string avoids innerHTML XSS risks from the code content.
function renderCodeWithLineNumbers(code) {
var lines = (code || "").split("\n");
return lines.map(function (line, index) {
var row = document.createElement("div");
row.className = "code-line";

var lineNum = document.createElement("span");
lineNum.className = "code-line-number";
lineNum.setAttribute("aria-hidden", "true");
lineNum.textContent = index + 1;

var lineCode = document.createElement("span");
lineCode.className = "code-line-content";
lineCode.textContent = line;

row.appendChild(lineNum);
row.appendChild(lineCode);
return row;
});
}

//fetches the starter code from the server via an API call
//inserts the code into the panel and handles loading/error states
function fetchStarterCode() {
Expand Down
Loading