Skip to content

Commit

Permalink
Merge pull request #8459 from RocketChat/improvements/md-autolinker-d…
Browse files Browse the repository at this point in the history
…isable-option

[NEW] Setting to disable MarkDown and enable AutoLinker
  • Loading branch information
rodrigok committed Oct 11, 2017
1 parent 47afc0b commit 941051c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/rocketchat-autolinker/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import Autolinker from 'autolinker';

function AutoLinker(message) {
if (RocketChat.settings.get('AutoLinker') !== true) {
return message;
}

if (_.trim(message.html)) {
const regUrls = new RegExp(RocketChat.settings.get('AutoLinker_UrlsRegExp'));

Expand Down
21 changes: 14 additions & 7 deletions packages/rocketchat-autolinker/server/settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
Meteor.startup(function() {
RocketChat.settings.add('AutoLinker_StripPrefix', false, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, i18nDescription: 'AutoLinker_StripPrefix_Description'});
RocketChat.settings.add('AutoLinker_Urls_Scheme', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true});
RocketChat.settings.add('AutoLinker_Urls_www', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true});
RocketChat.settings.add('AutoLinker_Urls_TLD', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true});
RocketChat.settings.add('AutoLinker_UrlsRegExp', '(://|www\\.).+', {type: 'string', group: 'Message', section: 'AutoLinker', public: true});
RocketChat.settings.add('AutoLinker_Email', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true});
RocketChat.settings.add('AutoLinker_Phone', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, i18nDescription: 'AutoLinker_Phone_Description'});
const enableQuery = {
_id: 'AutoLinker',
value: true
};

RocketChat.settings.add('AutoLinker', false, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, i18nLabel: 'Enabled'});

RocketChat.settings.add('AutoLinker_StripPrefix', false, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, i18nDescription: 'AutoLinker_StripPrefix_Description', enableQuery});
RocketChat.settings.add('AutoLinker_Urls_Scheme', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, enableQuery});
RocketChat.settings.add('AutoLinker_Urls_www', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, enableQuery});
RocketChat.settings.add('AutoLinker_Urls_TLD', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, enableQuery});
RocketChat.settings.add('AutoLinker_UrlsRegExp', '(://|www\\.).+', {type: 'string', group: 'Message', section: 'AutoLinker', public: true, enableQuery});
RocketChat.settings.add('AutoLinker_Email', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, enableQuery});
RocketChat.settings.add('AutoLinker_Phone', true, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, i18nDescription: 'AutoLinker_Phone_Description', enableQuery});
});
5 changes: 5 additions & 0 deletions packages/rocketchat-markdown/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class MarkdownClass {

parseMessageNotEscaped(message) {
const parser = RocketChat.settings.get('Markdown_Parser');

if (parser === 'disabled') {
return message;
}

if (typeof parsers[parser] === 'function') {
return parsers[parser](message);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-markdown/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Meteor.startup(() => {
RocketChat.settings.add('Markdown_Parser', 'original', {
type: 'select',
values: [{
key: 'disabled',
i18nLabel: 'Disabled'
}, {
key: 'original',
i18nLabel: 'Original'
}, {
Expand Down
6 changes: 3 additions & 3 deletions packages/rocketchat-ui-message/client/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const markdownButtons = [
icon: 'italic',
pattern: '_{{text}}_',
command: 'i',
condition: () => RocketChat.Markdown
condition: () => RocketChat.Markdown && RocketChat.settings.get('Markdown_Parser') !== 'disabled'
},
{
label: 'strike',
Expand All @@ -115,13 +115,13 @@ const markdownButtons = [
label: 'inline_code',
icon: 'code',
pattern: '`{{text}}`',
condition: () => RocketChat.Markdown
condition: () => RocketChat.Markdown && RocketChat.settings.get('Markdown_Parser') !== 'disabled'
},
{
label: 'multi_line',
icon: 'multi-line',
pattern: '```\n{{text}}\n``` ',
condition: () => RocketChat.Markdown
condition: () => RocketChat.Markdown && RocketChat.settings.get('Markdown_Parser') !== 'disabled'
},
{
label: katexSyntax,
Expand Down

0 comments on commit 941051c

Please sign in to comment.