2
0

Mathjax.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * DEPRECATED
  3. * replaced by markdown-it-mathjax and rendering by PageEditor/Preview component -- 2018.01.30 Yuki Takei
  4. *
  5. export default class Mathjax {
  6. constructor(crowi) {
  7. this.crowi = crowi;
  8. this.defaultUrl = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?skipStartupTypeset=true';
  9. this.mathJaxConfigured = false;
  10. const config = crowi.getConfig();
  11. if (config.env.MATHJAX) {
  12. this.mathJaxConfigured = true;
  13. if (crowi.window.MathJax) {
  14. return ;
  15. }
  16. const document = crowi.document;
  17. const head = document.getElementsByTagName('head')[0];
  18. const mathJaxConfig= document.createElement('script');
  19. mathJaxConfig.type = 'text/x-mathjax-config';
  20. mathJaxConfig.text = `MathJax.Hub.Config({
  21. extensions: ["tex2jax.js"],
  22. jax: ["input/TeX", "output/SVG"],
  23. tex2jax: {
  24. inlineMath: [ ['$','$'] ],
  25. displayMath: [ ['$$','$$'] ],
  26. processEscapes: true
  27. },
  28. showMathMenu: false,
  29. showMathMenuMSIE: false,
  30. showProcessingMessages: false,
  31. messageStyle: "none",
  32. skipStartupTypeset: true
  33. });`;
  34. head.appendChild(mathJaxConfig);
  35. const script = document.createElement('script');
  36. script.type = 'text/javascript';
  37. script.src = this.defaultUrl;
  38. head.appendChild(script);
  39. }
  40. this.process = this.process.bind(this);
  41. }
  42. process(html, dom) {
  43. if (!this.mathJaxConfigured) {
  44. return html;
  45. }
  46. const intervalId = setInterval(() => {
  47. if (this.crowi.window.MathJax) {
  48. const MathJax = this.crowi.window.MathJax;
  49. MathJax.Hub.Queue(["Typeset", MathJax.Hub, dom.id]);
  50. clearInterval(intervalId);
  51. }
  52. }, 100);
  53. return html;
  54. }
  55. }
  56. */