Is is not possible to force Ckeditor5 to always paste plain text
I reviewed this code:
https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-clipboard/src/pasteplaintext.ts
It looks like the plain text is pasted to editor only if user use 'ctr + shift +v'. How to make it work for 'ctrl +v'? Thre is no easy way to configure it so I report a bug.
Anyway how to work around it?
Hi, did you see the paste as plain text plugin example? This might be a good starting point for your use case.
Hi, I'm facing the same problem as Przemek625. Is there a solution for it ? Thanks.
I also think that plugin should have option to force "paste as plain text' by default.
As part of the create().then().catch() of initialising the plugin, I have added the below which works for me.
This is definitely an interim, rather than a plugin option.
CKEDITOR.ClassicEditor.create(
// your init code here
)
.then( editor => {
editor.editing.view.document.on('clipboardInput', (evt, data) => {
const plainText = data.dataTransfer.getData('text/plain');
// Prevent the default behavior
evt.stop();
// Insert plain text into the editor
editor.model.change(writer => {
const insertPosition = editor.model.document.selection.getFirstPosition();
writer.insertText(plainText, insertPosition);
});
});
}).catch(error => {
console.error(error);
});
I'm trying if the data contains table ,tr,td or figure html then remove this and other formatting should not get removed for example see below:
Problem statement: The limited accessibility for first and last-mile connectivity for transit stations poses a multifaceted problem with significant implications for public transport usage, environmental sustainability, public health, and social equity. Addressing this issue requires a comprehensive and context-sensitive approach that evaluates the current state of infrastructure. Objectives: To develop a context-sensitive accessibility evaluation f_ramework to enhance first- and last-mile connectivity and promote public transport usage, environmental sustainability, public health, and_ social equity.
editor.editing.view.document.on('clipboardInput', (evt, data) => {
// Retrieve plain text and HTML content from the clipboard
const plainText = data.dataTransfer.getData('text/plain');
const htmlContent = data.dataTransfer.getData('text/html');
// Check if the HTML content contains table, figure, or cell-related tags
const containsTableOrFigure = /<(table|fig(ure|caption)|td|th)>/i.test(htmlContent);
if (containsTableOrFigure) {
// Prevent the default behavior
evt.stop();
// Insert plain text into the editor
editor.model.change(writer => {
const insertPosition = editor.model.document.selection.getFirstPosition();
writer.insertText(plainText, insertPosition);
});
}
});