1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { transformListItemLikeElementsIntoLists } from '../filters/list.js';
|
9 | import { replaceImagesSourceWithBase64 } from '../filters/image.js';
|
10 | import removeMSAttributes from '../filters/removemsattributes.js';
|
11 | const msWordMatch1 = /<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i;
|
12 | const msWordMatch2 = /xmlns:o="urn:schemas-microsoft-com/i;
|
13 |
|
14 |
|
15 |
|
16 | export default class MSWordNormalizer {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 | constructor(document, hasMultiLevelListPlugin = false) {
|
23 | this.document = document;
|
24 | this.hasMultiLevelListPlugin = hasMultiLevelListPlugin;
|
25 | }
|
26 | |
27 |
|
28 |
|
29 | isActive(htmlString) {
|
30 | return msWordMatch1.test(htmlString) || msWordMatch2.test(htmlString);
|
31 | }
|
32 | |
33 |
|
34 |
|
35 | execute(data) {
|
36 | const { body: documentFragment, stylesString } = data._parsedData;
|
37 | transformListItemLikeElementsIntoLists(documentFragment, stylesString, this.hasMultiLevelListPlugin);
|
38 | replaceImagesSourceWithBase64(documentFragment, data.dataTransfer.getData('text/rtf'));
|
39 | removeMSAttributes(documentFragment);
|
40 | data.content = documentFragment;
|
41 | }
|
42 | }
|