From cf7488ddd6b0c788683a8ae122cdfb5ede41beee Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 21 Dec 2015 16:15:36 +0000 Subject: [PATCH] Fixed simple markdown parser Closes #1009 --- app/js/lib/ng_utils.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/js/lib/ng_utils.js b/app/js/lib/ng_utils.js index 3493efd1..f1cf9717 100644 --- a/app/js/lib/ng_utils.js +++ b/app/js/lib/ng_utils.js @@ -1178,7 +1178,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\.,:?!;]|$)|(^|\s)`([^\n]+?)`([\s\.,:?!;]|$)/; + var markdownRegExp = /(^|\s)(````?)([\s\S]+?)(````?)([\s\n\.,:?!;]|$)|(^|\s)`([^\n]+?)`([\s\.,:?!;]|$)/; var siteHashtags = { Telegram: '#/im?q=%23{1}', @@ -1340,11 +1340,19 @@ angular.module('izhukov.utils', []) matchIndex = rawOffset + match.index; newText.push(raw.substr(0, match.index)); - var text = (match[3] || match[7]).replace(/^\s+|\s+$/g, ''); + var text = (match[3] || match[7]); + rawOffset -= text.length; + text = text.replace(/^\s+|\s+$/g, ''); + rawOffset += text.length; + if (text.match(/^`*$/)) { newText.push(match[0]); } else if (match[3]) { // pre + if (match[5] == "\n") { + match[5] = ''; + rawOffset -= 1; + } newText.push(match[1] + text + match[5]); entities.push({ _: 'messageEntityPre',