From 480ccdbe9c5522247bc696e332c4ecc480b8e964 Mon Sep 17 00:00:00 2001 From: Mark Rapson Date: Wed, 15 Jul 2026 02:38:24 +0100 Subject: [PATCH] Text pasting fix --- package.json | 2 +- src/web/public/js/slide-form.js | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 24e19b8..b8227e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pulse-signage", - "version": "1.1.3", + "version": "1.1.5", "private": false, "description": "Pulse Signage application with MySQL and media uploads", "repository": { diff --git a/src/web/public/js/slide-form.js b/src/web/public/js/slide-form.js index bfefd2d..104568e 100644 --- a/src/web/public/js/slide-form.js +++ b/src/web/public/js/slide-form.js @@ -3,6 +3,7 @@ import { BlockQuote, Bold, ClassicEditor, + ClipboardPipeline, Essentials, FontBackgroundColor, FontColor, @@ -142,6 +143,26 @@ import { } } + class ForcePlainTextPaste extends Plugin { + static get pluginName() { + return 'ForcePlainTextPaste'; + } + + static get requires() { + return [ClipboardPipeline]; + } + + init() { + var editor = this.editor; + var clipboardPipeline = editor.plugins.get(ClipboardPipeline); + + this.listenTo(clipboardPipeline, 'inputTransformation', function (_event, data) { + var plainText = data.dataTransfer.getData('text/plain'); + data.content = editor.data.processor.toView(plainTextToHtml(plainText)); + }, { priority: 'high' }); + } + } + function escapeHtml(value) { return String(value ?? '') .replace(/&/g, '&') @@ -151,6 +172,32 @@ import { .replace(/'/g, '''); } + function plainTextToHtml(value) { + var lines = String(value ?? '').replace(/\r\n?/g, '\n').split('\n'); + var paragraphs = []; + var currentParagraph = []; + + lines.forEach(function (line) { + if (line === '') { + if (currentParagraph.length) { + paragraphs.push('

' + currentParagraph.join('
') + '

'); + currentParagraph = []; + } else { + paragraphs.push('

'); + } + return; + } + + currentParagraph.push(escapeHtml(line)); + }); + + if (currentParagraph.length) { + paragraphs.push('

' + currentParagraph.join('
') + '

'); + } + + return paragraphs.length ? paragraphs.join('') : '

'; + } + function getTemplateById(id) { return templates.find(function (item) { return Number(item.id) === Number(id); }) || null; } @@ -608,6 +655,7 @@ import { BlockQuote, Bold, Essentials, + ForcePlainTextPaste, FontBackgroundColor, FontColor, FontFamily,