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.

68 lines
2.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_preview_markdown.PreviewHandler', function (require) {
  20. "use strict";
  21. var ajax = require('web.ajax');
  22. var core = require('web.core');
  23. var PreviewHandler = require('muk_preview.PreviewHandler');
  24. var QWeb = core.qweb;
  25. var _t = core._t;
  26. var MarkdownHandler = PreviewHandler.BaseHandler.extend({
  27. cssLibs: [
  28. ],
  29. jsLibs: [
  30. '/muk_web_preview_markdown/static/lib/showdown/showdown.js',
  31. ],
  32. checkExtension: function(extension) {
  33. return ['.md', 'md'].includes(extension);
  34. },
  35. checkType: function(mimetype) {
  36. return ['text/markdown'].includes(mimetype);
  37. },
  38. createHtml: function(url, mimetype, extension, title) {
  39. var result = $.Deferred();
  40. var $content = $(QWeb.render('MarkdownHTMLContent'));
  41. ajax.loadLibs(this).then(function() {
  42. $.ajax(url, {
  43. dataType: "text",
  44. success: function(text) {
  45. $content.find('.markdown-loader').hide();
  46. $content.find('.markdown-container').show();
  47. $content.find('.markdown-container').html(
  48. new showdown.Converter().makeHtml(text));
  49. },
  50. error: function(request, status, error) {
  51. console.error(request.responseText);
  52. }
  53. });
  54. });
  55. result.resolve($content);
  56. return result;
  57. },
  58. });
  59. return {
  60. MarkdownHandler: MarkdownHandler,
  61. }
  62. });