@ckeditor/ckeditor5-paste-from-office 35.4.0 → 36.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/build/paste-from-office.js +2 -2
- package/package.json +28 -24
- package/src/filters/br.js +51 -63
- package/src/filters/image.js +216 -197
- package/src/filters/list.js +359 -429
- package/src/filters/parse.js +76 -106
- package/src/filters/removeboldwrapper.js +10 -17
- package/src/filters/space.js +37 -39
- package/src/index.js +1 -3
- package/src/normalizer.js +5 -0
- package/src/normalizers/googledocsnormalizer.js +26 -41
- package/src/normalizers/mswordnormalizer.js +24 -38
- package/src/pastefromoffice.js +41 -62
- package/src/normalizer.jsdoc +0 -34
package/src/filters/parse.js
CHANGED
|
@@ -1,123 +1,93 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paste-from-office/filters/parse
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/* globals DOMParser */
|
|
11
|
-
|
|
12
9
|
import { DomConverter, ViewDocument } from 'ckeditor5/src/engine';
|
|
13
|
-
|
|
14
10
|
import { normalizeSpacing, normalizeSpacerunSpans } from './space';
|
|
15
|
-
|
|
16
11
|
/**
|
|
17
12
|
* Parses provided HTML extracting contents of `<body>` and `<style>` tags.
|
|
18
13
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor
|
|
21
|
-
* @returns {Object} result
|
|
22
|
-
* @returns {module:engine/view/documentfragment~DocumentFragment} result.body Parsed body
|
|
23
|
-
* content as a traversable structure.
|
|
24
|
-
* @returns {String} result.bodyString Entire body content as a string.
|
|
25
|
-
* @returns {Array.<CSSStyleSheet>} result.styles Array of native `CSSStyleSheet` objects, each representing
|
|
26
|
-
* separate `style` tag from the source HTML.
|
|
27
|
-
* @returns {String} result.stylesString All `style` tags contents combined in the order of occurrence into one string.
|
|
14
|
+
* @param htmlString HTML string to be parsed.
|
|
28
15
|
*/
|
|
29
|
-
export function parseHtml(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const stylesObject = extractStyles( htmlDocument );
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
body: bodyView,
|
|
53
|
-
bodyString,
|
|
54
|
-
styles: stylesObject.styles,
|
|
55
|
-
stylesString: stylesObject.stylesString
|
|
56
|
-
};
|
|
16
|
+
export function parseHtml(htmlString, stylesProcessor) {
|
|
17
|
+
const domParser = new DOMParser();
|
|
18
|
+
// Remove Word specific "if comments" so content inside is not omitted by the parser.
|
|
19
|
+
htmlString = htmlString.replace(/<!--\[if gte vml 1]>/g, '');
|
|
20
|
+
const normalizedHtml = normalizeSpacing(cleanContentAfterBody(htmlString));
|
|
21
|
+
// Parse htmlString as native Document object.
|
|
22
|
+
const htmlDocument = domParser.parseFromString(normalizedHtml, 'text/html');
|
|
23
|
+
normalizeSpacerunSpans(htmlDocument);
|
|
24
|
+
// Get `innerHTML` first as transforming to View modifies the source document.
|
|
25
|
+
const bodyString = htmlDocument.body.innerHTML;
|
|
26
|
+
// Transform document.body to View.
|
|
27
|
+
const bodyView = documentToView(htmlDocument, stylesProcessor);
|
|
28
|
+
// Extract stylesheets.
|
|
29
|
+
const stylesObject = extractStyles(htmlDocument);
|
|
30
|
+
return {
|
|
31
|
+
body: bodyView,
|
|
32
|
+
bodyString,
|
|
33
|
+
styles: stylesObject.styles,
|
|
34
|
+
stylesString: stylesObject.stylesString
|
|
35
|
+
};
|
|
57
36
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return domConverter.domToView( fragment, { skipComments: true } );
|
|
37
|
+
/**
|
|
38
|
+
* Transforms native `Document` object into {@link module:engine/view/documentfragment~DocumentFragment}. Comments are skipped.
|
|
39
|
+
*
|
|
40
|
+
* @param htmlDocument Native `Document` object to be transformed.
|
|
41
|
+
*/
|
|
42
|
+
function documentToView(htmlDocument, stylesProcessor) {
|
|
43
|
+
const viewDocument = new ViewDocument(stylesProcessor);
|
|
44
|
+
const domConverter = new DomConverter(viewDocument, { renderingMode: 'data' });
|
|
45
|
+
const fragment = htmlDocument.createDocumentFragment();
|
|
46
|
+
const nodes = htmlDocument.body.childNodes;
|
|
47
|
+
while (nodes.length > 0) {
|
|
48
|
+
fragment.appendChild(nodes[0]);
|
|
49
|
+
}
|
|
50
|
+
return domConverter.domToView(fragment, { skipComments: true });
|
|
75
51
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
styles,
|
|
98
|
-
stylesString: stylesString.join( ' ' )
|
|
99
|
-
};
|
|
52
|
+
/**
|
|
53
|
+
* Extracts both `CSSStyleSheet` and string representation from all `style` elements available in a provided `htmlDocument`.
|
|
54
|
+
*
|
|
55
|
+
* @param htmlDocument Native `Document` object from which styles will be extracted.
|
|
56
|
+
*/
|
|
57
|
+
function extractStyles(htmlDocument) {
|
|
58
|
+
const styles = [];
|
|
59
|
+
const stylesString = [];
|
|
60
|
+
const styleTags = Array.from(htmlDocument.getElementsByTagName('style'));
|
|
61
|
+
for (const style of styleTags) {
|
|
62
|
+
if (style.sheet && style.sheet.cssRules && style.sheet.cssRules.length) {
|
|
63
|
+
styles.push(style.sheet);
|
|
64
|
+
stylesString.push(style.innerHTML);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
styles,
|
|
69
|
+
stylesString: stylesString.join(' ')
|
|
70
|
+
};
|
|
100
71
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
( htmlCloseIndex >= 0 ? htmlString.substring( htmlCloseIndex ) : '' );
|
|
72
|
+
/**
|
|
73
|
+
* Removes leftover content from between closing </body> and closing </html> tag:
|
|
74
|
+
*
|
|
75
|
+
* ```html
|
|
76
|
+
* <html><body><p>Foo Bar</p></body><span>Fo</span></html> -> <html><body><p>Foo Bar</p></body></html>
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* This function is used as specific browsers (Edge) add some random content after `body` tag when pasting from Word.
|
|
80
|
+
* @param htmlString The HTML string to be cleaned.
|
|
81
|
+
* @returns The HTML string with leftover content removed.
|
|
82
|
+
*/
|
|
83
|
+
function cleanContentAfterBody(htmlString) {
|
|
84
|
+
const bodyCloseTag = '</body>';
|
|
85
|
+
const htmlCloseTag = '</html>';
|
|
86
|
+
const bodyCloseIndex = htmlString.indexOf(bodyCloseTag);
|
|
87
|
+
if (bodyCloseIndex < 0) {
|
|
88
|
+
return htmlString;
|
|
89
|
+
}
|
|
90
|
+
const htmlCloseIndex = htmlString.indexOf(htmlCloseTag, bodyCloseIndex + bodyCloseTag.length);
|
|
91
|
+
return htmlString.substring(0, bodyCloseIndex + bodyCloseTag.length) +
|
|
92
|
+
(htmlCloseIndex >= 0 ? htmlString.substring(htmlCloseIndex) : '');
|
|
123
93
|
}
|
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @module paste-from-office/filters/removeboldwrapper
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
5
|
/**
|
|
11
6
|
* Removes `<b>` tag wrapper added by Google Docs to a copied content.
|
|
12
7
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param {module:engine/view/upcastwriter~UpcastWriter} writer
|
|
8
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
15
9
|
*/
|
|
16
|
-
export default function removeBoldWrapper(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
10
|
+
export default function removeBoldWrapper(documentFragment, writer) {
|
|
11
|
+
for (const child of documentFragment.getChildren()) {
|
|
12
|
+
if (child.is('element', 'b') && child.getStyle('font-weight') === 'normal') {
|
|
13
|
+
const childIndex = documentFragment.getChildIndex(child);
|
|
14
|
+
writer.remove(child);
|
|
15
|
+
writer.insertChild(childIndex, child.getChildren(), documentFragment);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
25
18
|
}
|
package/src/filters/space.js
CHANGED
|
@@ -1,61 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paste-from-office/filters/space
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Replaces last space preceding elements closing tag with ` `. Such operation prevents spaces from being removed
|
|
12
10
|
* during further DOM/View processing (see especially {@link module:engine/view/domconverter~DomConverter#_processDataFromDomText}).
|
|
13
11
|
* This method also takes into account Word specific `<o:p></o:p>` empty tags.
|
|
14
12
|
* Additionally multiline sequences of spaces and new lines between tags are removed (see #39 and #40).
|
|
15
13
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @returns
|
|
14
|
+
* @param htmlString HTML string in which spacing should be normalized.
|
|
15
|
+
* @returns Input HTML with spaces normalized.
|
|
18
16
|
*/
|
|
19
|
-
export function normalizeSpacing(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
export function normalizeSpacing(htmlString) {
|
|
18
|
+
// Run normalizeSafariSpaceSpans() two times to cover nested spans.
|
|
19
|
+
return normalizeSafariSpaceSpans(normalizeSafariSpaceSpans(htmlString))
|
|
20
|
+
// Remove all \r\n from "spacerun spans" so the last replace line doesn't strip all whitespaces.
|
|
21
|
+
.replace(/(<span\s+style=['"]mso-spacerun:yes['"]>[^\S\r\n]*?)[\r\n]+([^\S\r\n]*<\/span>)/g, '$1$2')
|
|
22
|
+
.replace(/<span\s+style=['"]mso-spacerun:yes['"]><\/span>/g, '')
|
|
23
|
+
.replace(/ <\//g, '\u00A0</')
|
|
24
|
+
.replace(/ <o:p><\/o:p>/g, '\u00A0<o:p></o:p>')
|
|
25
|
+
// Remove <o:p> block filler from empty paragraph. Safari uses \u00A0 instead of .
|
|
26
|
+
.replace(/<o:p>( |\u00A0)<\/o:p>/g, '')
|
|
27
|
+
// Remove all whitespaces when they contain any \r or \n.
|
|
28
|
+
.replace(/>([^\S\r\n]*[\r\n]\s*)</g, '><');
|
|
31
29
|
}
|
|
32
|
-
|
|
33
30
|
/**
|
|
34
31
|
* Normalizes spacing in special Word `spacerun spans` (`<span style='mso-spacerun:yes'>\s+</span>`) by replacing
|
|
35
32
|
* all spaces with ` ` pairs. This prevents spaces from being removed during further DOM/View processing
|
|
36
33
|
* (see especially {@link module:engine/view/domconverter~DomConverter#_processDataFromDomText}).
|
|
37
34
|
*
|
|
38
|
-
* @param
|
|
35
|
+
* @param htmlDocument Native `Document` object in which spacing should be normalized.
|
|
39
36
|
*/
|
|
40
|
-
export function normalizeSpacerunSpans(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
export function normalizeSpacerunSpans(htmlDocument) {
|
|
38
|
+
htmlDocument.querySelectorAll('span[style*=spacerun]').forEach(el => {
|
|
39
|
+
const htmlElement = el;
|
|
40
|
+
const innerTextLength = htmlElement.innerText.length || 0;
|
|
41
|
+
htmlElement.innerText = Array(innerTextLength + 1).join('\u00A0 ').substr(0, innerTextLength);
|
|
42
|
+
});
|
|
46
43
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Normalizes specific spacing generated by Safari when content pasted from Word (`<span class="Apple-converted-space"> </span>`)
|
|
46
|
+
* by replacing all spaces sequences longer than 1 space with ` ` pairs. This prevents spaces from being removed during
|
|
47
|
+
* further DOM/View processing (see especially {@link module:engine/view/domconverter~DomConverter#_processDataFromDomText}).
|
|
48
|
+
*
|
|
49
|
+
* This function is similar to {@link module:clipboard/utils/normalizeclipboarddata normalizeClipboardData util} but uses
|
|
50
|
+
* regular spaces / sequence for replacement.
|
|
51
|
+
*
|
|
52
|
+
* @param htmlString HTML string in which spacing should be normalized
|
|
53
|
+
* @returns Input HTML with spaces normalized.
|
|
54
|
+
*/
|
|
55
|
+
function normalizeSafariSpaceSpans(htmlString) {
|
|
56
|
+
return htmlString.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g, (fullMatch, spaces) => {
|
|
57
|
+
return spaces.length === 1 ? ' ' : Array(spaces.length + 1).join('\u00A0 ').substr(0, spaces.length);
|
|
58
|
+
});
|
|
61
59
|
}
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paste-from-office
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
export { default as PasteFromOffice } from './pastefromoffice';
|
|
@@ -1,57 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paste-from-office/normalizers/googledocsnormalizer
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { UpcastWriter } from 'ckeditor5/src/engine';
|
|
11
|
-
|
|
12
9
|
import removeBoldWrapper from '../filters/removeboldwrapper';
|
|
13
10
|
import transformBlockBrsToParagraphs from '../filters/br';
|
|
14
11
|
import { unwrapParagraphInListItem } from '../filters/list';
|
|
15
|
-
|
|
16
12
|
const googleDocsMatch = /id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;
|
|
17
|
-
|
|
18
13
|
/**
|
|
19
14
|
* Normalizer for the content pasted from Google Docs.
|
|
20
|
-
*
|
|
21
|
-
* @implements module:paste-from-office/normalizer~Normalizer
|
|
22
15
|
*/
|
|
23
16
|
export default class GoogleDocsNormalizer {
|
|
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
|
-
const { body: documentFragment } = data._parsedData;
|
|
50
|
-
|
|
51
|
-
removeBoldWrapper( documentFragment, writer );
|
|
52
|
-
unwrapParagraphInListItem( documentFragment, writer );
|
|
53
|
-
transformBlockBrsToParagraphs( documentFragment, writer );
|
|
54
|
-
|
|
55
|
-
data.content = documentFragment;
|
|
56
|
-
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new `GoogleDocsNormalizer` instance.
|
|
19
|
+
*
|
|
20
|
+
* @param document View document.
|
|
21
|
+
*/
|
|
22
|
+
constructor(document) {
|
|
23
|
+
this.document = document;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
isActive(htmlString) {
|
|
29
|
+
return googleDocsMatch.test(htmlString);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
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
|
+
}
|
|
57
42
|
}
|
|
@@ -1,53 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module paste-from-office/normalizers/mswordnormalizer
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { transformListItemLikeElementsIntoLists } from '../filters/list';
|
|
11
9
|
import { replaceImagesSourceWithBase64 } from '../filters/image';
|
|
12
|
-
|
|
13
10
|
const msWordMatch1 = /<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i;
|
|
14
11
|
const msWordMatch2 = /xmlns:o="urn:schemas-microsoft-com/i;
|
|
15
|
-
|
|
16
12
|
/**
|
|
17
13
|
* Normalizer for the content pasted from Microsoft Word.
|
|
18
|
-
*
|
|
19
|
-
* @implements module:paste-from-office/normalizer~Normalizer
|
|
20
14
|
*/
|
|
21
15
|
export default class MSWordNormalizer {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
execute( data ) {
|
|
46
|
-
const { body: documentFragment, stylesString } = data._parsedData;
|
|
47
|
-
|
|
48
|
-
transformListItemLikeElementsIntoLists( documentFragment, stylesString );
|
|
49
|
-
replaceImagesSourceWithBase64( documentFragment, data.dataTransfer.getData( 'text/rtf' ) );
|
|
50
|
-
|
|
51
|
-
data.content = documentFragment;
|
|
52
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new `MSWordNormalizer` instance.
|
|
18
|
+
*
|
|
19
|
+
* @param document View document.
|
|
20
|
+
*/
|
|
21
|
+
constructor(document) {
|
|
22
|
+
this.document = document;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
isActive(htmlString) {
|
|
28
|
+
return msWordMatch1.test(htmlString) || msWordMatch2.test(htmlString);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
execute(data) {
|
|
34
|
+
const { body: documentFragment, stylesString } = data._parsedData;
|
|
35
|
+
transformListItemLikeElementsIntoLists(documentFragment, stylesString);
|
|
36
|
+
replaceImagesSourceWithBase64(documentFragment, data.dataTransfer.getData('text/rtf'));
|
|
37
|
+
data.content = documentFragment;
|
|
38
|
+
}
|
|
53
39
|
}
|