git repos / sago_web_git

static/app.js

browsing at commit = 4fe276c400f51581a3858e55f7b9a48a1f90f419

raw · blame · history

// Client-side rendering: syntax highlighting for source files and markdown
// rendering for READMEs and .md files.
(function () {
  "use strict";

  function highlight() {
    if (typeof hljs === "undefined") return;
    document.querySelectorAll("pre.code > code.hljs").forEach(function (el) {
      hljs.highlightElement(el);
    });
  }

  // Each ".markdown-src" element holds raw markdown and a data-target CSS
  // selector pointing at the element to render it into.
  function renderMarkdown() {
    if (typeof marked === "undefined") return;
    document.querySelectorAll(".markdown-src").forEach(function (src) {
      var target = document.querySelector(src.dataset.target);
      if (target) target.innerHTML = marked.parse(src.textContent);
    });
  }

  document.addEventListener("DOMContentLoaded", function () {
    highlight();
    renderMarkdown();
  });
})();