Changes for page EditSheet

Last modified by superadmin on 2025/02/27 10:46

From version 2.1
edited by Thomas Coelho (local)
on 2022/05/27 15:18
Change comment: Install extension [org.xwiki.contrib:application-ckeditor-ui/1.63.1]
To version 1.1
edited by Thomas Coelho (local)
on 2022/04/20 16:09
Change comment: Install extension [org.xwiki.contrib:application-ckeditor-ui/1.61]

Summary

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -3,7 +3,6 @@
3 3  #set ($ckeditorBasePath = $stringtool.removeEnd($stringtool.removeEnd($ckeditorPath, '.js'), 'ckeditor'))
4 4  #set ($resourcePickerBundlePath = "${ckeditorBasePath}plugins/xwiki-resource/resourcePicker.bundle.min")
5 5  #set ($macroWizardBundlePath = "${ckeditorBasePath}plugins/xwiki-macro/macroWizard.bundle.min")
6 -#set ($imageWizardBundlePath = "${ckeditorBasePath}plugins/xwiki-image/imageWizard.bundle.min")
7 7  #set ($modalPath = "${ckeditorBasePath}plugins/xwiki-dialog/modal.min")
8 8  #set ($l10nPath = "${ckeditorBasePath}plugins/xwiki-localization/l10n.min")
9 9  */
... ... @@ -14,7 +14,6 @@
14 14   modal: '$!modalPath',
15 15   l10n: '$!l10nPath',
16 16   macroWizard: '$!macroWizardBundlePath',
17 - imageWizard: '$!imageWizardBundlePath',
18 18   // This is used by the resource suggest picker on the link modal.
19 19   'bootstrap3-typeahead': $jsontool.serialize($services.webjars.url('org.webjars.npm:bootstrap-3-typeahead',
20 20   'bootstrap3-typeahead.min')),
... ... @@ -29,7 +29,7 @@
29 29   ckeditor: {
30 30   exports: 'CKEDITOR',
31 31   // This includes dependencies of the plugins bundled with the CKEditor code.
32 - deps: ['jquery', 'resource', 'resourcePicker', 'macroWizard', 'imageWizard']
30 + deps: ['jquery', 'resource', 'resourcePicker', 'macroWizard']
33 33   }
34 34   },
35 35   config: {
... ... @@ -58,6 +58,56 @@
58 58   "$!services.webjars.url('org.xwiki.platform:xwiki-platform-tree-webjar', 'require-config.min.js', {'evaluate': true})"
59 59  ], function($, ckeditor, xwikiMeta) {
60 60   var deferred = $.Deferred();
59 +
60 + var loadJavaScriptSkinExtensions = $jsontool.serialize($xwiki.getDocument('CKEditor.Config'
61 + ).getValue('loadJavaScriptSkinExtensions')) === 1;
62 +
63 + // See http://docs.ckeditor.com/#!/guide/dev_allowed_content_rules
64 + var allowedContentBySyntax = {
65 + 'xwiki/2.1': {
66 + '$1': {
67 + elements: {
68 + // Elements required because the editor input is a full HTML page.
69 + html: true, head: true, link: true, script: loadJavaScriptSkinExtensions, body: true,
70 + // Headings
71 + h1: true, h2: true, h3: true, h4: true, h5: true, h6: true,
72 + // Lists
73 + dl: true, ol: true, ul: true,
74 + // Tables
75 + table: true, tr: true, th: true, td: true,
76 + // Formatting
77 + span: true, strong: true, em: true, ins: true, del: true, sub: true, sup: true, tt: true, pre: true,
78 + // Others
79 + div: true, hr: true, p: true, a: true, img: true, blockquote: true, figure: true
80 + },
81 + // The elements above can have any attribute, through the parameter (%%) syntax.
82 + attributes: '*',
83 + styles: '*',
84 + classes: '*'
85 + },
86 + '$2': {
87 + // The XWiki syntax doesn't support parameters for the following elements.
88 + elements: {br: true, dd: true, dt: true, li: true, tbody: true, figcaption: true}
89 + },
90 + '$3': {
91 + // Wiki syntax macros can output any HTML.
92 + match: CKEDITOR.plugins.xwikiMacro.isMacroOutput,
93 + attributes: '*',
94 + styles: '*',
95 + classes: '*'
96 + }
97 + },
98 + 'plain/1.0': ';'
99 + };
100 + allowedContentBySyntax['xwiki/2.0'] = allowedContentBySyntax['xwiki/2.1'];
101 + // This is a hack, increasing the technical debt since the CKEditor module should not know about the Markdown
102 + // syntax. Actually it should not know either about the xwiki/2.0 and xwiki/2.1 syntaxes ;)
103 + // This should be fixed by implementing https://jira.xwiki.org/browse/CKEDITOR-319
104 + allowedContentBySyntax['markdown/1.2'] = $.extend(true, {}, allowedContentBySyntax['xwiki/2.1']);
105 + // Markdown doesn't allow figures at the moment.
106 + delete allowedContentBySyntax['markdown/1.2']['$1'].elements.figure;
107 + delete allowedContentBySyntax['markdown/1.2']['$2'].elements.figcaption;
108 +
61 61   var currentLocale = $('html').attr('lang') || '';
62 62  
63 63   // We have to pass the plugin that makes the request (the initiator) because the expected response can be different
... ... @@ -66,7 +66,6 @@
66 66   return document.getURL('get', $.param({
67 67   sheet: 'CKEditor.FileUploader',
68 68   outputSyntax: 'plain',
69 - // The syntax and language are important especially when the upload request creates a new document.
70 70   syntax: document.syntax,
71 71   language: currentLocale,
72 72   form_token: xwikiMeta.form_token,
... ... @@ -82,14 +82,60 @@
82 82   sourceDocument = new XWiki.Document(XWiki.Model.resolve(sourceDocumentReference, XWiki.EntityType.DOCUMENT));
83 83   }
84 84   sourceDocument.syntax = $(element).attr('data-sourceDocumentSyntax');
132 + var isHTML5 = $(element).data('syntax') !== 'annotatedxhtml/1.0';
85 85  
134 + var allowedContent;
135 + var allowedContentWithoutFigure;
136 + if (sourceDocument.syntax in allowedContentBySyntax) {
137 + allowedContent = allowedContentBySyntax[sourceDocument.syntax];
138 + // Try removing the figure/figcaption tags for caption content to forbid nested figures.
139 + allowedContentWithoutFigure = $.extend(true, {}, allowedContent);
140 + delete allowedContentWithoutFigure['$1']?.elements?.figure;
141 + delete allowedContentWithoutFigure['$2']?.elements?.figcaption;
142 +
143 + // Disable figure support if the syntax isn't HTML 5.
144 + if (!isHTML5) {
145 + allowedContent = allowedContentWithoutFigure;
146 + }
147 + }
148 +
86 86   var config = {
150 + allowedContent: allowedContent,
151 + editorplaceholder: $jsontool.serialize($services.localization.render('ckeditor.content.placeholder')),
87 87   filebrowserUploadUrl: getUploadURL(sourceDocument, 'filebrowser'),
153 + // This is used in CKEditor.FileUploader so we must keep them in sync.
154 + fileTools_defaultFileName: '__fileCreatedFromDataURI__',
88 88   height: $(element).height(),
156 + // CKEditor uses '-' (dash) as locale separator (between the language code and the country code).
157 + language: currentLocale.toLowerCase().replace('_', '-'),
158 + uploadUrl: getUploadURL(sourceDocument, 'filetools'),
159 + stylesSet: isHTML5 ? 'html5' : 'html4',
160 + 'xwiki-image' : {
161 + captionAllowedContent: allowedContentWithoutFigure
162 + },
163 + 'xwiki-link': {
164 + labelGenerator: sourceDocument.getURL('get', $.param({
165 + sheet: 'CKEditor.LinkLabelGenerator',
166 + outputSyntax: 'plain',
167 + language: currentLocale
168 + }))
169 + },
170 + 'xwiki-resource': {
171 + dispatcher: sourceDocument.getURL('get', $.param({
172 + sheet: 'CKEditor.ResourceDispatcher',
173 + outputSyntax: 'plain',
174 + language: currentLocale
175 + }))
176 + },
177 + 'xwiki-source': {
178 + htmlConverter: sourceDocument.getURL('get', $.param({
179 + sheet: 'CKEditor.HTMLConverter',
180 + outputSyntax: 'plain',
181 + language: currentLocale
182 + }))
183 + },
89 89   mentions: [
90 90   {
91 - // We use the source document to compute the feed URL because we want the suggested link references to be
92 - // relative to the edited document (we want the editor to output relative references as much as possible).
93 93   feed: sourceDocument.getURL('get', $.param({
94 94   sheet: 'CKEditor.LinkSuggestions',
95 95   outputSyntax: 'plain',
... ... @@ -114,19 +114,16 @@
114 114   minChars: 0,
115 115   itemsLimit: 6
116 116   }
117 - ],
118 - sourceDocument: sourceDocument,
119 - uploadUrl: getUploadURL(sourceDocument, 'filetools'),
120 - 'xwiki-link': {
121 - // We use the source document to compute the link label generator URL because we want the link references to be
122 - // resolved relative to the edited document (as they were inserted).
123 - labelGenerator: sourceDocument.getURL('get', $.param({
124 - sheet: 'CKEditor.LinkLabelGenerator',
125 - outputSyntax: 'plain',
210 + ]
211 + };
212 + if ($(element).attr('data-officeImporterSupported') === 'true') {
213 + config['xwiki-office'] = {
214 + importer: sourceDocument.getURL('get', $.param({
215 + sheet: 'CKEditor.OfficeImporter',
126 126   language: currentLocale
127 127   }))
128 - }
129 - };
218 + };
219 + }
130 130   return config;
131 131   };
132 132