djangocopy-pastedjango-ckeditor

Half space in django CKEditor


I am developing a website that requires an advanced text editor for Persian, and I have used CKEditor. When I copy text from Microsoft Word and paste it into CKEditor, it does not paste all the half spaces correctly.

For example, if the text of an article has 10 half spaces or somebody may call it semi space, after pasting it into the CKEditor, it might only display 7 half spaces correctly, and the rest are missing. Have you encountered a similar issue? What is your opinion?


Solution

  • This problem is caused by the entities that Microsoft Word uses to show the half space (semi-space). When users press CTRL + - to add a half space in their text content, Microsoft Word can add it, but when users copy and paste the text in django-ckeditor==6.7.1, it can't detect the half space, so it writes it like this:

    متن نمونه با نیم فاصله در کلمه میخواهم
    

    There is another shortcut to write a half space in Microsoft Word, which is CTRL + SHIFT + 2. If you use this shortcut, django-ckeditor==6.7.1 will detect the half space in your Persian content:

    متن نمونه با نیم فاصله در کلمه می‌خواهم
    

    This shortcut is hard to press when you are typing in Persian, so I installed AutoHotkey on my computer, from the AutoHotkey website. When you download and install it, right-click and in the options panel that appears, click on New and in the subpanel that appears, click on AutoHotkey Script, like in this photo:

    Add AutoHotkey script

    Then write this code in it, to use the ALT + C shortcut instead of CTRL + SHIFT + 2:

    ; Define new shortcut for ZWNJ (Alt + C)
    !c::Send {U+200C}
    

    It should look like this:

    content of AutoHotkey script

    After that, restart AutoHotkey, change your keyboard language to English, and double-click on your script on the desktop or any other directory. Now you can use the ALT + C shortcut to type a half space in Word that can be kept in django-ckeditor==6.7.1.

    Also, to edit the script, you can right-click and click on the Edit Script option.