diff options
Diffstat (limited to 'js/App.js')
| -rw-r--r-- | js/App.js | 59 |
1 files changed, 29 insertions, 30 deletions
@@ -411,40 +411,39 @@ const App = { }, // htmlspecialchars()-alike for headlines data-content attribute escapeHtml: function(p) { - if (typeof p == "string") { - const map = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; + if (typeof p !== 'string') + return p; - return p.replace(/[&<>"']/g, function(m) { return map[m]; }); - } else { + const map = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''', + '/': '/', + }; + + return p.replace(/[&<>"'\/]/g, m => map[m]); + }, + unescapeHtml: function(p) { + if (typeof p !== 'string' || p.indexOf('&') === -1) return p; - } + + return p.replace(/&(?:amp|lt|gt|quot|#x27|#x2F|#039|#47);/g, function(entity) { + switch (entity) { + case '&': return '&'; + case '<': return '<'; + case '>': return '>'; + case '"': return '"'; + case ''': case ''': return "'"; + case '/': case '/': return '/'; + default: return entity; + } + }); }, - // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac getSelectedText: function() { - let text = ""; - - if (typeof window.getSelection != "undefined") { - const sel = window.getSelection(); - if (sel.rangeCount) { - const container = document.createElement("div"); - for (let i = 0, len = sel.rangeCount; i < len; ++i) { - container.appendChild(sel.getRangeAt(i).cloneContents()); - } - text = container.innerHTML; - } - } else if (typeof document.selection != "undefined") { - if (document.selection.type == "Text") { - text = document.selection.createRange().textText; - } - } - - return text.stripTags(); + const sel = window.getSelection(); + return sel ? sel.toString().trim() : ""; }, displayIfChecked: function(checkbox, elemId) { if (checkbox.checked) { |