/
googledocsnormalizer.js
51 lines (44 loc) · 1.24 KB
/
googledocsnormalizer.js
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
/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module paste-from-office/normalizers/googledocsnormalizer
*/
import removeBoldWrapper from '../filters/removeboldwrapper';
import { unwrapParagraphInListItem } from '../filters/list';
import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
const googleDocsMatch = /id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;
/**
* Normalizer for the content pasted from Google Docs.
*
* @implements module:paste-from-office/normalizer~Normalizer
*/
export default class GoogleDocsNormalizer {
/**
* Creates a new `GoogleDocsNormalizer` instance.
*
* @param {module:engine/view/document~Document} document View document.
*/
constructor( document ) {
/**
* @readonly
* @type {module:engine/view/document~Document}
*/
this.document = document;
}
/**
* @inheritDoc
*/
isActive( htmlString ) {
return googleDocsMatch.test( htmlString );
}
/**
* @inheritDoc
*/
execute( data ) {
const writer = new UpcastWriter( this.document );
removeBoldWrapper( data.content, writer );
unwrapParagraphInListItem( data.content, writer );
}
}