CKEditor установить атрибут с помощью getElementsByTag? - PullRequest
0 голосов
/ 10 февраля 2020

Мне нужно вставить новый класс, идентификатор и другие атрибуты элемента с помощью getElementsByTag метода в CKEditor.

CKEDITOR.on('instanceReady', function(event) {
  var editor = CKEDITOR.instances.editor;

  editor.dataProcessor.htmlFilter.addRules({
    elements: {
      $: function(element) {
        if (element.name == 'blockquote') {
          if (!element.attributes.class) {
               //element['class'] = 'block';
               element.attributes.class = 'block'  
          }
        }
      }
    }
  });
});

Ввод:

<blockquote>
  <p>(b) Any information recorded or stored by means of any tape-recorder, computer, or other device; and any material subsequently derived from information so recorded or stored.</p>
</blockquote>

Обязательный вывод

<blockquote class="block" id="bq001">
  <p>(b) Any information recorded or stored by means of any tape-recorder, computer, or other device; and any material subsequently derived from information so recorded or stored.</p>
</blockquote>
...