diff --git a/CHANGELOG.md b/CHANGELOG.md index d71cf80..f76fcf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- CKEditor configs created via the `ckeditor/convert` command now allow modifying HTML attributes, classes, and styles within the source view, if the Redactor config included the `html` button. ([#264](https://github.com/craftcms/ckeditor/pull/264), [#263](https://github.com/craftcms/ckeditor/issues/263)) - Added `craft\ckeditor\events\ModifyConfigEvent::$toolbar`. ([#233](https://github.com/craftcms/ckeditor/pull/233)) - Fixed a bug where code blocks created by a Redactor field only had `
` tags with no `` tags inside them. ([#258](https://github.com/craftcms/ckeditor/issues/258))
 
diff --git a/src/console/controllers/ConvertController.php b/src/console/controllers/ConvertController.php
index 5a4f2be..284ec56 100644
--- a/src/console/controllers/ConvertController.php
+++ b/src/console/controllers/ConvertController.php
@@ -207,7 +207,7 @@ public function actionRedactor(): int
                         throw new Exception('`manualConfig` contains invalid JSON.');
                     }
                     $configName = $field['name'] ?? (!empty($field['handle']) ? Inflector::camel2words($field['handle']) : 'Untitled');
-                    $ckeConfig = $this->generateCkeConfig($configName, $redactorConfig, $ckeConfigs, $fieldSettingsByConfig);
+                    $ckeConfig = $this->generateCkeConfig($configName, $redactorConfig, $ckeConfigs, $fieldSettingsByConfig, $field);
                     $this->stdout(PHP_EOL);
                 } else {
                     $basename = ($field['settings']['redactorConfig'] ?? $field['settings']['configFile'] ?? null) ?: 'Default.json';
@@ -347,6 +347,7 @@ private function generateCkeConfig(
         array $redactorConfig,
         array &$ckeConfigs,
         array &$fieldSettingsByConfig,
+        ?array $redactorField = null,
     ): string {
         // Make sure the name is unique
         $baseConfigName = $configName;
@@ -669,6 +670,22 @@ private function generateCkeConfig(
             }
         }
 
+        // if we added sourceEditing button, then to align with what Redactor allowed,
+        // we need add this predefined htmlSupport.allow config
+        if ($ckeConfig->hasButton('sourceEditing')) {
+            $htmlSupport = [
+                'attributes' => true,
+                'classes' => true,
+                'styles' => true,
+            ];
+
+            if ($redactorField !== null && $redactorField['settings']['removeInlineStyles']) {
+                unset($htmlSupport['styles']);
+            }
+
+            $ckeConfig->options['htmlSupport']['allow'][] = $htmlSupport;
+        }
+
         // redactor-link-styles
         if (!empty($fullRedactorConfig['linkClasses'])) {
             foreach ($fullRedactorConfig['linkClasses'] as $linkClass) {