Robb Hoff
Robb Hoff

Reputation: 1910

Can the CKEditor show some html while saving it as something else?

I'd like to adapt my CKEditor so that when editing an image or other object it will show something like this in the editor view

<figure style="float: left">
  <img src="sample.jpg" />
  <figcaption>Caption</figcaption>
</figure>

On save it should transform this part to something else, for example

<node id=3 />

Does the CKEditor have any support for this, maybe through Widget, dataProcessor, or otherwise?

Upvotes: 1

Views: 129

Answers (1)

Reinmar
Reinmar

Reputation: 22023

The short answer - yes, this can be done using the CKEDITOR.dataProcessor.

First thing to notice is that if you would use the widgets system (you will be interested in the image2 plugin), then you would be able to use downcasting to transform captioned images into whatever you want. Similar thing is done in Drupal 8, because Drupal saves captioned images as <img src=".." data-caption=".." ..>. (Note: Drupal 8 uses the image2 plugin but it overrides some things like e.g. downcasting method.)

The relation between mentioned CKEDITOR.dataProcessor and the widgets system is that the widget system uses the data processor to perform upcasting and downcasting of the widgets. Upcasting means discovering elements that should be turn into widgets and performing necessary transformations on the loaded data. Downcasting is the opposite.

You can also use the data processor without using widgets. You can do that:

Upvotes: 1

Related Questions