From f4d2092f4a3c99360d233a1bb0b71fac272b63ab Mon Sep 17 00:00:00 2001 From: ppoffice Date: Mon, 5 Jun 2017 22:08:21 +0800 Subject: [PATCH] fix(search): html entity does not display correctly in insight search items --- source/js/insight.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/js/insight.js b/source/js/insight.js index 5a9d6b1..53aa889 100644 --- a/source/js/insight.js +++ b/source/js/insight.js @@ -10,6 +10,13 @@ $main.parent().remove('.ins-search'); $('body').append($main); + // https://stackoverflow.com/questions/1147359/how-to-decode-html-entities-using-jquery#answer-1395954 + function decodeEntities(encodedString) { + var textArea = document.createElement('textarea'); + textArea.innerHTML = encodedString; + return textArea.value; + } + function section (title) { return $('
').addClass('ins-section') .append($('
').addClass('ins-section-header').text(title)); @@ -19,7 +26,7 @@ return $('
').addClass('ins-selectable').addClass('ins-search-item') .append($('
').append($('').addClass('fa').addClass('fa-' + icon)).append(title != null && title != '' ? title : CONFIG.TRANSLATION['UNTITLED']) .append(slug ? $('').addClass('ins-slug').text(slug) : null)) - .append(preview ? $('

').addClass('ins-search-preview').text(preview) : null) + .append(preview ? $('

').addClass('ins-search-preview').text(decodeEntities(preview)) : null) .attr('data-url', url); }