draft-convert icon indicating copy to clipboard operation
draft-convert copied to clipboard

Add ability not to trim trailing\leading spaces in text nodes in convertFromHtml

Open shapiroronny opened this issue 8 years ago • 3 comments

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.

shapiroronny avatar Jun 27 '17 15:06 shapiroronny

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.

SmilinBrian avatar Sep 06 '17 22:09 SmilinBrian

so, how to solve this issue?

CXJoyce avatar Dec 07 '19 09:12 CXJoyce

@maxwellskala Hey, it would be amazing if the PR was merged. Or if there will be some other fix for it.

shaulgo avatar Jun 14 '20 13:06 shaulgo