@ckeditor/ckeditor5-paste-from-office 39.0.2 → 40.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/build/paste-from-office.js.map +1 -0
- package/package.json +2 -2
- package/src/augmentation.d.ts +10 -10
- package/src/augmentation.js +5 -5
- package/src/filters/br.d.ts +14 -14
- package/src/filters/br.js +65 -65
- package/src/filters/image.d.ts +24 -24
- package/src/filters/image.js +241 -241
- package/src/filters/list.d.ts +26 -26
- package/src/filters/list.js +395 -395
- package/src/filters/parse.d.ts +35 -35
- package/src/filters/parse.js +93 -93
- package/src/filters/removeboldwrapper.d.ts +14 -14
- package/src/filters/removeboldwrapper.js +18 -18
- package/src/filters/removegooglesheetstag.d.ts +14 -14
- package/src/filters/removegooglesheetstag.js +18 -18
- package/src/filters/removeinvalidtablewidth.d.ts +14 -14
- package/src/filters/removeinvalidtablewidth.js +16 -16
- package/src/filters/removestyleblock.d.ts +14 -14
- package/src/filters/removestyleblock.js +16 -16
- package/src/filters/removexmlns.d.ts +14 -14
- package/src/filters/removexmlns.js +16 -16
- package/src/filters/space.d.ts +25 -25
- package/src/filters/space.js +60 -60
- package/src/index.d.ts +12 -12
- package/src/index.js +11 -11
- package/src/normalizer.d.ts +30 -30
- package/src/normalizer.js +5 -5
- package/src/normalizers/googledocsnormalizer.d.ts +29 -29
- package/src/normalizers/googledocsnormalizer.js +42 -42
- package/src/normalizers/googlesheetsnormalizer.d.ts +29 -29
- package/src/normalizers/googlesheetsnormalizer.js +44 -44
- package/src/normalizers/mswordnormalizer.d.ts +26 -26
- package/src/normalizers/mswordnormalizer.js +39 -39
- package/src/pastefromoffice.d.ts +36 -36
- package/src/pastefromoffice.js +70 -70
package/src/filters/parse.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/filters/parse
|
|
7
|
-
*/
|
|
8
|
-
import { type StylesProcessor, type ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* Parses the provided HTML extracting contents of `<body>` and `<style>` tags.
|
|
11
|
-
*
|
|
12
|
-
* @param htmlString HTML string to be parsed.
|
|
13
|
-
*/
|
|
14
|
-
export declare function parseHtml(htmlString: string, stylesProcessor: StylesProcessor): ParseHtmlResult;
|
|
15
|
-
/**
|
|
16
|
-
* The result of {@link ~parseHtml}.
|
|
17
|
-
*/
|
|
18
|
-
export interface ParseHtmlResult {
|
|
19
|
-
/**
|
|
20
|
-
* Parsed body content as a traversable structure.
|
|
21
|
-
*/
|
|
22
|
-
body: ViewDocumentFragment;
|
|
23
|
-
/**
|
|
24
|
-
* Entire body content as a string.
|
|
25
|
-
*/
|
|
26
|
-
bodyString: string;
|
|
27
|
-
/**
|
|
28
|
-
* Array of native `CSSStyleSheet` objects, each representing separate `style` tag from the source HTML.
|
|
29
|
-
*/
|
|
30
|
-
styles: Array<CSSStyleSheet>;
|
|
31
|
-
/**
|
|
32
|
-
* All `style` tags contents combined in the order of occurrence into one string.
|
|
33
|
-
*/
|
|
34
|
-
stylesString: string;
|
|
35
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/filters/parse
|
|
7
|
+
*/
|
|
8
|
+
import { type StylesProcessor, type ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* Parses the provided HTML extracting contents of `<body>` and `<style>` tags.
|
|
11
|
+
*
|
|
12
|
+
* @param htmlString HTML string to be parsed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseHtml(htmlString: string, stylesProcessor: StylesProcessor): ParseHtmlResult;
|
|
15
|
+
/**
|
|
16
|
+
* The result of {@link ~parseHtml}.
|
|
17
|
+
*/
|
|
18
|
+
export interface ParseHtmlResult {
|
|
19
|
+
/**
|
|
20
|
+
* Parsed body content as a traversable structure.
|
|
21
|
+
*/
|
|
22
|
+
body: ViewDocumentFragment;
|
|
23
|
+
/**
|
|
24
|
+
* Entire body content as a string.
|
|
25
|
+
*/
|
|
26
|
+
bodyString: string;
|
|
27
|
+
/**
|
|
28
|
+
* Array of native `CSSStyleSheet` objects, each representing separate `style` tag from the source HTML.
|
|
29
|
+
*/
|
|
30
|
+
styles: Array<CSSStyleSheet>;
|
|
31
|
+
/**
|
|
32
|
+
* All `style` tags contents combined in the order of occurrence into one string.
|
|
33
|
+
*/
|
|
34
|
+
stylesString: string;
|
|
35
|
+
}
|
package/src/filters/parse.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/filters/parse
|
|
7
|
-
*/
|
|
8
|
-
/* globals DOMParser */
|
|
9
|
-
import { DomConverter, ViewDocument } from 'ckeditor5/src/engine';
|
|
10
|
-
import { normalizeSpacing, normalizeSpacerunSpans } from './space';
|
|
11
|
-
/**
|
|
12
|
-
* Parses the provided HTML extracting contents of `<body>` and `<style>` tags.
|
|
13
|
-
*
|
|
14
|
-
* @param htmlString HTML string to be parsed.
|
|
15
|
-
*/
|
|
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
|
-
};
|
|
36
|
-
}
|
|
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 });
|
|
51
|
-
}
|
|
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
|
-
};
|
|
71
|
-
}
|
|
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) : '');
|
|
93
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/filters/parse
|
|
7
|
+
*/
|
|
8
|
+
/* globals DOMParser */
|
|
9
|
+
import { DomConverter, ViewDocument } from 'ckeditor5/src/engine';
|
|
10
|
+
import { normalizeSpacing, normalizeSpacerunSpans } from './space';
|
|
11
|
+
/**
|
|
12
|
+
* Parses the provided HTML extracting contents of `<body>` and `<style>` tags.
|
|
13
|
+
*
|
|
14
|
+
* @param htmlString HTML string to be parsed.
|
|
15
|
+
*/
|
|
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
|
+
};
|
|
36
|
+
}
|
|
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 });
|
|
51
|
+
}
|
|
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
|
+
};
|
|
71
|
+
}
|
|
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) : '');
|
|
93
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/filters/removeboldwrapper
|
|
7
|
-
*/
|
|
8
|
-
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* Removes the `<b>` tag wrapper added by Google Docs to a copied content.
|
|
11
|
-
*
|
|
12
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
-
*/
|
|
14
|
-
export default function removeBoldWrapper(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/filters/removeboldwrapper
|
|
7
|
+
*/
|
|
8
|
+
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* Removes the `<b>` tag wrapper added by Google Docs to a copied content.
|
|
11
|
+
*
|
|
12
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
*/
|
|
14
|
+
export default function removeBoldWrapper(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* Removes the `<b>` tag wrapper added by Google Docs to a copied content.
|
|
7
|
-
*
|
|
8
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
-
*/
|
|
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
|
-
}
|
|
18
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* Removes the `<b>` tag wrapper added by Google Docs to a copied content.
|
|
7
|
+
*
|
|
8
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
*/
|
|
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
|
+
}
|
|
18
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/filters/removegooglesheetstag
|
|
7
|
-
*/
|
|
8
|
-
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* Removes the `<google-sheets-html-origin>` tag wrapper added by Google Sheets to a copied content.
|
|
11
|
-
*
|
|
12
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
-
*/
|
|
14
|
-
export default function removeGoogleSheetsTag(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/filters/removegooglesheetstag
|
|
7
|
+
*/
|
|
8
|
+
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* Removes the `<google-sheets-html-origin>` tag wrapper added by Google Sheets to a copied content.
|
|
11
|
+
*
|
|
12
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
*/
|
|
14
|
+
export default function removeGoogleSheetsTag(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* Removes the `<google-sheets-html-origin>` tag wrapper added by Google Sheets to a copied content.
|
|
7
|
-
*
|
|
8
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
-
*/
|
|
10
|
-
export default function removeGoogleSheetsTag(documentFragment, writer) {
|
|
11
|
-
for (const child of documentFragment.getChildren()) {
|
|
12
|
-
if (child.is('element', 'google-sheets-html-origin')) {
|
|
13
|
-
const childIndex = documentFragment.getChildIndex(child);
|
|
14
|
-
writer.remove(child);
|
|
15
|
-
writer.insertChild(childIndex, child.getChildren(), documentFragment);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* Removes the `<google-sheets-html-origin>` tag wrapper added by Google Sheets to a copied content.
|
|
7
|
+
*
|
|
8
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
*/
|
|
10
|
+
export default function removeGoogleSheetsTag(documentFragment, writer) {
|
|
11
|
+
for (const child of documentFragment.getChildren()) {
|
|
12
|
+
if (child.is('element', 'google-sheets-html-origin')) {
|
|
13
|
+
const childIndex = documentFragment.getChildIndex(child);
|
|
14
|
+
writer.remove(child);
|
|
15
|
+
writer.insertChild(childIndex, child.getChildren(), documentFragment);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/filters/removeinvalidtablewidth
|
|
7
|
-
*/
|
|
8
|
-
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* Removes the `width:0px` style from table pasted from Google Sheets.
|
|
11
|
-
*
|
|
12
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
-
*/
|
|
14
|
-
export default function removeInvalidTableWidth(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/filters/removeinvalidtablewidth
|
|
7
|
+
*/
|
|
8
|
+
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* Removes the `width:0px` style from table pasted from Google Sheets.
|
|
11
|
+
*
|
|
12
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
*/
|
|
14
|
+
export default function removeInvalidTableWidth(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* Removes the `width:0px` style from table pasted from Google Sheets.
|
|
7
|
-
*
|
|
8
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
-
*/
|
|
10
|
-
export default function removeInvalidTableWidth(documentFragment, writer) {
|
|
11
|
-
for (const child of documentFragment.getChildren()) {
|
|
12
|
-
if (child.is('element', 'table') && child.getStyle('width') === '0px') {
|
|
13
|
-
writer.removeStyle('width', child);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* Removes the `width:0px` style from table pasted from Google Sheets.
|
|
7
|
+
*
|
|
8
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
*/
|
|
10
|
+
export default function removeInvalidTableWidth(documentFragment, writer) {
|
|
11
|
+
for (const child of documentFragment.getChildren()) {
|
|
12
|
+
if (child.is('element', 'table') && child.getStyle('width') === '0px') {
|
|
13
|
+
writer.removeStyle('width', child);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/filters/removestyleblock
|
|
7
|
-
*/
|
|
8
|
-
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* Removes `<style>` block added by Google Sheets to a copied content.
|
|
11
|
-
*
|
|
12
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
-
*/
|
|
14
|
-
export default function removeStyleBlock(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/filters/removestyleblock
|
|
7
|
+
*/
|
|
8
|
+
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* Removes `<style>` block added by Google Sheets to a copied content.
|
|
11
|
+
*
|
|
12
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
*/
|
|
14
|
+
export default function removeStyleBlock(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* Removes `<style>` block added by Google Sheets to a copied content.
|
|
7
|
-
*
|
|
8
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
-
*/
|
|
10
|
-
export default function removeStyleBlock(documentFragment, writer) {
|
|
11
|
-
for (const child of Array.from(documentFragment.getChildren())) {
|
|
12
|
-
if (child.is('element', 'style')) {
|
|
13
|
-
writer.remove(child);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* Removes `<style>` block added by Google Sheets to a copied content.
|
|
7
|
+
*
|
|
8
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
*/
|
|
10
|
+
export default function removeStyleBlock(documentFragment, writer) {
|
|
11
|
+
for (const child of Array.from(documentFragment.getChildren())) {
|
|
12
|
+
if (child.is('element', 'style')) {
|
|
13
|
+
writer.remove(child);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/filters/removexmlns
|
|
7
|
-
*/
|
|
8
|
-
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* Removes the `xmlns` attribute from table pasted from Google Sheets.
|
|
11
|
-
*
|
|
12
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
-
*/
|
|
14
|
-
export default function removeXmlns(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/filters/removexmlns
|
|
7
|
+
*/
|
|
8
|
+
import type { UpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* Removes the `xmlns` attribute from table pasted from Google Sheets.
|
|
11
|
+
*
|
|
12
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
*/
|
|
14
|
+
export default function removeXmlns(documentFragment: ViewDocumentFragment, writer: UpcastWriter): void;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* Removes the `xmlns` attribute from table pasted from Google Sheets.
|
|
7
|
-
*
|
|
8
|
-
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
-
*/
|
|
10
|
-
export default function removeXmlns(documentFragment, writer) {
|
|
11
|
-
for (const child of documentFragment.getChildren()) {
|
|
12
|
-
if (child.is('element', 'table') && child.hasAttribute('xmlns')) {
|
|
13
|
-
writer.removeAttribute('xmlns', child);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* Removes the `xmlns` attribute from table pasted from Google Sheets.
|
|
7
|
+
*
|
|
8
|
+
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
*/
|
|
10
|
+
export default function removeXmlns(documentFragment, writer) {
|
|
11
|
+
for (const child of documentFragment.getChildren()) {
|
|
12
|
+
if (child.is('element', 'table') && child.hasAttribute('xmlns')) {
|
|
13
|
+
writer.removeAttribute('xmlns', child);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/filters/space.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/filters/space
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Replaces last space preceding elements closing tag with ` `. Such operation prevents spaces from being removed
|
|
10
|
-
* during further DOM/View processing (see especially {@link module:engine/view/domconverter~DomConverter#_processDomInlineNodes}).
|
|
11
|
-
* This method also takes into account Word specific `<o:p></o:p>` empty tags.
|
|
12
|
-
* Additionally multiline sequences of spaces and new lines between tags are removed (see #39 and #40).
|
|
13
|
-
*
|
|
14
|
-
* @param htmlString HTML string in which spacing should be normalized.
|
|
15
|
-
* @returns Input HTML with spaces normalized.
|
|
16
|
-
*/
|
|
17
|
-
export declare function normalizeSpacing(htmlString: string): string;
|
|
18
|
-
/**
|
|
19
|
-
* Normalizes spacing in special Word `spacerun spans` (`<span style='mso-spacerun:yes'>\s+</span>`) by replacing
|
|
20
|
-
* all spaces with ` ` pairs. This prevents spaces from being removed during further DOM/View processing
|
|
21
|
-
* (see especially {@link module:engine/view/domconverter~DomConverter#_processDomInlineNodes}).
|
|
22
|
-
*
|
|
23
|
-
* @param htmlDocument Native `Document` object in which spacing should be normalized.
|
|
24
|
-
*/
|
|
25
|
-
export declare function normalizeSpacerunSpans(htmlDocument: Document): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/filters/space
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Replaces last space preceding elements closing tag with ` `. Such operation prevents spaces from being removed
|
|
10
|
+
* during further DOM/View processing (see especially {@link module:engine/view/domconverter~DomConverter#_processDomInlineNodes}).
|
|
11
|
+
* This method also takes into account Word specific `<o:p></o:p>` empty tags.
|
|
12
|
+
* Additionally multiline sequences of spaces and new lines between tags are removed (see #39 and #40).
|
|
13
|
+
*
|
|
14
|
+
* @param htmlString HTML string in which spacing should be normalized.
|
|
15
|
+
* @returns Input HTML with spaces normalized.
|
|
16
|
+
*/
|
|
17
|
+
export declare function normalizeSpacing(htmlString: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Normalizes spacing in special Word `spacerun spans` (`<span style='mso-spacerun:yes'>\s+</span>`) by replacing
|
|
20
|
+
* all spaces with ` ` pairs. This prevents spaces from being removed during further DOM/View processing
|
|
21
|
+
* (see especially {@link module:engine/view/domconverter~DomConverter#_processDomInlineNodes}).
|
|
22
|
+
*
|
|
23
|
+
* @param htmlDocument Native `Document` object in which spacing should be normalized.
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeSpacerunSpans(htmlDocument: Document): void;
|