template-integration.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. Markdown.use(emoji);
  30. Markdown.use(markdownItMermaid);
  31. if (Package.ui) {
  32. const Template = Package.templating.Template;
  33. const UI = Package.ui.UI;
  34. const HTML = Package.htmljs.HTML;
  35. const Blaze = Package.blaze.Blaze; // implied by `ui`
  36. UI.registerHelper('markdown', new Template('markdown', function () {
  37. const self = this;
  38. let text = '';
  39. if (self.templateContentBlock) {
  40. text = Blaze._toText(self.templateContentBlock, HTML.TEXTMODE.STRING);
  41. }
  42. return HTML.Raw(DOMPurify.sanitize(Markdown.render(text), {ALLOW_UNKNOWN_PROTOCOLS: true}));
  43. }));
  44. }