How to fix: CKEditor is removing style attributes. Drupal 8.
How it works
CKEditor can has filters for the html. We can use existing filters for example
\Drupal\filter\Plugin\Filter
or create own custom filter. This is an example:
Html content in CKEditor always is filtering in editor_filter_xss in editor.module by secure reasons.
So if we have a filter with FilterInterface::TYPE_HTML_RESTRICTOR type then our html text will be filtered in
\Drupal\editor\EditorXssFilter\Standard::filterXss
and then filterBadProtocol method will remove our style attributes.
\Drupal\Component\Utility\UrlHelper::filterBadProtocol in core/lib/Drupal/Component/Utility/Xss.php:279
How to change it
Replace the \Drupal\editor\EditorXssFilter\Standard on our custom class.
And create the custom class for XSS filtering
\Drupal\MODULE_NAME\EditorXssFilter\StandardWithStyles
Clear drupal cache for hook_editor_xss_filter_alter.