Problem/Motivation

When pasting content from modern versions of Microsoft Word or LibreOffice into CKEditor 5, the footnote transformation logic fails. The current implementation in footnotesediting.js expects a flat structure where the footnote paragraph is a direct child of an element with an ID (e.g., [id*="ftn"] > p).

However, modern "Paste from Office" filters often wrap footnotes in a more structured format:

<ol class="footnotes">
  <li class="footnote-definition" id="ftn1">
    <a class="footnote-backlink" href="#ref-ftn1">^</a>
    <div class="footnote-content">
      <p>Footnote text here...</p>
    </div>
  </li>
</ol>

Because the <p> is nested inside a div, and the backlink <a> is a sibling rather than a child of the paragraph, the current selectors return 0 matches, leaving the raw Word HTML in the editor instead of converting it to Drupal <footnotes> tags.

Proposed resolution

Update transformClipboardContent in footnotesediting.js to use more resilient selectors:

  • Descendant Selector: Change [id*="ftn"] > p to [id*="ftn"] p to catch nested paragraphs.
  • Container Logic: Use .closest() or generalized ID selectors to find the footnote wrapper, allowing support for both <li> and <div> tags.
  • Backlink Class: Include .footnote-backlink in the anchor search logic.
  • Null Safety: Add checks to ensure anchorDiv exists before attempting DOM manipulation to prevent JS errors during paste.

Remaining tasks

  • Review the proposed Javascript changes.
  • Verify compatibility with legacy Word HTML formats.

Issue fork footnotes-3579821

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

nnevill created an issue. See original summary.

nnevill’s picture

Status: Active » Needs review

The fix is in the MR.

scott_euser’s picture

Status: Needs review » Needs work

Thanks! Can you provide full sample html, e.g. word-4.html please? https://git.drupalcode.org/issue/footnotes-3579821/-/tree/3579821-ckedit... - I had a look and what's in the issue summary is just a partial snippet so I can't use it as is. Thanks!

nnevill’s picture

Status: Needs work » Needs review

  • scott_euser committed f37a671b on 4.0.x authored by nnevill
    feat: #3579821 CKEditor 5: Paste from Word fails to parse footnotes...
scott_euser’s picture

Status: Needs review » Fixed

Thank you! Completed the test coverage and merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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