简体   繁体   中英

Unbounded CkEditor5 view values

I am currently trying to build a color plugin for CkEditor5 to mimic the one that was available for CkEditor4.

I have an input method, but mapping the model values to view values is my stumbling block. The System appears to be set up so that every possible value is known in advance and mapped - which for hex values is obviously impractical.

Is there any way to tell CkEditor to just directly use the model value in the view style tag and the view value in the model?

I assume that you are creating a plugin with a colorpicker UI.

You won't be able to couple that with the existing highlight plugin available for CKE5. Instead, I recommend creating a new plugin. You may check out highlight plugin to see what needs to be done to provide a plugin.

Is there any way to tell CKEditor to just directly use the model value in the view style tag and the view value in the model?

Yes. You need to set up a proper downcast (model->view) and upcast (view->model) conversion. For that you will need to provide a function which will generate a model/view element.

See docs for downcastAttributeToElement and upcastElementToAttribute() . In those docs, there are examples of how to set up a conversion that uses style attribute value. Upcast converter shows a more complicated example but you can simply return the value from view.

To add such converter you need to use model.Conversion#for..#add construction :

  • editor.conversion.for( 'downcast' ).add( downcastAttributeToElement( downcastConfig ) )
  • editor.conversion.for( 'upcast' ).add( upcastElementToAttribute( upcastConfig ) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM