A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

105 lines
3.0 KiB

  1. <!-- Miscelaneous render related template parts we use multiple times -->
  2. {{define "collection-meta"}}
  3. {{if .Monetization -}}
  4. <meta name="monetization" content="{{.Monetization}}" />
  5. {{- end}}
  6. {{end}}
  7. {{define "highlighting"}}
  8. <script>
  9. // TODO: this feels more like a mutation observer
  10. addEventListener('DOMContentLoaded', function () {
  11. var hlbaseUri = "/js/";
  12. var lb = document.querySelectorAll("code[class^='language-']");
  13. // Custom aliasmap
  14. var aliasmap = {
  15. "elisp" : "lisp",
  16. "emacs-lisp" : "lisp",
  17. "c" : "cpp",
  18. "cc" : "cpp",
  19. "h" : "cpp",
  20. "c++" : "cpp",
  21. "h++" : "cpp",
  22. "hpp" : "cpp",
  23. "hh" : "cpp",
  24. "hxx" : "cpp",
  25. "cxx" : "cpp",
  26. "sh" : "bash",
  27. "js" : "javascript",
  28. "jsx" : "javascript",
  29. "html" : "xml"
  30. };
  31. // Given a set of nodes, run highlighting on them
  32. function highlight(nodes) {
  33. for (i=0; i < nodes.length; i++) {
  34. hljs.highlightBlock(nodes[i]);
  35. }
  36. }
  37. // Given a array of URIs, load them in order
  38. function loadLanguages(uris, callback) {
  39. uris.forEach(function(uri) {
  40. var sc = document.createElement('script');
  41. sc.src = uri;
  42. sc.async = false; // critical?
  43. // Set callback on last script
  44. if (uris.indexOf(uri) == uris.length-1) {
  45. // Set callback regardless
  46. // so we're sure it will run if last element had error
  47. // (we only know after loading, so we've had load time already)
  48. sc.onload = callback; sc.onerror = callback;
  49. }
  50. document.head.appendChild(sc);
  51. });
  52. }
  53. // We don't have to do anything if there are no language blocks
  54. if (lb.length > 0) {
  55. // We have blocks to be highlighted, so we load css
  56. var st = document.createElement('link');
  57. st.rel = "stylesheet";
  58. st.href = "/css/lib/atom-one-light.min.css";
  59. document.head.appendChild(st);
  60. // Construct set of files to load, in order
  61. var jss = [hlbaseUri + "highlight.min.js"];
  62. // Check what we need to load
  63. for (i=0; i < lb.length; i++) {
  64. lang = lb[i].className.replace('language-','');
  65. // Support the aliases specified above
  66. if (aliasmap[lang]) lang = aliasmap[lang];
  67. lurl = hlbaseUri + "highlightjs/" + lang + ".min.js";
  68. if (!jss.includes(lurl)) {
  69. jss.push(lurl);
  70. }
  71. }
  72. // Load files in order, higlight on last load
  73. loadLanguages(jss, () => {highlight(lb)});
  74. }
  75. });
  76. </script>
  77. {{end}}
  78. <!-- Include mathjax configuration -->
  79. {{define "mathjax"}}
  80. <script>
  81. MathJax = {
  82. tex: {
  83. inlineMath: [
  84. ["\\(", "\\)"],
  85. ['$', '$'],
  86. ],
  87. displayMath: [
  88. ['$$', '$$'],
  89. ['\\[', '\\]'],
  90. ],
  91. },
  92. };
  93. </script>
  94. <script type="text/javascript" id="MathJax-script" src="/js/mathjax/tex-svg-full.js" async>
  95. </script>
  96. {{end}}