@ckeditor/ckeditor5-paste-from-office 45.2.1 → 46.0.0-alpha.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 +1 -1
- package/dist/index.js +48 -23
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/filters/bookmark.d.ts +4 -2
- package/src/filters/bookmark.js +3 -1
- package/src/filters/br.d.ts +3 -2
- package/src/filters/br.js +4 -3
- package/src/filters/image.d.ts +1 -0
- package/src/filters/image.js +3 -2
- package/src/filters/list.d.ts +5 -2
- package/src/filters/list.js +10 -4
- package/src/filters/parse.d.ts +3 -3
- package/src/filters/parse.js +4 -4
- package/src/filters/removeboldwrapper.d.ts +3 -2
- package/src/filters/removeboldwrapper.js +2 -1
- package/src/filters/removegooglesheetstag.d.ts +3 -2
- package/src/filters/removegooglesheetstag.js +2 -1
- package/src/filters/removeinvalidtablewidth.d.ts +3 -2
- package/src/filters/removeinvalidtablewidth.js +2 -1
- package/src/filters/removemsattributes.d.ts +2 -1
- package/src/filters/removemsattributes.js +4 -3
- package/src/filters/removestyleblock.d.ts +3 -2
- package/src/filters/removestyleblock.js +2 -1
- package/src/filters/removexmlns.d.ts +3 -2
- package/src/filters/removexmlns.js +2 -1
- package/src/filters/space.d.ts +4 -2
- package/src/filters/space.js +6 -3
- package/src/filters/table.d.ts +4 -2
- package/src/filters/table.js +3 -1
- package/src/index.d.ts +19 -4
- package/src/index.js +18 -3
- package/src/normalizer.d.ts +5 -5
- package/src/normalizers/googledocsnormalizer.d.ts +5 -3
- package/src/normalizers/googledocsnormalizer.js +7 -5
- package/src/normalizers/googlesheetsnormalizer.d.ts +5 -3
- package/src/normalizers/googlesheetsnormalizer.js +9 -7
- package/src/normalizers/mswordnormalizer.d.ts +4 -4
- package/src/normalizers/mswordnormalizer.js +7 -7
- package/src/pastefromoffice.d.ts +3 -3
- package/src/pastefromoffice.js +9 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-paste-from-office",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "46.0.0-alpha.0",
|
|
4
4
|
"description": "Paste from Office feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "src/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ckeditor/ckeditor5-clipboard": "
|
|
17
|
-
"@ckeditor/ckeditor5-core": "
|
|
18
|
-
"@ckeditor/ckeditor5-engine": "
|
|
19
|
-
"ckeditor5": "
|
|
16
|
+
"@ckeditor/ckeditor5-clipboard": "46.0.0-alpha.0",
|
|
17
|
+
"@ckeditor/ckeditor5-core": "46.0.0-alpha.0",
|
|
18
|
+
"@ckeditor/ckeditor5-engine": "46.0.0-alpha.0",
|
|
19
|
+
"ckeditor5": "46.0.0-alpha.0"
|
|
20
20
|
},
|
|
21
21
|
"author": "CKSource (http://cksource.com/)",
|
|
22
22
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/bookmark
|
|
7
7
|
*/
|
|
8
|
-
import { type
|
|
8
|
+
import { type ViewUpcastWriter, type ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Transforms `<a>` elements which are bookmarks by moving their children after the element.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
11
13
|
*/
|
|
12
|
-
export
|
|
14
|
+
export declare function transformBookmarks(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
package/src/filters/bookmark.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Transforms `<a>` elements which are bookmarks by moving their children after the element.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
7
9
|
*/
|
|
8
|
-
export
|
|
10
|
+
export function transformBookmarks(documentFragment, writer) {
|
|
9
11
|
const elementsToChange = [];
|
|
10
12
|
for (const value of writer.createRangeIn(documentFragment)) {
|
|
11
13
|
const element = value.item;
|
package/src/filters/br.d.ts
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/br
|
|
7
7
|
*/
|
|
8
|
-
import { type
|
|
8
|
+
import { type ViewUpcastWriter, type ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Transforms `<br>` elements that are siblings to some block element into a paragraphs.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment The view structure to be transformed.
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export declare function transformBlockBrsToParagraphs(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
package/src/filters/br.js
CHANGED
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/br
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { ViewDomConverter, ViewDocument } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Transforms `<br>` elements that are siblings to some block element into a paragraphs.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment The view structure to be transformed.
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export function transformBlockBrsToParagraphs(documentFragment, writer) {
|
|
15
16
|
const viewDocument = new ViewDocument(writer.document.stylesProcessor);
|
|
16
|
-
const domConverter = new
|
|
17
|
+
const domConverter = new ViewDomConverter(viewDocument, { renderingMode: 'data' });
|
|
17
18
|
const blockElements = domConverter.blockElements;
|
|
18
19
|
const inlineObjectElements = domConverter.inlineObjectElements;
|
|
19
20
|
const elementsToReplace = [];
|
package/src/filters/image.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { type ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
|
12
12
|
*
|
|
13
13
|
* @param documentFragment Document fragment on which transform images.
|
|
14
14
|
* @param rtfData The RTF data from which images representation will be used.
|
|
15
|
+
* @internal
|
|
15
16
|
*/
|
|
16
17
|
export declare function replaceImagesSourceWithBase64(documentFragment: ViewDocumentFragment, rtfData: string): void;
|
|
17
18
|
/**
|
package/src/filters/image.js
CHANGED
|
@@ -5,19 +5,20 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/image
|
|
7
7
|
*/
|
|
8
|
-
import { Matcher,
|
|
8
|
+
import { Matcher, ViewUpcastWriter } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Replaces source attribute of all `<img>` elements representing regular
|
|
11
11
|
* images (not the Word shapes) with inlined base64 image representation extracted from RTF or Blob data.
|
|
12
12
|
*
|
|
13
13
|
* @param documentFragment Document fragment on which transform images.
|
|
14
14
|
* @param rtfData The RTF data from which images representation will be used.
|
|
15
|
+
* @internal
|
|
15
16
|
*/
|
|
16
17
|
export function replaceImagesSourceWithBase64(documentFragment, rtfData) {
|
|
17
18
|
if (!documentFragment.childCount) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
|
-
const upcastWriter = new
|
|
21
|
+
const upcastWriter = new ViewUpcastWriter(documentFragment.document);
|
|
21
22
|
const shapesIds = findAllShapesIds(documentFragment, upcastWriter);
|
|
22
23
|
removeAllImgElementsRepresentingShapes(shapesIds, documentFragment, upcastWriter);
|
|
23
24
|
insertMissingImgs(shapesIds, documentFragment, upcastWriter);
|
package/src/filters/list.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/list
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { ViewUpcastWriter, type ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Transforms Word specific list-like elements to the semantic HTML lists.
|
|
11
11
|
*
|
|
@@ -18,9 +18,12 @@ import { UpcastWriter, type ViewDocumentFragment } from 'ckeditor5/src/engine.js
|
|
|
18
18
|
*
|
|
19
19
|
* @param documentFragment The view structure to be transformed.
|
|
20
20
|
* @param stylesString Styles from which list-like elements styling will be extracted.
|
|
21
|
+
* @internal
|
|
21
22
|
*/
|
|
22
23
|
export declare function transformListItemLikeElementsIntoLists(documentFragment: ViewDocumentFragment, stylesString: string, hasMultiLevelListPlugin: boolean): void;
|
|
23
24
|
/**
|
|
24
25
|
* Removes paragraph wrapping content inside a list item.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
25
28
|
*/
|
|
26
|
-
export declare function unwrapParagraphInListItem(documentFragment: ViewDocumentFragment, writer:
|
|
29
|
+
export declare function unwrapParagraphInListItem(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
package/src/filters/list.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/list
|
|
7
7
|
*/
|
|
8
|
-
import { Matcher,
|
|
8
|
+
import { Matcher, ViewUpcastWriter } from 'ckeditor5/src/engine.js';
|
|
9
9
|
import { convertCssLengthToPx, isPx, toPx } from './utils.js';
|
|
10
10
|
/**
|
|
11
11
|
* Transforms Word specific list-like elements to the semantic HTML lists.
|
|
@@ -19,12 +19,13 @@ import { convertCssLengthToPx, isPx, toPx } from './utils.js';
|
|
|
19
19
|
*
|
|
20
20
|
* @param documentFragment The view structure to be transformed.
|
|
21
21
|
* @param stylesString Styles from which list-like elements styling will be extracted.
|
|
22
|
+
* @internal
|
|
22
23
|
*/
|
|
23
24
|
export function transformListItemLikeElementsIntoLists(documentFragment, stylesString, hasMultiLevelListPlugin) {
|
|
24
25
|
if (!documentFragment.childCount) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
|
-
const writer = new
|
|
28
|
+
const writer = new ViewUpcastWriter(documentFragment.document);
|
|
28
29
|
const itemLikeElements = findAllItemLikeElements(documentFragment, writer);
|
|
29
30
|
if (!itemLikeElements.length) {
|
|
30
31
|
return;
|
|
@@ -129,6 +130,8 @@ export function transformListItemLikeElementsIntoLists(documentFragment, stylesS
|
|
|
129
130
|
}
|
|
130
131
|
/**
|
|
131
132
|
* Removes paragraph wrapping content inside a list item.
|
|
133
|
+
*
|
|
134
|
+
* @internal
|
|
132
135
|
*/
|
|
133
136
|
export function unwrapParagraphInListItem(documentFragment, writer) {
|
|
134
137
|
for (const value of writer.createRangeIn(documentFragment)) {
|
|
@@ -146,7 +149,8 @@ export function unwrapParagraphInListItem(documentFragment, writer) {
|
|
|
146
149
|
* Finds all list-like elements in a given document fragment.
|
|
147
150
|
*
|
|
148
151
|
* @param documentFragment Document fragment in which to look for list-like nodes.
|
|
149
|
-
* @returns Array of found list-like items. Each item is an object containing
|
|
152
|
+
* @returns Array of found list-like items. Each item is an object containing
|
|
153
|
+
* @internal
|
|
150
154
|
*/
|
|
151
155
|
function findAllItemLikeElements(documentFragment, writer) {
|
|
152
156
|
const range = writer.createRangeIn(documentFragment);
|
|
@@ -193,8 +197,10 @@ function findAllItemLikeElements(documentFragment, writer) {
|
|
|
193
197
|
function isListContinuation(currentItem) {
|
|
194
198
|
const previousSibling = currentItem.element.previousSibling;
|
|
195
199
|
if (!previousSibling) {
|
|
200
|
+
const parent = currentItem.element.parent;
|
|
196
201
|
// If it's a li inside ul or ol like in here: https://github.com/ckeditor/ckeditor5/issues/15964.
|
|
197
|
-
|
|
202
|
+
// If the parent has previous sibling, which is not a list, then it is not a continuation.
|
|
203
|
+
return isList(parent) && (!parent.previousSibling || isList(parent.previousSibling));
|
|
198
204
|
}
|
|
199
205
|
// Even with the same id the list does not have to be continuous (#43).
|
|
200
206
|
return isList(previousSibling);
|
package/src/filters/parse.d.ts
CHANGED
|
@@ -11,11 +11,11 @@ import { type StylesProcessor, type ViewDocumentFragment } from 'ckeditor5/src/e
|
|
|
11
11
|
*
|
|
12
12
|
* @param htmlString HTML string to be parsed.
|
|
13
13
|
*/
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function parsePasteOfficeHtml(htmlString: string, stylesProcessor: StylesProcessor): PasteOfficeHtmlParseResult;
|
|
15
15
|
/**
|
|
16
|
-
* The result of {@link ~
|
|
16
|
+
* The result of {@link ~parsePasteOfficeHtml}.
|
|
17
17
|
*/
|
|
18
|
-
export interface
|
|
18
|
+
export interface PasteOfficeHtmlParseResult {
|
|
19
19
|
/**
|
|
20
20
|
* Parsed body content as a traversable structure.
|
|
21
21
|
*/
|
package/src/filters/parse.js
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/parse
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { ViewDomConverter, ViewDocument } from 'ckeditor5/src/engine.js';
|
|
9
9
|
import { normalizeSpacing, normalizeSpacerunSpans } from './space.js';
|
|
10
10
|
/**
|
|
11
11
|
* Parses the provided HTML extracting contents of `<body>` and `<style>` tags.
|
|
12
12
|
*
|
|
13
13
|
* @param htmlString HTML string to be parsed.
|
|
14
14
|
*/
|
|
15
|
-
export function
|
|
15
|
+
export function parsePasteOfficeHtml(htmlString, stylesProcessor) {
|
|
16
16
|
const domParser = new DOMParser();
|
|
17
17
|
// Remove Word specific "if comments" so content inside is not omitted by the parser.
|
|
18
18
|
htmlString = htmlString.replace(/<!--\[if gte vml 1]>/g, '');
|
|
@@ -37,13 +37,13 @@ export function parseHtml(htmlString, stylesProcessor) {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Transforms native `Document` object into {@link module:engine/view/documentfragment~
|
|
40
|
+
* Transforms native `Document` object into {@link module:engine/view/documentfragment~ViewDocumentFragment}. Comments are skipped.
|
|
41
41
|
*
|
|
42
42
|
* @param htmlDocument Native `Document` object to be transformed.
|
|
43
43
|
*/
|
|
44
44
|
function documentToView(htmlDocument, stylesProcessor) {
|
|
45
45
|
const viewDocument = new ViewDocument(stylesProcessor);
|
|
46
|
-
const domConverter = new
|
|
46
|
+
const domConverter = new ViewDomConverter(viewDocument, { renderingMode: 'data' });
|
|
47
47
|
const fragment = htmlDocument.createDocumentFragment();
|
|
48
48
|
const nodes = htmlDocument.body.childNodes;
|
|
49
49
|
while (nodes.length > 0) {
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/removeboldwrapper
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { ViewUpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Removes the `<b>` tag wrapper added by Google Docs to a copied content.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export declare function removeBoldWrapper(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* Removes the `<b>` tag wrapper added by Google Docs to a copied content.
|
|
7
7
|
*
|
|
8
8
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
* @internal
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export function removeBoldWrapper(documentFragment, writer) {
|
|
11
12
|
for (const child of documentFragment.getChildren()) {
|
|
12
13
|
if (child.is('element', 'b') && child.getStyle('font-weight') === 'normal') {
|
|
13
14
|
const childIndex = documentFragment.getChildIndex(child);
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/removegooglesheetstag
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { ViewUpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Removes the `<google-sheets-html-origin>` tag wrapper added by Google Sheets to a copied content.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export declare function removeGoogleSheetsTag(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* Removes the `<google-sheets-html-origin>` tag wrapper added by Google Sheets to a copied content.
|
|
7
7
|
*
|
|
8
8
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
* @internal
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export function removeGoogleSheetsTag(documentFragment, writer) {
|
|
11
12
|
for (const child of documentFragment.getChildren()) {
|
|
12
13
|
if (child.is('element', 'google-sheets-html-origin')) {
|
|
13
14
|
const childIndex = documentFragment.getChildIndex(child);
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/removeinvalidtablewidth
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { ViewUpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Removes the `width:0px` style from table pasted from Google Sheets.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export declare function removeInvalidTableWidth(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* Removes the `width:0px` style from table pasted from Google Sheets.
|
|
7
7
|
*
|
|
8
8
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
* @internal
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export function removeInvalidTableWidth(documentFragment, writer) {
|
|
11
12
|
for (const child of documentFragment.getChildren()) {
|
|
12
13
|
if (child.is('element', 'table') && child.getStyle('width') === '0px') {
|
|
13
14
|
writer.removeStyle('width', child);
|
|
@@ -10,5 +10,6 @@ import { type ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
|
10
10
|
* Cleanup MS attributes like styles, attributes and elements.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment element `data.content` obtained from clipboard.
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export declare function removeMSAttributes(documentFragment: ViewDocumentFragment): void;
|
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/removemsattributes
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { ViewUpcastWriter } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Cleanup MS attributes like styles, attributes and elements.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment element `data.content` obtained from clipboard.
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export function removeMSAttributes(documentFragment) {
|
|
15
16
|
const elementsToUnwrap = [];
|
|
16
|
-
const writer = new
|
|
17
|
+
const writer = new ViewUpcastWriter(documentFragment.document);
|
|
17
18
|
for (const { item } of writer.createRangeIn(documentFragment)) {
|
|
18
19
|
if (!item.is('element')) {
|
|
19
20
|
continue;
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/removestyleblock
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { ViewUpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Removes `<style>` block added by Google Sheets to a copied content.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export declare function removeStyleBlock(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* Removes `<style>` block added by Google Sheets to a copied content.
|
|
7
7
|
*
|
|
8
8
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
* @internal
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export function removeStyleBlock(documentFragment, writer) {
|
|
11
12
|
for (const child of Array.from(documentFragment.getChildren())) {
|
|
12
13
|
if (child.is('element', 'style')) {
|
|
13
14
|
writer.remove(child);
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/removexmlns
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { ViewUpcastWriter, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Removes the `xmlns` attribute from table pasted from Google Sheets.
|
|
11
11
|
*
|
|
12
12
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
+
export declare function removeXmlns(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* Removes the `xmlns` attribute from table pasted from Google Sheets.
|
|
7
7
|
*
|
|
8
8
|
* @param documentFragment element `data.content` obtained from clipboard
|
|
9
|
+
* @internal
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export function removeXmlns(documentFragment, writer) {
|
|
11
12
|
for (const child of documentFragment.getChildren()) {
|
|
12
13
|
if (child.is('element', 'table') && child.hasAttribute('xmlns')) {
|
|
13
14
|
writer.removeAttribute('xmlns', child);
|
package/src/filters/space.d.ts
CHANGED
|
@@ -7,19 +7,21 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
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~
|
|
10
|
+
* during further DOM/View processing (see especially {@link module:engine/view/domconverter~ViewDomConverter#_processDomInlineNodes}).
|
|
11
11
|
* This method also takes into account Word specific `<o:p></o:p>` empty tags.
|
|
12
12
|
* Additionally multiline sequences of spaces and new lines between tags are removed (see #39 and #40).
|
|
13
13
|
*
|
|
14
14
|
* @param htmlString HTML string in which spacing should be normalized.
|
|
15
15
|
* @returns Input HTML with spaces normalized.
|
|
16
|
+
* @internal
|
|
16
17
|
*/
|
|
17
18
|
export declare function normalizeSpacing(htmlString: string): string;
|
|
18
19
|
/**
|
|
19
20
|
* Normalizes spacing in special Word `spacerun spans` (`<span style='mso-spacerun:yes'>\s+</span>`) by replacing
|
|
20
21
|
* all spaces with ` ` pairs. This prevents spaces from being removed during further DOM/View processing
|
|
21
|
-
* (see especially {@link module:engine/view/domconverter~
|
|
22
|
+
* (see especially {@link module:engine/view/domconverter~ViewDomConverter#_processDomInlineNodes}).
|
|
22
23
|
*
|
|
23
24
|
* @param htmlDocument Native `Document` object in which spacing should be normalized.
|
|
25
|
+
* @internal
|
|
24
26
|
*/
|
|
25
27
|
export declare function normalizeSpacerunSpans(htmlDocument: Document): void;
|
package/src/filters/space.js
CHANGED
|
@@ -7,12 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
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~
|
|
10
|
+
* during further DOM/View processing (see especially {@link module:engine/view/domconverter~ViewDomConverter#_processDomInlineNodes}).
|
|
11
11
|
* This method also takes into account Word specific `<o:p></o:p>` empty tags.
|
|
12
12
|
* Additionally multiline sequences of spaces and new lines between tags are removed (see #39 and #40).
|
|
13
13
|
*
|
|
14
14
|
* @param htmlString HTML string in which spacing should be normalized.
|
|
15
15
|
* @returns Input HTML with spaces normalized.
|
|
16
|
+
* @internal
|
|
16
17
|
*/
|
|
17
18
|
export function normalizeSpacing(htmlString) {
|
|
18
19
|
// Run normalizeSafariSpaceSpans() two times to cover nested spans.
|
|
@@ -31,9 +32,10 @@ export function normalizeSpacing(htmlString) {
|
|
|
31
32
|
/**
|
|
32
33
|
* Normalizes spacing in special Word `spacerun spans` (`<span style='mso-spacerun:yes'>\s+</span>`) by replacing
|
|
33
34
|
* all spaces with ` ` pairs. This prevents spaces from being removed during further DOM/View processing
|
|
34
|
-
* (see especially {@link module:engine/view/domconverter~
|
|
35
|
+
* (see especially {@link module:engine/view/domconverter~ViewDomConverter#_processDomInlineNodes}).
|
|
35
36
|
*
|
|
36
37
|
* @param htmlDocument Native `Document` object in which spacing should be normalized.
|
|
38
|
+
* @internal
|
|
37
39
|
*/
|
|
38
40
|
export function normalizeSpacerunSpans(htmlDocument) {
|
|
39
41
|
htmlDocument.querySelectorAll('span[style*=spacerun]').forEach(el => {
|
|
@@ -45,13 +47,14 @@ export function normalizeSpacerunSpans(htmlDocument) {
|
|
|
45
47
|
/**
|
|
46
48
|
* Normalizes specific spacing generated by Safari when content pasted from Word (`<span class="Apple-converted-space"> </span>`)
|
|
47
49
|
* by replacing all spaces sequences longer than 1 space with ` ` pairs. This prevents spaces from being removed during
|
|
48
|
-
* further DOM/View processing (see especially {@link module:engine/view/domconverter~
|
|
50
|
+
* further DOM/View processing (see especially {@link module:engine/view/domconverter~ViewDomConverter#_processDataFromDomText}).
|
|
49
51
|
*
|
|
50
52
|
* This function is similar to {@link module:clipboard/utils/normalizeclipboarddata normalizeClipboardData util} but uses
|
|
51
53
|
* regular spaces / sequence for replacement.
|
|
52
54
|
*
|
|
53
55
|
* @param htmlString HTML string in which spacing should be normalized
|
|
54
56
|
* @returns Input HTML with spaces normalized.
|
|
57
|
+
* @internal
|
|
55
58
|
*/
|
|
56
59
|
function normalizeSafariSpaceSpans(htmlString) {
|
|
57
60
|
return htmlString.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g, (fullMatch, spaces) => {
|
package/src/filters/table.d.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office/filters/table
|
|
7
7
|
*/
|
|
8
|
-
import { type
|
|
8
|
+
import { type ViewUpcastWriter, type ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
9
|
/**
|
|
10
10
|
* Applies border none for table and cells without a border specified.
|
|
11
11
|
* Normalizes style length units to px.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
12
14
|
*/
|
|
13
|
-
export
|
|
15
|
+
export declare function transformTables(documentFragment: ViewDocumentFragment, writer: ViewUpcastWriter): void;
|
package/src/filters/table.js
CHANGED
|
@@ -6,8 +6,10 @@ import { convertCssLengthToPx } from './utils.js';
|
|
|
6
6
|
/**
|
|
7
7
|
* Applies border none for table and cells without a border specified.
|
|
8
8
|
* Normalizes style length units to px.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
9
11
|
*/
|
|
10
|
-
export
|
|
12
|
+
export function transformTables(documentFragment, writer) {
|
|
11
13
|
for (const item of writer.createRangeIn(documentFragment).getItems()) {
|
|
12
14
|
if (!item.is('element', 'table') &&
|
|
13
15
|
!item.is('element', 'td') &&
|
package/src/index.d.ts
CHANGED
|
@@ -5,8 +5,23 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office
|
|
7
7
|
*/
|
|
8
|
-
export {
|
|
9
|
-
export type {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
8
|
+
export { PasteFromOffice } from './pastefromoffice.js';
|
|
9
|
+
export type { PasteFromOfficeNormalizer, PasteFromOfficeNormalizerData } from './normalizer.js';
|
|
10
|
+
export { PasteFromOfficeMSWordNormalizer } from './normalizers/mswordnormalizer.js';
|
|
11
|
+
export { parsePasteOfficeHtml, type PasteOfficeHtmlParseResult } from './filters/parse.js';
|
|
12
|
+
export { transformBookmarks as _transformPasteOfficeBookmarks } from './filters/bookmark.js';
|
|
13
|
+
export { transformBlockBrsToParagraphs as _transformPasteOfficeBlockBrsToParagraphs } from './filters/br.js';
|
|
14
|
+
export { replaceImagesSourceWithBase64 as _replacePasteOfficeImagesSourceWithBase64, _convertHexToBase64 } from './filters/image.js';
|
|
15
|
+
export { transformListItemLikeElementsIntoLists as _transformPasteOfficeListItemLikeElementsIntoLists, unwrapParagraphInListItem as _unwrapPasteOfficeParagraphInListItem } from './filters/list.js';
|
|
16
|
+
export { removeBoldWrapper as _removePasteOfficeBoldWrapper } from './filters/removeboldwrapper.js';
|
|
17
|
+
export { removeGoogleSheetsTag as _removePasteGoogleOfficeSheetsTag } from './filters/removegooglesheetstag.js';
|
|
18
|
+
export { removeInvalidTableWidth as _removePasteOfficeInvalidTableWidths } from './filters/removeinvalidtablewidth.js';
|
|
19
|
+
export { removeMSAttributes as _removePasteMSOfficeAttributes } from './filters/removemsattributes.js';
|
|
20
|
+
export { removeStyleBlock as _removePasteOfficeStyleBlock } from './filters/removestyleblock.js';
|
|
21
|
+
export { removeXmlns as _removePasteOfficeXmlnsAttributes } from './filters/removexmlns.js';
|
|
22
|
+
export { normalizeSpacing as _normalizePasteOfficeSpacing, normalizeSpacerunSpans as _normalizePasteOfficeSpaceRunSpans } from './filters/space.js';
|
|
23
|
+
export { transformTables as _transformPasteOfficeTables } from './filters/table.js';
|
|
24
|
+
export { convertCssLengthToPx as _convertPasteOfficeCssLengthToPx, isPx as _isPasteOfficePxValue, toPx as _toPasteOfficePxValue } from './filters/utils.js';
|
|
25
|
+
export { GoogleDocsNormalizer as PasteFromOfficeGoogleDocsNormalizer } from './normalizers/googledocsnormalizer.js';
|
|
26
|
+
export { GoogleSheetsNormalizer as PasteFromOfficeGoogleSheetsNormalizer } from './normalizers/googlesheetsnormalizer.js';
|
|
12
27
|
import './augmentation.js';
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,22 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module paste-from-office
|
|
7
7
|
*/
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
8
|
+
export { PasteFromOffice } from './pastefromoffice.js';
|
|
9
|
+
export { PasteFromOfficeMSWordNormalizer } from './normalizers/mswordnormalizer.js';
|
|
10
|
+
export { parsePasteOfficeHtml } from './filters/parse.js';
|
|
11
|
+
export { transformBookmarks as _transformPasteOfficeBookmarks } from './filters/bookmark.js';
|
|
12
|
+
export { transformBlockBrsToParagraphs as _transformPasteOfficeBlockBrsToParagraphs } from './filters/br.js';
|
|
13
|
+
export { replaceImagesSourceWithBase64 as _replacePasteOfficeImagesSourceWithBase64, _convertHexToBase64 } from './filters/image.js';
|
|
14
|
+
export { transformListItemLikeElementsIntoLists as _transformPasteOfficeListItemLikeElementsIntoLists, unwrapParagraphInListItem as _unwrapPasteOfficeParagraphInListItem } from './filters/list.js';
|
|
15
|
+
export { removeBoldWrapper as _removePasteOfficeBoldWrapper } from './filters/removeboldwrapper.js';
|
|
16
|
+
export { removeGoogleSheetsTag as _removePasteGoogleOfficeSheetsTag } from './filters/removegooglesheetstag.js';
|
|
17
|
+
export { removeInvalidTableWidth as _removePasteOfficeInvalidTableWidths } from './filters/removeinvalidtablewidth.js';
|
|
18
|
+
export { removeMSAttributes as _removePasteMSOfficeAttributes } from './filters/removemsattributes.js';
|
|
19
|
+
export { removeStyleBlock as _removePasteOfficeStyleBlock } from './filters/removestyleblock.js';
|
|
20
|
+
export { removeXmlns as _removePasteOfficeXmlnsAttributes } from './filters/removexmlns.js';
|
|
21
|
+
export { normalizeSpacing as _normalizePasteOfficeSpacing, normalizeSpacerunSpans as _normalizePasteOfficeSpaceRunSpans } from './filters/space.js';
|
|
22
|
+
export { transformTables as _transformPasteOfficeTables } from './filters/table.js';
|
|
23
|
+
export { convertCssLengthToPx as _convertPasteOfficeCssLengthToPx, isPx as _isPasteOfficePxValue, toPx as _toPasteOfficePxValue } from './filters/utils.js';
|
|
24
|
+
export { GoogleDocsNormalizer as PasteFromOfficeGoogleDocsNormalizer } from './normalizers/googledocsnormalizer.js';
|
|
25
|
+
export { GoogleSheetsNormalizer as PasteFromOfficeGoogleSheetsNormalizer } from './normalizers/googlesheetsnormalizer.js';
|
|
11
26
|
import './augmentation.js';
|
package/src/normalizer.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module paste-from-office/normalizer
|
|
7
7
|
*/
|
|
8
8
|
import type { ClipboardInputTransformationData } from 'ckeditor5/src/clipboard.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { PasteOfficeHtmlParseResult } from './filters/parse.js';
|
|
10
10
|
/**
|
|
11
11
|
* Interface defining a content transformation pasted from an external editor.
|
|
12
12
|
*
|
|
@@ -14,7 +14,7 @@ import type { ParseHtmlResult } from './filters/parse.js';
|
|
|
14
14
|
* {@link module:clipboard/clipboardpipeline~ClipboardPipeline#event:inputTransformation inputTransformation event}.
|
|
15
15
|
* They detect environment-specific quirks and transform it into a form compatible with other CKEditor features.
|
|
16
16
|
*/
|
|
17
|
-
export interface
|
|
17
|
+
export interface PasteFromOfficeNormalizer {
|
|
18
18
|
/**
|
|
19
19
|
* Must return `true` if the `htmlString` contains content which this normalizer can transform.
|
|
20
20
|
*/
|
|
@@ -22,9 +22,9 @@ export interface Normalizer {
|
|
|
22
22
|
/**
|
|
23
23
|
* Executes the normalization of a given data.
|
|
24
24
|
*/
|
|
25
|
-
execute(data:
|
|
25
|
+
execute(data: PasteFromOfficeNormalizerData): void;
|
|
26
26
|
}
|
|
27
|
-
export interface
|
|
27
|
+
export interface PasteFromOfficeNormalizerData extends ClipboardInputTransformationData {
|
|
28
28
|
_isTransformedWithPasteFromOffice?: boolean;
|
|
29
|
-
_parsedData:
|
|
29
|
+
_parsedData: PasteOfficeHtmlParseResult;
|
|
30
30
|
}
|
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
* @module paste-from-office/normalizers/googledocsnormalizer
|
|
7
7
|
*/
|
|
8
8
|
import { type ViewDocument } from 'ckeditor5/src/engine.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { PasteFromOfficeNormalizer, PasteFromOfficeNormalizerData } from '../normalizer.js';
|
|
10
10
|
/**
|
|
11
11
|
* Normalizer for the content pasted from Google Docs.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
12
14
|
*/
|
|
13
|
-
export
|
|
15
|
+
export declare class GoogleDocsNormalizer implements PasteFromOfficeNormalizer {
|
|
14
16
|
readonly document: ViewDocument;
|
|
15
17
|
/**
|
|
16
18
|
* Creates a new `GoogleDocsNormalizer` instance.
|
|
@@ -25,5 +27,5 @@ export default class GoogleDocsNormalizer implements Normalizer {
|
|
|
25
27
|
/**
|
|
26
28
|
* @inheritDoc
|
|
27
29
|
*/
|
|
28
|
-
execute(data:
|
|
30
|
+
execute(data: PasteFromOfficeNormalizerData): void;
|
|
29
31
|
}
|