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.
 
 
 
 
 

108 lines
3.1 KiB

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