Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AutoLinker issues #2808

Merged
merged 4 commits into from Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ [email protected]
kadira:[email protected]
kadira:[email protected]
kenton:[email protected]
konecty:[email protected]
konecty:[email protected]
konecty:[email protected]
konecty:[email protected]
Expand Down
29 changes: 20 additions & 9 deletions packages/rocketchat-autolinker/autolinker.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@
class AutoLinker
constructor: (message) ->
if _.trim message.html
regUrls = new RegExp(RocketChat.settings.get 'AutoLinker_UrlsRegExp')

autolinker = new Autolinker
stripPrefix: RocketChat.settings.get 'AutoLinker_StripPrefix'
urls: RocketChat.settings.get 'AutoLinker_Urls'
email: RocketChat.settings.get 'AutoLinker_Email'
phone: RocketChat.settings.get 'AutoLinker_Phone'
twitter: false
replaceFn: (autolinker, match) ->
if match.getType() is 'url'
return regUrls.test match.matchedText
return null

regNonAutoLink = /(```\w*[\n ]?[\s\S]*?```+?)|(`(?:[^`]+)`)/
if RocketChat.settings.get 'Katex_Enabled'
regNonAutoLink = /(```\w*[\n ]?[\s\S]*?```+?)|(`(?:[^`]+)`)|(\\\(\w*[\n ]?[\s\S]*?\\\)+?)/

# Separate text in code blocks and non code blocks
msgParts = message.html.split /(```\w*[\n ]?[\s\S]*?```+?)|(`(?:[^`]+)`)/
msgParts = message.html.split regNonAutoLink

for part, index in msgParts
if part?.length? > 0
# Verify if this part is code
codeMatch = part.match /(?:```(\w*)[\n ]?([\s\S]*?)```+?)|(?:`(?:[^`]+)`)/
codeMatch = part.match regNonAutoLink
if not codeMatch?
msgParts[index] = Autolinker.link part,
stripPrefix: false
twitter: false
replaceFn: (autolinker, match) ->
if match.getType() is 'url'
return /(:\/\/|www\.).+/.test match.matchedText
return true
msgParts[index] = autolinker.link part

# Re-mount message
message.html = msgParts.join('')
Expand Down
10 changes: 10 additions & 0 deletions packages/rocketchat-autolinker/lib/Autolinker.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions packages/rocketchat-autolinker/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ Package.onUse(function(api) {

api.use([
'coffeescript',
'konecty:autolinker',
'rocketchat:lib'
]);

api.addFiles('autolinker.coffee', ['server','client']);
api.addFiles([
'autolinker.coffee',
'lib/Autolinker.min.js',
], ['client']);

api.addFiles('settings.coffee', ['server']);
});
6 changes: 6 additions & 0 deletions packages/rocketchat-autolinker/settings.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Meteor.startup ->
RocketChat.settings.add 'AutoLinker_StripPrefix', false, {type: 'boolean', group: 'Message', section: 'AutoLinker', public: true, i18nDescription: 'AutoLinker_StripPrefix_Description'}
RocketChat.settings.add 'AutoLinker_Urls', 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'}
7 changes: 7 additions & 0 deletions packages/rocketchat-lib/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@
"Are_you_sure_you_want_to_delete_your_account" : "Are you sure you want to delete your account?",
"Authorization_URL" : "Authorization URL",
"Authorize" : "Authorize",
"AutoLinker_StripPrefix": "AutoLinker Strip Prefix",
"AutoLinker_StripPrefix_Description": "Short display. e.g. https://rocket.chat => rocket.chat",
"AutoLinker_Urls": "AutoLinker URL",
"AutoLinker_UrlsRegExp": "AutoLinker URL Regular Expression",
"AutoLinker_Email": "AutoLinker Email",
"AutoLinker_Phone": "AutoLinker Phone",
"AutoLinker_Phone_Description": "Automatically linked for Phone numbers. e.g. `(123)456-7890`",
"Auto_Load_Images" : "Auto Load Images",
"Available_agents" : "Available agents",
"Avatar" : "Avatar",
Expand Down
9 changes: 8 additions & 1 deletion packages/rocketchat-lib/i18n/ja.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@
"Are_you_sure_you_want_to_delete_your_account" : "本当にアカウントを削除しますか?",
"Authorization_URL" : "認証 URL",
"Authorize" : "承認",
"AutoLinker_StripPrefix": "AutoLinker 先頭部分を表示しない",
"AutoLinker_StripPrefix_Description": "短い表示。例: https://rocket.chat => rocket.chat",
"AutoLinker_Urls": "AutoLinker URL",
"AutoLinker_UrlsRegExp": "AutoLinker URL 正規表現",
"AutoLinker_Email": "AutoLinker Email",
"AutoLinker_Phone": "AutoLinker 電話番号",
"AutoLinker_Phone_Description": "電話番号をリンクにする。例: `(123)456-7890`",
"Auto_Load_Images" : "画像自動読み込み",
"Available_agents" : "割り当てられる担当者",
"Avatar" : "アバター",
Expand Down Expand Up @@ -1013,4 +1020,4 @@
"Your_Open_Source_solution" : "独自のオープンソースチャットソリューション",
"Your_password_is_wrong" : "パスワードが間違っています!",
"Your_push_was_sent_to_s_devices" : "プッシュ通知が %s 台のデバイスへ送信されました"
}
}