developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.7k stars 170 forks source link

(Question) How to ensure a whitespace between two elements? #202

Closed jakub-g closed 3 years ago

jakub-g commented 3 years ago

I've been playing with htm, and I have prettier in my repo which formats code automatically.

I'm struggling to output a space between two elements; sometimes I end up with prettier formatting code like this:

      html`<span>long text long text long text</span>
      <span>foor bar</span>`

I want a single space between the two spans, but regular spaces get collapsed; and &nbsp; is escaped and output literally as &nbsp;.

Is there a clean solution to this?

timonson commented 3 years ago

I would love to hear an answer to this question, too.

antelle commented 3 years ago

${' '} seems to work: jsfiddle

html`<div>
  <span>sp</span>
  ${' '}
  <span>ace</span>
</div>`
developit commented 3 years ago

Yep, the expression with a space character is the way to go here, since it's the same behavior as JSX.