Merge pull request #10158 from sebastianberm/sebastianberm-patch-chatplayback

Fix newlines in playback of chat
This commit is contained in:
Anton Georgiev 2020-08-25 11:28:02 -04:00 committed by GitHub
commit b1e73281e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -58,7 +58,7 @@
i++;
contentDiv.innerHTML = "<strong>" + options.name + ":</strong>" + options.message;
contentDiv.innerHTML = "<strong>" + options.name + ":</strong>" + nl2br(options.message);
//If chat message contains a link, we add to it a target attribute
//So when the user clicks on it, it opens in a new tab

View File

@ -130,6 +130,43 @@ function replaceTimeOnURL(secs) {
window.history.replaceState({}, "", newUrl);
};
/*
* From: https://locutus.io/php/strings/nl2br/
*/
function nl2br (str, isXhtml) {
// discuss at: https://locutus.io/php/nl2br/
// original by: Kevin van Zonneveld (https://kvz.io)
// improved by: Philip Peterson
// improved by: Onno Marsman (https://twitter.com/onnomarsman)
// improved by: Atli Þór
// improved by: Brett Zamir (https://brett-zamir.me)
// improved by: Maximusya
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
// bugfixed by: Kevin van Zonneveld (https://kvz.io)
// bugfixed by: Reynier de la Rosa (https://scriptinside.blogspot.com.es/)
// input by: Brett Zamir (https://brett-zamir.me)
// example 1: nl2br('Kevin\nvan\nZonneveld')
// returns 1: 'Kevin<br />\nvan<br />\nZonneveld'
// example 2: nl2br("\nOne\nTwo\n\nThree\n", false)
// returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
// example 3: nl2br("\nOne\nTwo\n\nThree\n", true)
// returns 3: '<br />\nOne<br />\nTwo<br />\n<br />\nThree<br />\n'
// example 4: nl2br(null)
// returns 4: ''
// Some latest browsers when str is null return and unexpected null value
if (typeof str === 'undefined' || str === null) {
return ''
}
// Adjust comment to avoid issue on locutus.io display
var breakTag = (isXhtml || typeof isXhtml === 'undefined') ? '<br ' + '/>' : '<br>'
return (str + '')
.replace(/(\r\n|\n\r|\r|\n)/g, breakTag + '$1')
}
/*
* Sets the title attribute in a thumbnail.
*/