#2830·draft-js

Whitespaces getting trimmed when I try to render from convertFromHtml

Author: vikasrungta92Created Feb 18, 2021Updated Dec 3, 2022
#### Do you want to request a *feature* or report a *bug*? Bug/Feature #### What is the current behaviour? My application heavily depends on DraftJS. I am generating the editorState using **convertFromHtml** API. I am passing in the HTML text which contains the whitespaces at both end of the text. Following are behaviour observed:(consider '-' as a whitespace) 1. When I pass the HTML : **---This is Amazing.---** Within content blocks I can see the text value as : **"---This is Amazing.---" => as expected** Demo: [link](https://codepen.io/vikasrungta92-1/pen/MWbooYo) 2. Passed HTML: **---This is Amazing.---** (**Amazing** is encapsulated with em tag) Within content blocks I can see the text value as : **"---This is Amazing.---" => as expected** Demo: [link](https://codepen.io/vikasrungta92-1/pen/LYbLLVX) 3. But, When the passed HTML is : **---This is Amazing.---** (**This** is encapsulated with em tag) Text in content block is shown as: **''This is Amazing."** => Which is incorrect Demo: [link](https://codepen.io/vikasrungta92-1/pen/wvoeeKM) That is, when we pass the html where the just after the whitespace, HTML tag element is present then all the whitespaces are dropped. **Note:** That in demo, one whitespace is getting dropped each time. I am not sure why the whitespaces are getting dropped from HTML. Scenarios Tested but no luck: * Replaced the leading and trailing whitespaces with **&nbdp;** * Used "white-space: pre" in CSS. * Used **pre** HTML tag. Can anyone please guide me if I am missing anything here? It is important for me to retain these whitespaces as the content/HTML which is passed are critical content which we cannot drop. Or, is there any workaround I can use to make it work? **Version Used:** **Chrome**: 88.0.4324.150 **DraftJS**: 0.10.x **Mac/Windows**: latest Thanks in advance.

Source: facebookarchive/draft-js