From f6d8e6a380c357e5adcbb0f3ca34b619af911f38 Mon Sep 17 00:00:00 2001 From: Simon Grim Date: Tue, 14 Jul 2015 05:55:25 +0500 Subject: [PATCH] text markdown with [link](url) --- js/twister_formatpost.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/js/twister_formatpost.js b/js/twister_formatpost.js index 6aa26b2..254247b 100644 --- a/js/twister_formatpost.js +++ b/js/twister_formatpost.js @@ -373,7 +373,24 @@ function htmlFormatMsg(msg, mentions) { msg = escapeHtmlEntities(msg); for (var i = 0; i < msg.length - 7; i++) { - if (msg.slice(i, i + 4).toLowerCase() === 'http') { + if (msg.slice(i, i + 2) === '](') { + // FIXME there can be text with [] inside [] or links with () wee need to handle it too + j = getStrStart(msg, i - 1, '[', ''); + if (j < i) { + var k = getStrEnd(msg, i + 2, ')', ''); + if (k > i + 1) { + html.push($('#external-page-link-template')[0].outerHTML + .replace(/\bid\s*=\s*"[^]*?"+/ig, '') // $().removeAttr('id') + //.replace(/\bhref\s*=\s*"[^]*?"+/ig, '') // $().removeAttr('href') + .replace(/)[^]*?(<\/a>)/ig, '$1' + msg.slice(j, i) + '$2') // $().closest('a').text(url) + ); + strEncoded = '>' + (html.length - 1).toString() + '<'; + msg = msg.slice(0, j - 1) + strEncoded + msg.slice(k + 2); + i = j + strEncoded.length - 1; + } + } + } else if (msg.slice(i, i + 4).toLowerCase() === 'http') { if (msg.slice(i + 4, i + 7) === '://' && stopCharsRight.indexOf(msg[i + 7]) === -1) { j = getStrEnd(msg, i + 7, stopCharsRight, stopCharsTrailingUrl); if (j > i + 6) {