diff options
author | Joas Schilling <coding@schilljs.com> | 2017-01-17 11:11:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-17 11:11:16 +0100 |
commit | aea1b72f54d72331b8ea3b4e9cd4338ffbfe8ee9 (patch) | |
tree | d363ec4d37d33e14ab29c445fbfd6a7efd4741b3 /settings/js | |
parent | 012708e1badebe5dab6260c2e9edb521d5dbfee0 (diff) | |
parent | 6ba7ba6e0c7109b82c44316b1cdb181c1d37dbc7 (diff) | |
download | nextcloud-server-aea1b72f54d72331b8ea3b4e9cd4338ffbfe8ee9.tar.gz nextcloud-server-aea1b72f54d72331b8ea3b4e9cd4338ffbfe8ee9.zip |
Merge pull request #1594 from nextcloud/markdown-support-for-app-descriptions
Markdown support for app descriptions
Diffstat (limited to 'settings/js')
-rw-r--r-- | settings/js/apps.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/settings/js/apps.js b/settings/js/apps.js index 61d817e43e4..1538e71a491 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -19,6 +19,8 @@ Handlebars.registerHelper('level', function() { OC.Settings = OC.Settings || {}; OC.Settings.Apps = OC.Settings.Apps || { + markedOptions: {}, + setupGroupsSelect: function($elements) { OC.Settings.setupGroupsSelect($elements, { placeholder: t('core', 'All') @@ -186,6 +188,25 @@ OC.Settings.Apps = OC.Settings.Apps || { app.author = app.author['@value']; } + // Parse markdown in app description + app.description = DOMPurify.sanitize( + marked(app.description.trim(), OC.Settings.Apps.markedOptions), + { + SAFE_FOR_JQUERY: true, + ALLOWED_TAGS: [ + 'strong', + 'p', + 'a', + 'ul', + 'ol', + 'li', + 'em', + 'del', + 'blockquote' + ] + } + ); + var html = template(app); if (selector) { selector.html(html); @@ -633,6 +654,50 @@ OC.Settings.Apps = OC.Settings.Apps || { * Initializes the apps list */ initialize: function($el) { + + var renderer = new marked.Renderer(); + renderer.link = function(href, title, text) { + try { + var prot = decodeURIComponent(unescape(href)) + .replace(/[^\w:]/g, '') + .toLowerCase(); + } catch (e) { + return ''; + } + + if (prot.indexOf('http:') !== 0 && prot.indexOf('https:') !== 0) { + return ''; + } + + var out = '<a href="' + href + '" rel="noreferrer noopener"'; + if (title) { + out += ' title="' + title + '"'; + } + out += '>' + text + '</a>'; + return out; + }; + renderer.image = function(href, title, text) { + if (text) { + return text; + } + return title; + }; + renderer.blockquote = function(quote) { + return quote; + }; + + OC.Settings.Apps.markedOptions = { + renderer: renderer, + gfm: false, + highlight: false, + tables: false, + breaks: false, + pedantic: false, + sanitize: true, + smartLists: true, + smartypants: false + }; + OC.Plugins.register('OCA.Search', OC.Settings.Apps.Search); OC.Settings.Apps.loadCategories(); OC.Util.History.addOnPopStateHandler(_.bind(this._onPopState, this)); |