newLISP-Documentation-Highlight

Provide syntax hightlighting in newLISP documentation

  1. // ==UserScript==
  2. // @name newLISP-Documentation-Highlight
  3. // @namespace https://github.com/kosh04/userscript
  4. // @version 0.20181005
  5. // @description Provide syntax hightlighting in newLISP documentation
  6. // @grant GM_addStyle
  7. // @grant GM_getResourceText
  8. // @match http://www.newlisp.org/*/newlisp_manual.html
  9. // @match http://www.newlisp.org/*/CodePatterns.html
  10. // @match http://newlisp.nfshost.com/*/newlisp_manual.html
  11. // @match http://newlisp.nfshost.com/*/CodePatterns.html
  12. // @require http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js
  13. // @require http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/lisp.min.js
  14. // @resource default.css http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css
  15. // @resource github.css http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css
  16. // @resource zenburn.css http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/zenburn.min.css
  17. // @author KOBAYASHI Shigeru (kosh)
  18. // @license Public domain
  19. // ==/UserScript==
  20.  
  21. /* global hljs */
  22.  
  23. GM_addStyle(GM_getResourceText("default.css"));
  24. GM_addStyle(`
  25. code {
  26. /* font-size: 110%; */
  27. font-family: Consolas, 'Courier New', Courier, Monaco, monospace;
  28. }
  29. .arw {
  30. color: inherit;
  31. }
  32. `);
  33.  
  34. document.querySelectorAll("pre").forEach(pre => {
  35. const code = document.createElement("code");
  36. code.classList.add("lisp"); // assume lang=lisp
  37.  
  38. // wrapInner: <pre>...</pre> => <pre><code>...</code></pre>
  39. code.innerHTML = pre.innerHTML;
  40. pre.innerHTML = code.outerHTML;
  41. });
  42.  
  43. hljs.configure({languages:["lisp", "c", "bash"]});
  44. hljs.initHighlighting();