developit / developit/htm

Ampersand escapes in text content handled differently to JSX

Aperta
#76 11 commenti 5 reazioni 0 assegnatari Vedi su GitHub
discussion help wanted
Lingua principale
JavaScript
Stelle
9k
Fork
181
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Reproduction

With the following code:

```
import htm from "https://unpkg.com/htm@2.1.1/dist/htm.mjs";
import { h } from "https://unpkg.com/preact@8.4.2/dist/preact.mjs";
const html = htm.bind(h);

console.log(html`

<
`)
```

I get a VNode with `.children = ["<"]` — i.e. what I mean to render as `<` gets rendered as `<` instead.

## Expected results

Testing this in JSX via say , `

<
` gets transformed into `h("div", ["<"]);` as I originally expected.

I haven't poked into how they are doing this… seems like something that ultimately relies on a lookup table.

## Workaround

I am able to escape via string interpolation (e.g. `${'<'}` instead of `<`). Changing the last line in my sample code to:

```
// …

console.log(html`

${'<'}
`)
```

Results in a VNode with `.children = ["<"]` as I need. Is this the recommended style?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.