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
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
Comment #3
nnevillThe fix is in the MR.
Comment #4
scott_euser commentedThanks! 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!
Comment #5
nnevillComment #7
scott_euser commentedThank you! Completed the test coverage and merged.