Handle paste from office for footnotes

Created on 11 January 2024, 11 months ago
Updated 8 July 2024, 5 months ago

Problem/Motivation

If you paste from office, default <a> tags for citations and the final footnote references are added. These could be converted to to benefit from this module's functionality using the ClipboardPipeline provided by CK Editor 5.

Steps to reproduce

Paste from Word or LibreOffice Docs and the markup is pasted as is.

Proposed resolution

Implement the ClipboardPipeline to capture pasted content.

Example markup from LibreOffice:

<p style="line-height:100%;margin-bottom:0cm;">
    Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Etiam sollicitudin, ipsum eu pulvinar rutrum, tellus ipsum laoreet sapien, quis venenatis ante odio sit amet eros. Fusce neque. Suspendisse faucibus, nunc et pellentesque egestas, lacus ante convallis tellus, vitae iaculis lacus elit id tortor. Nullam tincidunt adipiscing enim.<a class="sdfootnoteanc" href="#sdfootnote1sym" name="sdfootnote1anc"><sup>1</sup></a>
</p>
<p style="line-height:100%;margin-bottom:0cm;">
    Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Suspendisse nisl elit, rhoncus eget<a class="sdfootnoteanc" href="#sdfootnote2sym" name="sdfootnote2anc"><sup>2</sup></a>, elementum ac, condimentum eget, diam. Proin magna. Donec vitae orci sed dolor rutrum auctor. Integer tincidunt.
</p>
<div id="sdfootnote1">
    <p class="sdfootnote">
        <a class="sdfootnotesym" href="#sdfootnote1anc" name="sdfootnote1sym">1</a> Footnote – 1 - Test
    </p>
</div>
<div id="sdfootnote2">
    <p class="sdfootnote">
        <a class="sdfootnotesym" href="#sdfootnote2anc" name="sdfootnote2sym">2</a> Footnote – 2 Test
    </p>
</div>

Example markup from Word:

<p>
    Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Etiam sollicitudin, ipsum eu pulvinar rutrum, tellus ipsum laoreet sapien, quis venenatis ante odio sit amet eros. Fusce neque. Suspendisse faucibus, nunc et pellentesque egestas, lacus ante convallis tellus, vitae iaculis lacus elit id tortor. Nullam tincidunt adipiscing enim.<a href="#_ftn1" name="_ftnref1" title=""><span style="font-family:&quot;Calibri&quot;,sans-serif;font-size:12.0pt;">[1]</span></a><o:p></o:p>
</p>
<p>
    Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Suspendisse nisl elit, rhoncus eget<a href="#_ftn2" name="_ftnref2" title=""><span style="font-family:&quot;Calibri&quot;,sans-serif;font-size:12.0pt;">[2]</span></a>, elementum ac, condimentum eget, diam. Proin magna. Donec vitae orci sed dolor rutrum auctor. Integer tincidunt.<o:p></o:p>
</p>
<div>
    <hr align="left" size="1" width="33%">
    <div id="ftn1">
        <p>
            <a href="#_ftnref1" name="_ftn1" title=""><span style="font-family:&quot;Calibri&quot;,sans-serif;font-size:10.0pt;">[1]</span></a> Footnote – 1 - Test<o:p></o:p>
        </p>
    </div>
    <div id="ftn2">
        <p>
            <a href="#_ftnref2" name="_ftn2" title=""><span style="font-family:&quot;Calibri&quot;,sans-serif;font-size:10.0pt;">[2]</span></a> Footnote – 2 Test<o:p></o:p>
        </p>
    </div>
</div>

Remaining tasks

  1. Implement the ClipboardPipeline. I have started this off putting the code in the right place. The function transformClipboardContent in assets/js/ckeditor5_plugins/footnotes/src/footnotesediting.js is where the work is needed.
  2. Its currently just ChatGPT written code which results in a a broken <footnotes> element.
  3. Add tests via FootnotesCkeditorPluginTest

User interface changes

No visible changes, but paste from word or libreoffice will change.

API changes

None

Data model changes

None

Feature request
Status

Fixed

Version

4.0

Component

Footnotes

Created by

🇬🇧United Kingdom scott_euser

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @scott_euser
  • Status changed to Needs work 11 months ago
  • First commit to issue fork.
  • Pipeline finished with Success
    6 months ago
    Total: 301s
    #197227
  • Pipeline finished with Success
    6 months ago
    Total: 197s
    #197335
  • Pipeline finished with Success
    6 months ago
    Total: 204s
    #202097
  • Pipeline finished with Skipped
    6 months ago
    #206952
  • Status changed to Fixed 6 months ago
  • 🇬🇧United Kingdom scott_euser

    Thanks Sam! Got this going so it also now happens before the 'Limit allowed html' strips out anything not allowed. Its going to need some more testing in reality as there may be edge cases or software that does not work, but at least having the foundation in here will be a good start.

    Also fixed eslint issues

    • scott_euser committed 1f87cc0b on 4.0.x
      Issue #3413998 by scott_euser, samsoapbox: Handle paste from office for...
  • 🇬🇧United Kingdom scott_euser

    Anyone coming across this, if you have specific issues, please create new issues with:

    1. The source html getting paste from the clipboard
    2. The software you are using
    3. Ideally a merge request looking at the commit above to see where the transformation is happening

    Thanks!

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

Production build 0.71.5 2024