From e9f790b8ea2f992442987116d079542124109c8b Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 6 Oct 2015 16:38:20 +0300 Subject: [PATCH] Improved markdown --- app/js/lib/ng_utils.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/js/lib/ng_utils.js b/app/js/lib/ng_utils.js index 80f13d4b..40fd51e2 100644 --- a/app/js/lib/ng_utils.js +++ b/app/js/lib/ng_utils.js @@ -1146,7 +1146,7 @@ angular.module('izhukov.utils', []) 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 markdownRegExp = /(^|\s)```([\s\S]+?)```|(^|\s)`([^\n]+?)`/; + var markdownRegExp = /(^|\s)(````?)([\s\S]+?)(````?)|(^|\s)`([^\n]+?)`/; var siteHashtags = { Telegram: '#/im?q=%23{1}', @@ -1325,21 +1325,21 @@ angular.module('izhukov.utils', []) matchIndex = rawOffset + match.index; newText.push(raw.substr(0, match.index)); - if (match[2]) { // pre - newText.push(match[1] + match[2]); + if (match[3]) { // pre + newText.push(match[1] + match[3]); entities.push({ _: 'messageEntityPre', language: '', offset: matchIndex + match[1].length, - length: match[2].length + length: match[3].length }); - rawOffset -= 6; + rawOffset -= match[2].length + match[4].length; } else { // code - newText.push(match[3] + match[4]); + newText.push(match[5] + match[6]); entities.push({ _: 'messageEntityCode', - offset: matchIndex + match[3].length, - length: match[4].length + offset: matchIndex + match[5].length, + length: match[6].length }); rawOffset -= 2; }