Skip to content

InputfieldTinyMCE.js pastePreprocess (Paste Filter) and empty table cells #2335

Description

@BrendonKoz

I think the InputfieldTinyMCE's Paste Filter is great! Unfortunately, I've discovered one caveat that is fairly troublesome when used against Microsoft tabular data - empty table cells, or table header cells, (which Word or Excel generate for richtext content in the clipboard) end up getting removed. That said, because table cells are structural in their nature for the proper rendering of a table, even if empty, they should not be dropped.

I'm not sure if it's good practice to use empty anchor tags when inserting anchor points on a page (ex: <a id="jump-to-here"></a>), though it is somewhat common. Pasting rich text that contains that, I would gather, is probably more of a mistake than an intentional act. I am making an assumption though, so if expansion of my adjustment to include empty anchor elements is desirable, it may be warranted. Similarly, empty list item (<li></li>) elements do hold structure but are most often mistakes. (Just being thorough in my research!)

Since order may need to be preserved for <col> elements inside of a table for accessibility purposes, an empty tag may also be required to be kept. Technically, I don't think there should be an empty one, but if any exist, if one is dropped, the association to the rows/cells is also broken.

Anyhow, here is my suggested fix to wire/modules/Inputfield/InputfieldTinyMCE/InputfieldTinyMCE.js - this only corrects empty TD elements:
Replace the affected line, with the following:

		html = html.replaceAll(/<(?!t[dh]\b)([-a-z0-9]+)[^>]*>\s*<\/\1>/ig, ''); // remove empty tags except td/th

NOTE: I'm linking to a specific version of the file in time in case there are any modifications in the interim to compare and contrast my suggested fix.

See the forum topic for additional information on what was discovered.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions