@ckeditor/ckeditor5-html-support 35.3.2 → 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.
@@ -0,0 +1,90 @@
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
+ /**
7
+ * @module html-support/htmlpagedataprocessor
8
+ */
9
+
10
+ import { HtmlDataProcessor, UpcastWriter } from 'ckeditor5/src/engine';
11
+
12
+ /**
13
+ * The full page HTML data processor class.
14
+ * This data processor implementation uses HTML as input and output data.
15
+ *
16
+ * @implements module:engine/dataprocessor/dataprocessor~DataProcessor
17
+ */
18
+ export default class HtmlPageDataProcessor extends HtmlDataProcessor {
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ toView( data ) {
23
+ // Ignore content that is not a full page source.
24
+ if ( !data.match( /<(?:html|body|head|meta)(?:\s[^>]*)?>/i ) ) {
25
+ return super.toView( data );
26
+ }
27
+
28
+ // Store doctype and xml declaration in a separate properties as they can't be stringified later.
29
+ let docType = '';
30
+ let xmlDeclaration = '';
31
+
32
+ data = data.replace( /<!DOCTYPE[^>]*>/i, match => {
33
+ docType = match;
34
+
35
+ return '';
36
+ } );
37
+
38
+ data = data.replace( /<\?xml\s[^?]*\?>/i, match => {
39
+ xmlDeclaration = match;
40
+
41
+ return '';
42
+ } );
43
+
44
+ // Convert input HTML data to DOM DocumentFragment.
45
+ const domFragment = this._toDom( data );
46
+
47
+ // Convert DOM DocumentFragment to view DocumentFragment.
48
+ const viewFragment = this.domConverter.domToView( domFragment, { skipComments: this.skipComments } );
49
+
50
+ const writer = new UpcastWriter( viewFragment.document );
51
+
52
+ // Using the DOM document with body content extracted as a skeleton of the page.
53
+ writer.setCustomProperty( '$fullPageDocument', domFragment.ownerDocument.documentElement.outerHTML, viewFragment );
54
+
55
+ if ( docType ) {
56
+ writer.setCustomProperty( '$fullPageDocType', docType, viewFragment );
57
+ }
58
+
59
+ if ( xmlDeclaration ) {
60
+ writer.setCustomProperty( '$fullPageXmlDeclaration', xmlDeclaration, viewFragment );
61
+ }
62
+
63
+ return viewFragment;
64
+ }
65
+
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ toData( viewFragment ) {
70
+ let data = super.toData( viewFragment );
71
+
72
+ const page = viewFragment.getCustomProperty( '$fullPageDocument' );
73
+ const docType = viewFragment.getCustomProperty( '$fullPageDocType' );
74
+ const xmlDeclaration = viewFragment.getCustomProperty( '$fullPageXmlDeclaration' );
75
+
76
+ if ( page ) {
77
+ data = page.replace( /<\/body\s*>/, data + '$&' );
78
+
79
+ if ( docType ) {
80
+ data = docType + '\n' + data;
81
+ }
82
+
83
+ if ( xmlDeclaration ) {
84
+ data = xmlDeclaration + '\n' + data;
85
+ }
86
+ }
87
+
88
+ return data;
89
+ }
90
+ }
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -11,3 +11,5 @@ export { default as GeneralHtmlSupport } from './generalhtmlsupport';
11
11
  export { default as DataFilter } from './datafilter';
12
12
  export { default as DataSchema } from './dataschema';
13
13
  export { default as HtmlComment } from './htmlcomment';
14
+ export { default as FullPage } from './fullpage';
15
+ export { default as HtmlPageDataProcessor } from './htmlpagedataprocessor';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -83,7 +83,7 @@ export default class MediaEmbedElementSupport extends Plugin {
83
83
 
84
84
  function viewToModelMediaAttributesConverter( dataFilter, mediaElementName ) {
85
85
  return dispatcher => {
86
- dispatcher.on( `element:${ mediaElementName }`, upcastMedia );
86
+ dispatcher.on( `element:${ mediaElementName }`, upcastMedia, { priority: 'low' } );
87
87
  };
88
88
 
89
89
  function upcastMedia( evt, data, conversionApi ) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -101,7 +101,7 @@ function viewToModelTableAttributeConverter( dataFilter ) {
101
101
  conversionApi.writer.setAttribute( attributeName, viewAttributes, data.modelRange );
102
102
  }
103
103
  }
104
- } );
104
+ }, { priority: 'low' } );
105
105
  };
106
106
  }
107
107
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
5
 
@@ -609,7 +609,8 @@ export default {
609
609
  view: 'strong',
610
610
  coupledAttribute: 'bold',
611
611
  attributeProperties: {
612
- copyOnEnter: true
612
+ copyOnEnter: true,
613
+ isFormatting: true
613
614
  }
614
615
  },
615
616
  {
@@ -617,7 +618,8 @@ export default {
617
618
  view: 'b',
618
619
  coupledAttribute: 'bold',
619
620
  attributeProperties: {
620
- copyOnEnter: true
621
+ copyOnEnter: true,
622
+ isFormatting: true
621
623
  }
622
624
  },
623
625
  {
@@ -625,7 +627,8 @@ export default {
625
627
  view: 'i',
626
628
  coupledAttribute: 'italic',
627
629
  attributeProperties: {
628
- copyOnEnter: true
630
+ copyOnEnter: true,
631
+ isFormatting: true
629
632
  }
630
633
  },
631
634
  {
@@ -633,7 +636,8 @@ export default {
633
636
  view: 'em',
634
637
  coupledAttribute: 'italic',
635
638
  attributeProperties: {
636
- copyOnEnter: true
639
+ copyOnEnter: true,
640
+ isFormatting: true
637
641
  }
638
642
  },
639
643
  {
@@ -641,7 +645,8 @@ export default {
641
645
  view: 's',
642
646
  coupledAttribute: 'strikethrough',
643
647
  attributeProperties: {
644
- copyOnEnter: true
648
+ copyOnEnter: true,
649
+ isFormatting: true
645
650
  }
646
651
  },
647
652
  // TODO According to HTML-spec can behave as div-like element, although CKE4 only handles it as an inline element.
@@ -666,7 +671,8 @@ export default {
666
671
  view: 'u',
667
672
  coupledAttribute: 'underline',
668
673
  attributeProperties: {
669
- copyOnEnter: true
674
+ copyOnEnter: true,
675
+ isFormatting: true
670
676
  }
671
677
  },
672
678
  {
@@ -674,7 +680,8 @@ export default {
674
680
  view: 'sub',
675
681
  coupledAttribute: 'subscript',
676
682
  attributeProperties: {
677
- copyOnEnter: true
683
+ copyOnEnter: true,
684
+ isFormatting: true
678
685
  }
679
686
  },
680
687
  {
@@ -682,7 +689,8 @@ export default {
682
689
  view: 'sup',
683
690
  coupledAttribute: 'superscript',
684
691
  attributeProperties: {
685
- copyOnEnter: true
692
+ copyOnEnter: true,
693
+ isFormatting: true
686
694
  }
687
695
  },
688
696
  {
@@ -690,7 +698,8 @@ export default {
690
698
  view: 'code',
691
699
  coupledAttribute: 'code',
692
700
  attributeProperties: {
693
- copyOnEnter: true
701
+ copyOnEnter: true,
702
+ isFormatting: true
694
703
  }
695
704
  },
696
705
  {
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * 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
5