<commit_before>var marked = require("marked");
var fs = require("fs");
var hljs = require("highlight.js");

var TOS = fs.readFileSync("resources/TOS.md", "utf-8");
var pageTemplate = fs.readFileSync("resources/template.html", "utf-8");
var footerTemplate = fs.readFileSync("resources/footer.html", "utf-8");
var editTemplate = fs.readFileSync("resources/edit.html", "utf-8");
var header = fs.readFileSync(process.env.HEADER || "/dev/null", "utf-8");
var defaultBL = new Set();

var deriveTitle = text => text
  .split(/[\n\r]/)[0].slice(0,25)
  .replace(/[^a-zA-Z0-9\s]/g, "");

var renderPage = (id, title, content, footer, blackList) => pageTemplate
  .replace("%HEADER%", (blackList || defaultBL).has(id) ? header : "")
  .replace("%TITLE%", title)
  .replace("%CONTENT%", content.replace(/<meta.*?>/gi, "").replace(/<script[\s\S.]*?\/script>/gi, ""))
  .replace("%FOOTER%", footer || "");

marked.setOptions({
  langPrefix: 'hljs lang-',
  highlight: function (code) {
    return hljs.highlightAuto(code).value;
  },
});

module.exports.renderPage = renderPage;

module.exports.renderStats = note => renderPage(note.id, deriveTitle(note.text), 
  `<h2>Statistics</h2>
  <table>
    <tr><td>Published</td><td>${note.published}</td></tr>
    <tr><td>Edited</td><td>${note.edited || "N/A"}</td></tr>
    <tr><td>Views</td><td>${note.views}</td></tr>
  </table>`);

module.exports.renderTOS = () => 
  renderPage("tos", "Terms of Service", marked(TOS));

module.exports.renderNote = (note, blackList) => renderPage(note.id,
  deriveTitle(note.text), 
  marked(note.text),
  footerTemplate.replace(/%LINK%/g, note.id),
  blackList);

module.exports.newNotePage = session => editTemplate
  .replace("%ACTION%", "POST")
  .replace("%SESSION%", session)
  .replace("%CONTENT%", "Loading...");
<commit_msg>Highlight: Use arrow functions (back-end rendering).<commit_after>var marked = require("marked");
var fs = require("fs");
var hljs = require("highlight.js");

var TOS = fs.readFileSync("resources/TOS.md", "utf-8");
var pageTemplate = fs.readFileSync("resources/template.html", "utf-8");
var footerTemplate = fs.readFileSync("resources/footer.html", "utf-8");
var editTemplate = fs.readFileSync("resources/edit.html", "utf-8");
var header = fs.readFileSync(process.env.HEADER || "/dev/null", "utf-8");
var defaultBL = new Set();

var deriveTitle = text => text
  .split(/[\n\r]/)[0].slice(0,25)
  .replace(/[^a-zA-Z0-9\s]/g, "");

var renderPage = (id, title, content, footer, blackList) => pageTemplate
  .replace("%HEADER%", (blackList || defaultBL).has(id) ? header : "")
  .replace("%TITLE%", title)
  .replace("%CONTENT%", content.replace(/<meta.*?>/gi, "").replace(/<script[\s\S.]*?\/script>/gi, ""))
  .replace("%FOOTER%", footer || "");

marked.setOptions({
  langPrefix: "hljs lang-",
  highlight: code => hljs.highlightAuto(code).value,
});

module.exports.renderPage = renderPage;

module.exports.renderStats = note => renderPage(note.id, deriveTitle(note.text), 
  `<h2>Statistics</h2>
  <table>
    <tr><td>Published</td><td>${note.published}</td></tr>
    <tr><td>Edited</td><td>${note.edited || "N/A"}</td></tr>
    <tr><td>Views</td><td>${note.views}</td></tr>
  </table>`);

module.exports.renderTOS = () => 
  renderPage("tos", "Terms of Service", marked(TOS));

module.exports.renderNote = (note, blackList) => renderPage(note.id,
  deriveTitle(note.text), 
  marked(note.text),
  footerTemplate.replace(/%LINK%/g, note.id),
  blackList);

module.exports.newNotePage = session => editTemplate
  .replace("%ACTION%", "POST")
  .replace("%SESSION%", session)
  .replace("%CONTENT%", "Loading...");

{'fraction_non_alphanumeric': 0.2318118948824343, 'fraction_numerical': 0.007192254495159059, 'mean_word_length': 4.918166939443535, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1242260', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1277, 'n_words': 213}