ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Tables, Images, and Figures

Open KirkMunroSagent opened this issue 5 months ago • 6 comments

📝 Ask a question

I'm having a problem with tables in CKEditor (latest version: 43.1.0).

In my environment, I'm working with a lot of pre-existing HTML, loading that into CKEditor as needed to allow users to modify that content.

Some of that content includes tables that were never intended to be figures.

For example, using a simple table to list a bunch of related values in a nicely formatted manner.

CKEditor5 takes those tables, and wraps them in figures. I've looked through the docs and the GitHub repo and found a lot of discussion from the past about how the team interpreted the HTML5 standard as indicating that tables should always be represented as figures, even if they do not have an associated caption. I disagree completely with this approach. Figures can contain tables, but tables are not implicitly figures. Not in HTML, and not in formal documentation either.

At any rate, my challenge is figuring out how to undo this, because figures are centered by default, but tables outside of figures are not, so this auto-wrapping of the tables in figures changes the rendering of the content, and since much of the content passed into the editor is controlled/managed by customers, the rendered view of the content that is being passed into the editor must not change just because the editor team interpreted the HTML5 standard as requiring tables to be in figures (the customer owns the content, not the editor).

Images seem to function in a similar manner in CKEditor, but with much more flexibility. I can have an img tag in a document, and it renders properly. If I use CKEditor add a caption to the image, then the image is wrapped in a figure. If I remove the caption, it is unwrapped and becomes a plain image again. This is what I want to happen with tables, allowing vanilla tables to render using default table formatting/rendering, but if I add a caption, then and only then wrap them inside of a figure to group the table and the caption together, at which point figure formatting/rendering is used.

Does anyone have any idea how to make this happen? Does this require duplicating the CKEditor5-table plugin and modifying it to undo the hard/forced wrapping in figures that plugin seems to apply with no option to have it do otherwise? Or are there some simple settings that can be applied to change this behavior to preserve/respect what the user is doing, keeping tables as tables with an option to promote them to figures when necessary (such as when you add a caption)?

KirkMunroSagent avatar Sep 19 '24 14:09 KirkMunroSagent