@ckeditor/ckeditor5-clipboard 0.0.0-nightly-next-20260105.0 → 0.0.0-nightly-next-20260106.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.
@@ -1,28 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module clipboard/utils/normalizeclipboarddata
7
- */
8
- /**
9
- * Removes some popular browser quirks out of the clipboard data (HTML).
10
- * Removes all HTML comments. These are considered an internal thing and it makes little sense if they leak into the editor data.
11
- *
12
- * @param data The HTML data to normalize.
13
- * @returns Normalized HTML.
14
- * @internal
15
- */
16
- export function normalizeClipboardData(data) {
17
- return data
18
- .replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g, (fullMatch, spaces) => {
19
- // Handle the most popular and problematic case when even a single space becomes an nbsp;.
20
- // Decode those to normal spaces. Read more in https://github.com/ckeditor/ckeditor5-clipboard/issues/2.
21
- if (spaces.length == 1) {
22
- return ' ';
23
- }
24
- return spaces;
25
- })
26
- // Remove all HTML comments.
27
- .replace(/<!--[\s\S]*?-->/g, '');
28
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module clipboard/utils/plaintexttohtml
7
- */
8
- /**
9
- * Converts plain text to its HTML-ized version.
10
- *
11
- * @param text The plain text to convert.
12
- * @returns HTML generated from the plain text.
13
- */
14
- export function plainTextToHtml(text) {
15
- text = text
16
- // Encode &.
17
- .replace(/&/g, '&amp;')
18
- // Encode <>.
19
- .replace(/</g, '&lt;')
20
- .replace(/>/g, '&gt;')
21
- // Creates a paragraph for each double line break.
22
- .replace(/\r?\n\r?\n/g, '</p><p>')
23
- // Creates a line break for each single line break.
24
- .replace(/\r?\n/g, '<br>')
25
- // Replace tabs with four spaces.
26
- .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;')
27
- // Preserve trailing spaces (only the first and last one – the rest is handled below).
28
- .replace(/^\s/, '&nbsp;')
29
- .replace(/\s$/, '&nbsp;')
30
- // Preserve other subsequent spaces now.
31
- .replace(/\s\s/g, ' &nbsp;');
32
- if (text.includes('</p><p>') || text.includes('<br>')) {
33
- // If we created paragraphs above, add the trailing ones.
34
- text = `<p>${text}</p>`;
35
- }
36
- // TODO:
37
- // * What about '\nfoo' vs ' foo'?
38
- return text;
39
- }
@@ -1,96 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- // Elements which should not have empty-line padding.
6
- // Most `view.ContainerElement` want to be separate by new-line, but some are creating one structure
7
- // together (like `<li>`) so it is better to separate them by only one "\n".
8
- const smallPaddingElements = ['figcaption', 'li'];
9
- const listElements = ['ol', 'ul'];
10
- /**
11
- * Converts {@link module:engine/view/item~ViewItem view item} and all of its children to plain text.
12
- *
13
- * @param converter The converter instance.
14
- * @param viewItem View item to convert.
15
- * @returns Plain text representation of `viewItem`.
16
- */
17
- export function viewToPlainText(converter, viewItem) {
18
- if (viewItem.is('$text') || viewItem.is('$textProxy')) {
19
- return viewItem.data;
20
- }
21
- if (viewItem.is('element', 'img') && viewItem.hasAttribute('alt')) {
22
- return viewItem.getAttribute('alt');
23
- }
24
- if (viewItem.is('element', 'br')) {
25
- return '\n'; // Convert soft breaks to single line break (#8045).
26
- }
27
- /**
28
- * Item is a document fragment, attribute element or container element. It doesn't
29
- * have it's own text value, so we need to convert its children elements.
30
- */
31
- let text = '';
32
- let prev = null;
33
- for (const child of viewItem.getChildren()) {
34
- text += newLinePadding(child, prev) + viewToPlainText(converter, child);
35
- prev = child;
36
- }
37
- // If item is a raw element, the only way to get its content is to render it and read the text directly from DOM.
38
- if (viewItem.is('rawElement')) {
39
- const doc = document.implementation.createHTMLDocument('');
40
- const tempElement = doc.createElement('div');
41
- viewItem.render(tempElement, converter);
42
- text += domElementToPlainText(tempElement);
43
- }
44
- return text;
45
- }
46
- /**
47
- * Recursively converts DOM element and all of its children to plain text.
48
- */
49
- function domElementToPlainText(element) {
50
- let text = '';
51
- if (element.nodeType === Node.TEXT_NODE) {
52
- return element.textContent;
53
- }
54
- else if (element.tagName === 'BR') {
55
- return '\n';
56
- }
57
- for (const child of element.childNodes) {
58
- text += domElementToPlainText(child);
59
- }
60
- return text;
61
- }
62
- /**
63
- * Returns new line padding to prefix the given elements with.
64
- */
65
- function newLinePadding(element, previous) {
66
- if (!previous) {
67
- // Don't add padding to first elements in a level.
68
- return '';
69
- }
70
- if (element.is('element', 'li') && !element.isEmpty && element.getChild(0).is('containerElement')) {
71
- // Separate document list items with empty lines.
72
- return '\n\n';
73
- }
74
- if (listElements.includes(element.name) && listElements.includes(previous.name)) {
75
- /**
76
- * Because `<ul>` and `<ol>` are ViewAttributeElements, two consecutive lists will not have any padding between
77
- * them (see the `if` statement below). To fix this, we need to make an exception for this case.
78
- */
79
- return '\n\n';
80
- }
81
- if (!element.is('containerElement') && !previous.is('containerElement')) {
82
- // Don't add padding between non-container elements.
83
- return '';
84
- }
85
- if (smallPaddingElements.includes(element.name) || smallPaddingElements.includes(previous.name)) {
86
- // Add small padding between selected container elements.
87
- return '\n';
88
- }
89
- // Do not add padding around the elements that won't be rendered.
90
- if (element.is('element') && element.getCustomProperty('dataPipeline:transparentRendering') ||
91
- previous.is('element') && previous.getCustomProperty('dataPipeline:transparentRendering')) {
92
- return '';
93
- }
94
- // Add empty lines between container elements.
95
- return '\n\n';
96
- }