This commit is contained in:
+1
-1
@@ -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": {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user