如何在ckeditor5的$ block中添加/删除类?

时间:2018-12-05 07:21:10

标签: ckeditor ckeditor5

我想向带有span-size style属性的块中添加一个类。我能够发现当前块是否具有fontSize属性的跨度,但无法向该块添加/删除类。

我已覆盖FontSize插件,并添加了一些代码,例如

// Adding the class.
view.document.registerPostFixer(writer => {
  const selection = editor.model.document.selection;
  const parent = Array.from(selection.getSelectedBlocks())[0];

  var itemfound = false;
  for ( const item of parent.getChildren() ) {
    if (item.hasAttribute('fontSize')) {
      itemfound = true;
      // How to add a class to parent here
      // writer.setAttribute('class', 'aaa', parent);
    	break;
    }
  }

  if (!itemfound) {
      // How to remove above added class from parent here
      // writer.removeAttribute('class', parent);
  }
});

0 个答案:

没有答案