|
|
@ -1238,7 +1238,7 @@ angular.module('izhukov.utils', []) |
|
|
|
var soundcloudRegExp = /^https?:\/\/(?:soundcloud\.com|snd\.sc)\/([a-zA-Z0-9%\-\_]+)\/([a-zA-Z0-9%\-\_]+)/i |
|
|
|
var soundcloudRegExp = /^https?:\/\/(?:soundcloud\.com|snd\.sc)\/([a-zA-Z0-9%\-\_]+)\/([a-zA-Z0-9%\-\_]+)/i |
|
|
|
var spotifyRegExp = /(https?:\/\/(open\.spotify\.com|play\.spotify\.com|spoti\.fi)\/(.+)|spotify:(.+))/i |
|
|
|
var spotifyRegExp = /(https?:\/\/(open\.spotify\.com|play\.spotify\.com|spoti\.fi)\/(.+)|spotify:(.+))/i |
|
|
|
|
|
|
|
|
|
|
|
var markdownRegExp = /(^|\s)(````?)([\s\S]+?)(````?)([\s\n\.,:?!;]|$)|(^|\s)`([^\n]+?)`([\s\.,:?!;]|$)|@(\d+)\s*\((.+?)\)/ |
|
|
|
var markdownRegExp = /(^|\s)(````?)([\s\S]+?)(````?)([\s\n\.,:?!;]|$)|(^|\s)([`*_])([^\n]+?)\7([\s\.,:?!;]|$)|@(\d+)\s*\((.+?)\)/ |
|
|
|
|
|
|
|
|
|
|
|
var siteHashtags = { |
|
|
|
var siteHashtags = { |
|
|
|
Telegram: 'tg://search_hashtag?hashtag={1}', |
|
|
|
Telegram: 'tg://search_hashtag?hashtag={1}', |
|
|
@ -1254,6 +1254,12 @@ angular.module('izhukov.utils', []) |
|
|
|
GitHub: 'https://github.com/{1}' |
|
|
|
GitHub: 'https://github.com/{1}' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var markdownEntities = { |
|
|
|
|
|
|
|
'`': 'messageEntityCode', |
|
|
|
|
|
|
|
'*': 'messageEntityBold', |
|
|
|
|
|
|
|
'_': 'messageEntityItalic' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
wrapRichText: wrapRichText, |
|
|
|
wrapRichText: wrapRichText, |
|
|
|
wrapPlainText: wrapPlainText, |
|
|
|
wrapPlainText: wrapPlainText, |
|
|
@ -1402,7 +1408,7 @@ angular.module('izhukov.utils', []) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function parseMarkdown (text, entities, noTrim) { |
|
|
|
function parseMarkdown (text, entities, noTrim) { |
|
|
|
if (text.indexOf('`') == -1 && text.indexOf('@') == -1) { |
|
|
|
if (!text.test(/[`_*@]/)) { |
|
|
|
return noTrim ? text : text.trim() |
|
|
|
return noTrim ? text : text.trim() |
|
|
|
} |
|
|
|
} |
|
|
|
var raw = text |
|
|
|
var raw = text |
|
|
@ -1414,7 +1420,7 @@ angular.module('izhukov.utils', []) |
|
|
|
matchIndex = rawOffset + match.index |
|
|
|
matchIndex = rawOffset + match.index |
|
|
|
newText.push(raw.substr(0, match.index)) |
|
|
|
newText.push(raw.substr(0, match.index)) |
|
|
|
|
|
|
|
|
|
|
|
var text = (match[3] || match[7] || match[10]) |
|
|
|
var text = (match[3] || match[8] || match[11]) |
|
|
|
rawOffset -= text.length |
|
|
|
rawOffset -= text.length |
|
|
|
text = text.replace(/^\s+|\s+$/g, '') |
|
|
|
text = text.replace(/^\s+|\s+$/g, '') |
|
|
|
rawOffset += text.length |
|
|
|
rawOffset += text.length |
|
|
@ -1435,23 +1441,23 @@ angular.module('izhukov.utils', []) |
|
|
|
length: text.length |
|
|
|
length: text.length |
|
|
|
}) |
|
|
|
}) |
|
|
|
rawOffset -= match[2].length + match[4].length |
|
|
|
rawOffset -= match[2].length + match[4].length |
|
|
|
} else if (match[7]) { // code
|
|
|
|
} else if (match[9]) { // code
|
|
|
|
newText.push(match[6] + text + match[8]) |
|
|
|
newText.push(match[6] + text + match[9]) |
|
|
|
entities.push({ |
|
|
|
entities.push({ |
|
|
|
_: 'messageEntityCode', |
|
|
|
_: markdownEntities[match[7]], |
|
|
|
offset: matchIndex + match[6].length, |
|
|
|
offset: matchIndex + match[6].length, |
|
|
|
length: text.length |
|
|
|
length: text.length |
|
|
|
}) |
|
|
|
}) |
|
|
|
rawOffset -= 2 |
|
|
|
rawOffset -= 2 |
|
|
|
} else if (match[10]) { // custom mention
|
|
|
|
} else if (match[11]) { // custom mention
|
|
|
|
newText.push(text) |
|
|
|
newText.push(text) |
|
|
|
entities.push({ |
|
|
|
entities.push({ |
|
|
|
_: 'messageEntityMentionName', |
|
|
|
_: 'messageEntityMentionName', |
|
|
|
user_id: match[9], |
|
|
|
user_id: match[10], |
|
|
|
offset: matchIndex, |
|
|
|
offset: matchIndex, |
|
|
|
length: text.length |
|
|
|
length: text.length |
|
|
|
}) |
|
|
|
}) |
|
|
|
rawOffset -= match[0] - text.length |
|
|
|
rawOffset -= match[0].length - text.length |
|
|
|
} |
|
|
|
} |
|
|
|
raw = raw.substr(match.index + match[0].length) |
|
|
|
raw = raw.substr(match.index + match[0].length) |
|
|
|
rawOffset += match.index + match[0].length |
|
|
|
rawOffset += match.index + match[0].length |
|
|
@ -1808,6 +1814,18 @@ angular.module('izhukov.utils', []) |
|
|
|
) |
|
|
|
) |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageEntityBold': |
|
|
|
|
|
|
|
code.push( |
|
|
|
|
|
|
|
'*', entityText, '*' |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageEntityItalic': |
|
|
|
|
|
|
|
code.push( |
|
|
|
|
|
|
|
'_', entityText, '_' |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
case 'messageEntityPre': |
|
|
|
case 'messageEntityPre': |
|
|
|
code.push( |
|
|
|
code.push( |
|
|
|
'```', entityText, '```' |
|
|
|
'```', entityText, '```' |
|
|
|