1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { UpcastWriter } from 'ckeditor5/src/engine.js';
|
9 | import removeBoldWrapper from '../filters/removeboldwrapper.js';
|
10 | import transformBlockBrsToParagraphs from '../filters/br.js';
|
11 | import { unwrapParagraphInListItem } from '../filters/list.js';
|
12 | const googleDocsMatch = /id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;
|
13 |
|
14 |
|
15 |
|
16 | export default class GoogleDocsNormalizer {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 | constructor(document) {
|
23 | this.document = document;
|
24 | }
|
25 | |
26 |
|
27 |
|
28 | isActive(htmlString) {
|
29 | return googleDocsMatch.test(htmlString);
|
30 | }
|
31 | |
32 |
|
33 |
|
34 | execute(data) {
|
35 | const writer = new UpcastWriter(this.document);
|
36 | const { body: documentFragment } = data._parsedData;
|
37 | removeBoldWrapper(documentFragment, writer);
|
38 | unwrapParagraphInListItem(documentFragment, writer);
|
39 | transformBlockBrsToParagraphs(documentFragment, writer);
|
40 | data.content = documentFragment;
|
41 | }
|
42 | }
|