preserve newlines in study practice comments - closes #2655

pull/2661/head
Thibault Duplessis 2017-02-12 11:53:14 +01:00
parent 3dbfc8f398
commit 19fb848490
2 changed files with 8 additions and 4 deletions

View File

@ -1,6 +1,7 @@
var m = require('mithril');
var classSet = require('common').classSet;
var plural = require('../../util').plural;
var renderComment = require('../studyComments').embedYoutube;
var firstRender = true;
@ -78,7 +79,7 @@ module.exports = {
default:
return m('div.feedback.ongoing', [
m('div.goal', renderGoal(p, p.goal().moves - p.nbMoves())),
p.comment() ? m('div.comment', p.comment()) : null
p.comment() ? m('div.comment', renderComment(p.comment(), true)) : null
]);
}
},

View File

@ -1,5 +1,6 @@
var m = require('mithril');
var nodeFullName = require('../util').nodeFullName;
var renderComment = require('./studyComments').embedYoutube;
function authorDom(author) {
if (!author) return 'Unknown';
@ -17,12 +18,14 @@ function authorText(author) {
var commentYoutubeRegex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch)?(?:\?v=)?(?:[^"&?\/ ]{11})\S*/gi;
function embedYoutube(text) {
return m.trust(lichess.escapeHtml(text).replace(commentYoutubeRegex, function(found) {
function embedYoutube(text, allowNewlines) {
var html = lichess.escapeHtml(text).replace(commentYoutubeRegex, function(found) {
var url = lichess.toYouTubeEmbedUrl(found);
if (!url) return found;
return '<iframe width="100%" height="300" src="' + url + '" frameborder=0 allowfullscreen></iframe>';
}));
});
if (allowNewlines) html = html.replace(/\n/g, '<br>');
return m.trust(html);
}
module.exports = {