Add ability not to trim trailing\leading spaces in text nodes in convertFromHtml
Currently empty text nodes are trimmed to one whitespace char. I assume it makes sense in some cases but if an entity is padded with some whitespaces, they are removed, and the appearance of the text is not as expected.
Example : convertFromHtml("<p>&nbps;&nbps;&nbps;&nbps;<a href='/home'>Link</a>&nbps;&nbps;&nbps;&nbps;</p>") results in<p> <a href='/home'>Link</a> </p>
The 'link' word that was supposed to be padded with spaces is now aligned to the left with a single spaces.
This is the relevant code :
if (text.trim() === '' && inBlock !== 'code-block') {
return getWhitespaceChunk(inEntity);
}
It would be useful to have control over this functionality.
We wanted this, too, so I made a pull request with our changes.
The issue is actually that spaces found between tags in the HTML get collapsed.
In other words, a key part of the example you gave is that the spaces are between the <p> tag and the <a> tag. In the case without the link, for example, (<p> . . . Plaintext . . . </p>), draft-convert already keeps those spaces. But if it was <p> . . . <b>Bold Text</b> . . . </p>, the spaces get consolidated to a single space.
so, how to solve this issue?
@maxwellskala Hey, it would be amazing if the PR was merged. Or if there will be some other fix for it.