imba / imba/imba.io

Need an idiomatic way to insert HTML text

Open
#192 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
83
Forks
36
PR merge metrics
No merged PRs in 30d

Description

Currently, the variables and string constants are inserted using the `innerText` property. This causes HTML encoded elements like ` ` or `»` to show up as the code, and not as a space or » character.

There's a hacky way to make that happen using the `innerHTML` property, like this:
``

However, this is not in the documentation and is more of a workaround than a standard way of doing it.

It also does not offer a way to insert the HTML without adding another level to the DOM tree.

There should be a way to insert HTML from a variable or expression without adding an extra element.

For example something like this:
```
// this can be coming from an API call
let price= "$11.95$9.99"


"Price: ", HTML price
"Add to Cart
```
Where `HTML` would be a special function or construct to add the content of the `price` as HTML.

Contributor guide

Open the contributing guide

Research direction

No source file, test, or entry point is named. Start by locating the implementation of `innerText` insertion and the template syntax for expressions, then determine how a proposed HTML-insertion construct should handle nested content and untrusted API values; done means the documented syntax inserts the example markup without an extra wrapper.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.