UNPKG

1.48 kBJavaScriptView Raw
1/**
2 * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5/**
6 * @module paste-from-office/normalizers/googlesheetsnormalizer
7 */
8import { UpcastWriter } from 'ckeditor5/src/engine.js';
9import removeXmlns from '../filters/removexmlns.js';
10import removeGoogleSheetsTag from '../filters/removegooglesheetstag.js';
11import removeInvalidTableWidth from '../filters/removeinvalidtablewidth.js';
12import removeStyleBlock from '../filters/removestyleblock.js';
13const googleSheetsMatch = /<google-sheets-html-origin/i;
14/**
15 * Normalizer for the content pasted from Google Sheets.
16 */
17export default class GoogleSheetsNormalizer {
18 /**
19 * Creates a new `GoogleSheetsNormalizer` instance.
20 *
21 * @param document View document.
22 */
23 constructor(document) {
24 this.document = document;
25 }
26 /**
27 * @inheritDoc
28 */
29 isActive(htmlString) {
30 return googleSheetsMatch.test(htmlString);
31 }
32 /**
33 * @inheritDoc
34 */
35 execute(data) {
36 const writer = new UpcastWriter(this.document);
37 const { body: documentFragment } = data._parsedData;
38 removeGoogleSheetsTag(documentFragment, writer);
39 removeXmlns(documentFragment, writer);
40 removeInvalidTableWidth(documentFragment, writer);
41 removeStyleBlock(documentFragment, writer);
42 data.content = documentFragment;
43 }
44}