The task at hand here is to allow the client to create a classed wrapper around multiple elements using CKEditor in Drupal 8.

The fundamental problem here is the CKEditor’s built in “Styles” dropdown classes each

individually, while we need a class wrapping them.

You could probably make or install your own CKEditor plugin, but that’s not what I did.

I did this with Javascript.

Create the class and add it to the menu at /admin/config/content/formats -> my format
2017-08-09_13-17-39.png

Add this setting to allow the class to be added:
2017-08-09_13-20-22.png

Note: If you want to allow any class, add this instead:

Establish the JS library.
mytheme.libraries.yml


content-sidebar:
  js:
    path-to-file.js: { }
  dependencies:
    - core/jquery

Here’s the JS code you need:
(function ($, Drupal) {
Drupal.behaviors.content_sidebar = {
attach: function (context) {
var foundSidebars = 1;
while (foundSidebars > 0) {
foundSidebars = wrapSidebarGroup($);
}
function wrapSidebarGroup($) {
return $(‘p.content-sidebar__unprocessed’).first().nextUntil(‘:not(.content-sidebar__unprocessed)’).addBack().removeClass(‘content-sidebar__unprocessed’).addClass(‘content-sidebar’).wrapAll(‘