Add missing helpers: unescapeHTML and escapeHTML
These helpers are there in the main ConverseJS utils but not in the headless one; unfortunately they are used in some cases (while parsing inline emoji) so not having them causes an error. Ideally we'd patch ConverseJS to include this in the headless version too, but for now as a quick-fix we're just defining everything directly in our converse.js itself.
This commit is contained in:
parent
a5593a22ca
commit
ce3f8254b1
|
@ -34,9 +34,36 @@ import {
|
|||
hexToArrayBuffer,
|
||||
stringToArrayBuffer
|
||||
} from '@converse/headless/utils/arraybuffer.js';
|
||||
import { getHyperlinkTemplate } from '@converse/headless/utils/html.js'
|
||||
|
||||
// Define unescapeHTML since it's needed by a plugin
|
||||
// This function is there in ConverseJS but not included
|
||||
// in the headless version
|
||||
import u from '@converse/headless/utils/core'
|
||||
|
||||
/**
|
||||
* Helper method that replace HTML-escaped symbols with equivalent characters
|
||||
* (e.g. transform occurrences of '&' to '&')
|
||||
* @private
|
||||
* @method u#unescapeHTML
|
||||
* @param { String } string - a String containing the HTML-escaped symbols.
|
||||
*/
|
||||
u.unescapeHTML = function (string) {
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = string;
|
||||
return div.innerText;
|
||||
};
|
||||
|
||||
u.escapeHTML = function (string) {
|
||||
return string
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
};
|
||||
|
||||
|
||||
// Expose converse for debugging
|
||||
// TODO: remove this before release!
|
||||
window.converse = converse;
|
||||
window._converse = _converse;
|
||||
|
||||
|
|
Loading…
Reference in a new issue