Skip to content

Spaces between words and inline elements are lost #135

Closed
@davidtheclark

Description

@davidtheclark

If I start with this JSX:

<div>
  foo <strong>bar</strong> baz
</div>

That renders to React element that with children like this:

[ 
  'foo ',
  { type: 'strong', props: { children: [Object] }, .. },
  ' baz'
]

If I then pass that element through this module, I come out with this JSX — replacing some whitespaces with * to clarify:

<div>
  foo*
  <strong>
    bar
  </strong>
  *baz
</div>

The problem is that with the reformatting, those whitespace are actually lost. End-of-line and beginning-of-line whitespace is not meaningful, so the output HTML is actually this:

<div>
  foo<strong>bar</strong>baz
</div>

If introducing all the line breaks is the preference here, I think one fix would be to add spaces as strings, e.g.

<div>
  foo{' '}
  <strong>
    bar
  </strong>
  {' '}baz
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions