-
Notifications
You must be signed in to change notification settings - Fork 67
Description
What is the current behavior?
Pasting the block of text from this word doc removes the superscript and subscript formatting, while preserving the bold and italics.
draftail-test.docx
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. GIFs and screenshots are very helpful too.
To reproduce, open the attached .docx file, copy it's contents, then paste them into a RichText editor on a Wagtail site. I've added Superscript and Subscript behavior to my Draftail editor via the following hook:
@hooks.register('register_rich_text_features')
def register_core_draftail_plugins(features):
# Add a "Subscript" plugin.
features.register_editor_plugin(
'draftail', 'subscript', draftail_features.InlineStyleFeature({
'type': 'SUBSCRIPT',
'icon': 'fa-subscript'
})
)
features.register_converter_rule('contentstate', 'subscript', {
'from_database_format': {'sub': InlineStyleElementHandler('SUBSCRIPT')},
'to_database_format': {'style_map': {'SUBSCRIPT': 'sub'}},
})
features.default_features.append('subscript')
# Add a "Superscript" plugin.
features.register_editor_plugin(
'draftail', 'superscript', draftail_features.InlineStyleFeature({
'type': 'SUPERSCRIPT',
'icon': 'fa-superscript'
})
)
features.register_converter_rule('contentstate', 'superscript', {
'from_database_format': {'sup': InlineStyleElementHandler('SUPERSCRIPT')},
'to_database_format': {'style_map': {'SUPERSCRIPT': 'sup'}},
})
features.default_features.append('superscript')
What is the expected behavior?
Pasting superscript and subscript text from Word should preserve the formatting in Draftail.
Which versions of Draftail + Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draftail or Draft.js?
I'm in macOS Mojave, pasting from Word for Mac 16.25 into Chrome 74. The reason I discovered this is because my clients are reporting seeing the same behavior when pasting from Word for Windows on Windows 7, most likely into IE11 (though some use Firefox). My sites run Wagtail 2.3 (which appears to use Draftail 0.17.2), but I've confirmed that this happens with Wagtail 2.5.1 as well (with whatever version of Draftail it ships with).
I'm afraid I have no knowledge of whether this worked in any previous versions of Draftail.
Additional info
I do have one odd bit of behavior to report, which may be related? I've read the Draftail docs, and it seems like I should be able to use this dict in my hook to enable the use of SUPERSCRIPT in Draftail: {'type': 'SUPERSCRIPT'}. But if I try to use only that, I see "Sup" in my toolbar, instead of X2). Pasting superscript text still fails to retain its formatting, though.
Note also that when I paste from superscript text copied from a Draftail editor, the formatting is preserved. So it's not that pasting doesn't work at all. It just doesn't seem to work when copied from Word, Outlook, or Pages.