-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
googlesheetsnormalizer.ts
56 lines (46 loc) · 1.58 KB
/
googlesheetsnormalizer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module paste-from-office/normalizers/googlesheetsnormalizer
*/
import { UpcastWriter, type ViewDocument } from 'ckeditor5/src/engine.js';
import removeXmlns from '../filters/removexmlns.js';
import removeGoogleSheetsTag from '../filters/removegooglesheetstag.js';
import removeInvalidTableWidth from '../filters/removeinvalidtablewidth.js';
import removeStyleBlock from '../filters/removestyleblock.js';
import type { Normalizer, NormalizerData } from '../normalizer.js';
const googleSheetsMatch = /<google-sheets-html-origin/i;
/**
* Normalizer for the content pasted from Google Sheets.
*/
export default class GoogleSheetsNormalizer implements Normalizer {
public readonly document: ViewDocument;
/**
* Creates a new `GoogleSheetsNormalizer` instance.
*
* @param document View document.
*/
constructor( document: ViewDocument ) {
this.document = document;
}
/**
* @inheritDoc
*/
public isActive( htmlString: string ): boolean {
return googleSheetsMatch.test( htmlString );
}
/**
* @inheritDoc
*/
public execute( data: NormalizerData ): void {
const writer = new UpcastWriter( this.document );
const { body: documentFragment } = data._parsedData;
removeGoogleSheetsTag( documentFragment, writer );
removeXmlns( documentFragment, writer );
removeInvalidTableWidth( documentFragment, writer );
removeStyleBlock( documentFragment, writer );
data.content = documentFragment;
}
}