Text pasting fix
Publish Docker Image / build-and-push (push) Successful in 24s

This commit is contained in:
2026-07-15 02:38:24 +01:00
parent 8020a12408
commit 480ccdbe9c
2 changed files with 49 additions and 1 deletions
+1 -1
View File
@@ -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": {
+48
View File
@@ -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('<p>' + currentParagraph.join('<br />') + '</p>');
currentParagraph = [];
} else {
paragraphs.push('<p></p>');
}
return;
}
currentParagraph.push(escapeHtml(line));
});
if (currentParagraph.length) {
paragraphs.push('<p>' + currentParagraph.join('<br />') + '</p>');
}
return paragraphs.length ? paragraphs.join('') : '<p></p>';
}
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,