developit / developit/htm

Ampersand escapes in text content handled differently to JSX

Đang mở
#76 11 bình luận 5 reaction 0 người được giao Xem trên GitHub
discussion help wanted
Ngôn ngữ chính
JavaScript
Star
9k
Fork
181
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## 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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.