const $ = require('jquery');
const content = require('../README.md');

require('./style.css');

const $content = $('.content');
const $chapters = $('.navigation-list');

$content.html(content);

$('h2').each(function (index, heading) {
  const href = $(heading).attr('id');
  const title = $(heading).text();
  $chapters.append(`
    <li class="navigation-list-item">
      <a href="#${href}" title="${title}">${title}</a>
    </li>
  `);
});

$('pre > .lang-javascript').replaceWith(function (index, content) {
  return desanitize`<script type="text/p5" data-autoplay>${content}</script>`
});

function desanitize([openingTag, closingTag], content) {
  const substitutions = { '&lt;': '<', '&gt;': '>'  };

  for (let [sanitized, unsanitized] of Object.entries(substitutions)) {
    content = content.replace(sanitized, unsanitized);
  }

  return openingTag + content + closingTag;
}

@@ -712,17 +712,16 @@
 or (let 
-%5B
 sanitize
@@ -725,22 +725,8 @@
 ized
-, unsanitized%5D
  of 
@@ -736,14 +736,11 @@
 ect.
-entrie
+key
 s(su
@@ -796,18 +796,30 @@
 itized, 
-un
+substitutions%5B
 sanitize
@@ -819,16 +819,17 @@
 anitized
+%5D
 );%0A  %7D%0A%0A

Fix Object.entries