Problem/Motivation

Ckeditor 4 supports them, and they're already available in CKEditor 5, so lets support them.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-3230230

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Issue fork ckeditor5-3230230

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bnjmnm created an issue. See original summary.

wim leers’s picture

Added this to the roadmap's Ensure CKE5 functionality matches that of Drupal core's CKE4 section at #3201824-33: Roadmap to core :)

johnwebdev’s picture

Status: Active » Needs review
StatusFileSize
new530 bytes

This patch enables table captions.

lauriii’s picture

Status: Needs review » Needs work

Thank you for the patch @johnwebdev!

I tested the patch manually and I noticed that adding a caption generates a <figure> element with data-caption attribute. This is not consistent with CKEditor 4, which would simply use <caption> element inside the <table>. I think we want the CKEditor 4 behavior here so moving back to needs work.

wim leers’s picture

Does the CKE5 table.TableCaption plugin support the configuration described in #4? We'll have to find out, and if not, we'll raise that in the upcoming meeting with the CKEditor 5 developers this Thursday :)

lauriii’s picture

It seems like the caption is added to dataCaption attribute by the image plugin. When image plugin is disabled, the caption is added to figcaption and the <table> is wrapped with <figure>, which is still not what we'd expect.

I don't think their documentation include how we could make the caption downcast to the desired markup. However, that's something we should be able to do regardless of that.

wim leers’s picture

Project: CKEditor 5 » Drupal core
Version: 1.0.x-dev » 9.3.x-dev
Component: Code » ckeditor5.module
Status: Needs work » Postponed

Just asked the CKEditor team:

It’s surprising that https://ckeditor.com/docs/ckeditor5/latest/features/table.html#table-cap... in CKEditor 5 generates <figure><table>…</table><figcaption>this is the caption</figcaption></figure> instead of CKEditor 4's <table><caption>…this is the caption</caption><tbody></table> in https://ckeditor.com/docs/ckeditor4/latest/examples/table.html. I could not find docs about this, nor issue discussions in the public repo. Could you shine a light on this? 🙏

Agreed with #6 as the solution, but I'd rather first understand why they went this way.

wim leers’s picture

Status: Postponed » Active

@Anna_CKSource responded!

This is based on the research done before we started developing CKE5 and was summarized in https://ckeditor.github.io/editor-recommendations/features/table.html.

Some further references and discussions:

We'll need to investigate this.

wim leers’s picture

Thanks, Anna! :)

Wim Leers credited Reinmar.

wim leers’s picture

Status: Active » Needs review

Analysis

@Anna_CKSource provided two discussion links:

  1. Over at https://github.com/ckeditor/ckeditor5/issues/3204#issuecomment-618289944, Alexander Schranz made the same remark. @Reinmar pointed to https://ckeditor.github.io/editor-recommendations/features/table.html for the rationale. But … that contains no discussion at all, just the conclusion, not the reasoning behind the conclusion. 😔
  2. Then over at https://github.com/ckeditor/ckeditor5/issues/3194#issuecomment-397234125, there's very high-level description by Tomasz Jakut about a generic approach that is acceptable per the HTML 5 spec for captioning of arbitrary "self-contained content". This is fine, but still not an answer.
    Further in that same issue, Maciej asks at https://github.com/ckeditor/ckeditor5/issues/3194#issuecomment-397242600

    ps.: side question what about table > caption? It looks like another choice do describe table.

    — which is basically what we are asking here.

    Tomasz responded there:

    There are several techniques for describing table. In our case we use figcaption as also the mean to describe the whole figure element. Probably it would be nice to additionally bind figcaption with table using [aria-labelledby]/[aria-describedby].

    This is again not really an answer why they chose this approach. His link to https://html.spec.whatwg.org/multipage/tables.html#table-descriptions-te... is super valuable though: it shows there are 3 distinct WHATWG-approved techniques:

    1. Prose before the table → irrelevant here, that is always possible.
    2. table > caption → the current approach used in Drupal 8|9, because this is what CKEditor 4 used
    3. table > caption > details
    4. figure > table + figcaption → the approach used in CKEditor 5

Conclusion

My conclusion from this is that the CKEditor 5 development team understandably chose the approach that is generically applicable for all the markup they need to generate.

But Drupal has a different set of requirements:

  1. it needs to care about not breaking existing sites' CSS/JS/PHP code
  2. it prefers to stick to units of semantical HTML that can be transformed on output, through its Filter API

The only <figure> markup that Drupal currently generates, is for captioned images. Drupal stores <img src=… data-caption=…> and transforms this to <figure><img src=…><figcaption>…</figcaption></figure> via the caption filter. Why? Because this makes it easy for different channels/consumers of this data to present the data in a different way; they won't have to parse the full final HTML markup. Drupal prefers structured content, that is more canonical/less coupled to one channel/easier to transform.

Therefore it would IMHO still be preferable that Drupal overrides the ckeditor5-table's table.TableCaption's default downcast (both "data" and "editing" downcast).

wim leers’s picture

Title: Enable table captions » [upstream] Enable table captions; override CKE5's default downcast to generate <table><caption></table> instead of <figure><table><figcaption></figure>
Status: Needs review » Postponed
Issue tags: +Needs upstream feature

Discussed during today's CKEditor 5 meeting.

@Reinmar confirms the above. He recommends to:

  1. add a very late stage downcast override, to avoid Drupal having to repeat the same table construction logic
  2. … but it should not be implemented as a downcast; there's a "view postfix" concept that would be a better fit
  3. @Reinmar will provide more guidance on this in the near future

Upstream, the upcasting from <table><caption></table> will be taken care of upstream; they will need that for their customers upgrading from CKEditor 4 anyway.

wim leers’s picture

Issue tags: +Needs tests

We should have test coverage to ensure that a pasted <figure><table><figcaption></figure> while not using Full HTML does not allow the <figure> to continue to exist; it should be downcast to <table><caption></table>.

IOW: document the expected behavior through test coverage.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

Per today's CKEditor 5 + Drupal meeting, both the upcast (actually, this is already working!) and downcast will be handled upstream, in https://github.com/ckeditor/ckeditor5/issues/10892.

wim leers’s picture

Issue tags: +stable blocker
wim leers’s picture

Status: Postponed » Active
Issue tags: -Needs upstream feature
Parent issue: » #3238333: Roadmap to CKEditor 5 stable in Drupal 9
Related issues: +#3269064: Update to CKEditor 5 v33.0.0

#3269064: Update to CKEditor 5 v33.0.0 landed, this is now unblocked!

See #3269064-6: Update to CKEditor 5 v33.0.0 for details/next steps.

wim leers’s picture

Status: Active » Postponed

Even though we updated to CKEditor 5 v33.0.0, the DLL build doesn't contain it yet. They acknowledged this is a problem that they will fix. So this is again blocked on upstream: https://github.com/ckeditor/ckeditor5/issues/11516.

Thanks @bnjmnm for creating that issue upstream!

wim leers’s picture

Status: Postponed » Active

There should be a new CKEditor 5 release tomorrow. That means we should already start writing a test.

bnjmnm’s picture

StatusFileSize
new6.24 KB
lauriii’s picture

Priority: Normal » Major

It seems like <table> element is now always wrapped with a <figure>. Bumping this to major based on that, even though this probably should be a critical since this is tagged as a stable blocker.

bnjmnm’s picture

Issue tags: -Needs tests
StatusFileSize
new10.25 KB

Tests are expanded and confirm

  • Editor downcast still wraps in <figure> (i believe that's fine provided it's only in the editor?)
  • Data downcast does not wrap in <figure>, caption is in the expected structure and matches CKEditor 4
  • When viewing a saved node, unlike CKEditor 4, the caption is not inside the table in <caption>. The tests are failing because of this.

SO my next step is to see why the downcast markup that has caption within table is not translating to the rendered markup.

wim leers’s picture

YAY!

Those first two bullets are indeed as expected 👍

Third bullet: do you mean when viewing a saved node inside CKEditor (i.e. editor downcast) or outside CKEditor (i.e. as visitor)?

wim leers’s picture

  1. Looks great — only nits! 🤓
  2. +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php
    @@ -0,0 +1,236 @@
    +    $this->adminUser = $this->drupalCreateUser([
    

    This doesn't need to be an "admin" user — a "content creator" is just fine!

  3. +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php
    @@ -0,0 +1,236 @@
    +      'administer filters',
    

    This permission is not needed.

  4. +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php
    @@ -0,0 +1,236 @@
    +    $this->drupalLogin($this->adminUser);
    

    This is the only place $this->adminUser is used — hence it does not need to be an object property.

  5. +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php
    @@ -0,0 +1,236 @@
    +   * Confirm tables convert to the expected markup.
    

    Übernit: s/Confirm/Confirms/

  6. +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php
    @@ -0,0 +1,236 @@
    +  public function assertTableStructureInRenderedPage() {
    

    Übernit: this and other methods could have the void return type.

bnjmnm’s picture

Status: Active » Needs review
StatusFileSize
new9.11 KB
new2.02 KB

Addresses #25 and the test failures I mentioned in #23 (just forgot to explicitly add <caption>)

wim leers’s picture

Status: Needs review » Needs work
+++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php
@@ -0,0 +1,234 @@
+  /**
+   * The user to use during testing.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $adminUser;

This should still be removed. 🤓

+++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
@@ -445,6 +447,7 @@ ckeditor5_table:
+      - <caption>

👍

bnjmnm’s picture

Status: Needs work » Needs review
StatusFileSize
new8.99 KB
new623 bytes

🤦

Here it is!

Status: Needs review » Needs work

The last submitted patch, 28: 3230230--28.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Reviewed & tested by the community

Looks great, thanks! 👍

Unrelated functional JS test failures for Layout Builder and Media → re-testing.

The last submitted patch, 23: 3230230-24.patch, failed testing. View results

  • lauriii committed 613b862 on 10.0.x
    Issue #3230230 by bnjmnm, johnwebdev, Wim Leers, lauriii, Anna_CKSource...

  • lauriii committed 7bdf3b0 on 9.4.x
    Issue #3230230 by bnjmnm, johnwebdev, Wim Leers, lauriii, Anna_CKSource...

  • lauriii committed 8dc3eb1 on 9.3.x
    Issue #3230230 by bnjmnm, johnwebdev, Wim Leers, lauriii, Anna_CKSource...
lauriii’s picture

Title: [upstream] Enable table captions; override CKE5's default downcast to generate <table><caption></table> instead of <figure><table><figcaption></figure> » Enable table captions; override CKE5's default downcast to generate <table><caption></table> instead of <figure><table><figcaption></figure>
Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 613b862 and pushed to 10.0.x. Also cherry-picked to 9.4.x and 9.3.x. Thanks!

Committed from 40000ft above the Labrador Sea on the way to DrupalCon Portland ✈️

wim leers’s picture

🦅😄

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.