Merge pull request #6212 from tsiegleauq/clean-html-on-motion-paste

Clean HTML before pasting in tinymce
This commit is contained in:
GabrielInTheWorld 2021-08-20 08:30:59 +02:00 committed by GitHub
commit 70d5b32bd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,7 +67,8 @@ export abstract class BaseComponent {
plugins: ['autosave', 'lists', 'autolink']
},
relative_urls: false,
remove_script_host: true
remove_script_host: true,
paste_preprocess: this.pastePreprocess
};
public constructor(protected titleService: Title, protected translate: TranslateService) {
@ -75,6 +76,29 @@ export abstract class BaseComponent {
this.tinyMceSettings.language = this.translate.currentLang;
}
/**
* Clean pasted HTML.
* If the user decides to copy-paste HTML (like from another OpenSlides motion detail)
* - remove all classes
* - remove data-line-number="X"
* - remove contenteditable="false"
*
* Not doing so would save control sequences from diff/linenumbering into the
* model which will open pandoras pox during PDF generation (and potentially web view)
* @param _
* @param args
*/
private pastePreprocess(_: any, args: any): void {
const getClassesRe: RegExp = new RegExp(/\s*class\=\"[\w\W]*?\"/, 'gi');
const getDataLineNumberRe: RegExp = new RegExp(/\s*data-line-number\=\"\d+\"/, 'gi');
const getContentEditableRe: RegExp = new RegExp(/\s*contenteditable\=\"\w+\"/, 'gi');
const cleanedContent = (args.content as string)
.replace(getClassesRe, '')
.replace(getDataLineNumberRe, '')
.replace(getContentEditableRe, '');
args.content = cleanedContent;
}
/**
* Set the title in web browser using angulars TitleService
* @param prefix The title prefix. Should be translated here.