Format slide texts in WhatsApp style
CI / Deploy / test (push) Successful in 1m9s
CI / Deploy / deploy (push) Skipped

Slide descriptions support *bold*, _italic_, ~strikethrough~ and lists
with "- " or "* " at the start of a line. FormatHelper renders them for
the participant page and the PDF (escaping everything else), Format in
plenario.js builds the same DOM for presenter and embed. Participant
input stays plain text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 14:23:10 +01:00
1 parent 3465f69bfc
commit 8d3d8d4341
12 files changed
+215 -8

No files matched your search

+47 -1
View File
@@ -42,6 +42,52 @@
return node;
}
/**
* Light formatting of slide texts in WhatsApp style, same rules as App\View\Helper\FormatHelper:
* *bold*, _italic_, ~strikethrough~, lists with "- " or "* " at the start of a line.
* Builds DOM nodes (text via textContent), never HTML strings.
*/
var Format = {
INLINE: /(^|[^\p{L}\p{N}])([*_~])(\S|\S[^\n]*?\S)\2(?=$|[^\p{L}\p{N}])/u,
LIST_ITEM: /^\s*[-*•]\s+(.*)$/u,
TAGS: { '*': 'strong', '_': 'em', '~': 's' },
render: function (container, text) {
container.textContent = '';
var lines = String(text || '').trim().split(/\r\n|\r|\n/);
var list = null;
var lineBefore = false;
lines.forEach(function (line) {
var item = Format.LIST_ITEM.exec(line);
if (item) {
if (!list) {
list = container.appendChild(el('ul'));
}
list.appendChild(el('li', {}, Format.inline(item[1])));
lineBefore = false;
return;
}
if (lineBefore) {
container.appendChild(el('br'));
}
list = null;
Format.inline(line).forEach(function (node) { container.appendChild(node); });
lineBefore = true;
});
},
inline: function (text) {
var m = Format.INLINE.exec(text);
if (!m) {
return text ? [document.createTextNode(text)] : [];
}
var before = text.slice(0, m.index) + m[1];
return (before ? [document.createTextNode(before)] : [])
.concat([el(Format.TAGS[m[2]], {}, Format.inline(m[3]))])
.concat(Format.inline(text.slice(m.index + m[0].length)));
}
};
function csrfToken() {
var meta = document.querySelector('meta[name="csrf-token"]');
return meta ? meta.getAttribute('content') : '';
@@ -1294,7 +1340,7 @@
: (qaStage ? Qa.labels[qaStage]
: (orderRevealed ? 'Auflösung' : (closed ? 'Abstimmung geschlossen' : '')));
q('[data-question]').textContent = slide.question;
q('[data-description]').textContent = slide.description;
Format.render(q('[data-description]'), slide.description);
root.classList.toggle('stage--content', !slide.isInteractive);
root.classList.toggle('stage--video', slide.type === 'youtube');
renderMedia(slide);