template-integration.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import DOMPurify from 'dompurify';
  2. var Markdown = require('markdown-it')({
  3. html: true,
  4. linkify: true,
  5. typographer: true,
  6. breaks: true,
  7. });
  8. import markdownItMermaid from "@wekanteam/markdown-it-mermaid";
  9. // Static URL Scheme Listing
  10. var urlschemes = [
  11. "aodroplink",
  12. "thunderlink",
  13. "cbthunderlink",
  14. "onenote",
  15. "file",
  16. "abasurl",
  17. "conisio",
  18. "mailspring"
  19. ];
  20. // Better would be a field in the admin backend to set this dynamically
  21. // instead of putting all known or wanted url schemes here hard into code
  22. // but i was not able to access those settings
  23. // var urlschemes = currentSetting.automaticLinkedUrlSchemes.split('\n');
  24. // put all url schemes into the linkify configuration to automatically make it clickable
  25. for(var i=0; i<urlschemes.length;i++){
  26. Markdown.linkify.add(urlschemes[i]+":",'http:');
  27. }
  28. var emoji = require('markdown-it-emoji');
  29. var mathjax = require('markdown-it-mathjax3');
  30. Markdown.use(emoji);
  31. Markdown.use(mathjax);
  32. // Try to fix Mermaid Diagram error: Maximum call stack size exceeded.
  33. // Added bigger text size for Diagram.
  34. // https://github.com/wekan/wekan/issues/4251
  35. // https://stackoverflow.com/questions/66825888/maximum-text-size-in-diagram-exceeded-mermaid-js
  36. // https://github.com/mermaid-js/mermaid/blob/74b1219d62dd76d98d60abeeb36d4520f64faceb/src/defaultConfig.js#L39
  37. // https://github.com/wekan/cli-table3
  38. // https://www.npmjs.com/package/@wekanteam/markdown-it-mermaid
  39. // https://github.com/wekan/markdown-it-mermaid
  40. Markdown.use(markdownItMermaid,{
  41. maxTextSize: 100000,
  42. });
  43. if (Package.ui) {
  44. const Template = Package.templating.Template;
  45. const UI = Package.ui.UI;
  46. const HTML = Package.htmljs.HTML;
  47. const Blaze = Package.blaze.Blaze; // implied by `ui`
  48. UI.registerHelper('markdown', new Template('markdown', function () {
  49. const self = this;
  50. let text = '';
  51. if (self.templateContentBlock) {
  52. text = Blaze._toText(self.templateContentBlock, HTML.TEXTMODE.STRING);
  53. }
  54. return HTML.Raw(DOMPurify.sanitize(Markdown.render(text), {ALLOW_UNKNOWN_PROTOCOLS: true}));
  55. }));
  56. }