An open API service indexing awesome lists of open source software.

https://github.com/thecolaber/text2html

Takes text and inserts it into the page as HTML. Pure JS.
https://github.com/thecolaber/text2html

html inserts javascript js

Last synced: about 1 year ago
JSON representation

Takes text and inserts it into the page as HTML. Pure JS.

Awesome Lists containing this project

README

          

# Text2HTML - PLEASE REPORT BUGS

## Info

Takes text and parces it with your desired options. Useful when not wanting to use DOM Parsers, insertAdjentHTML, and innerHTML.

#### Syntax:

```js
parseHTML(String text, Object options {| Boolean asList, String baseUrls |} )
```

- text - text to parse
- options
- asList - return data as a list of Nodes. defaults to false.
- baseUrls - change the base urls in src and href attributes. defaults to "".

#### Example:

```js
document.querySelector(".main").append(
...parseHTML(
`


body{
margin: 0;
color: white;
font-size: 60px;
letter-spacing: 2px;
line-height: 60px;
font-family: system-ui;
}

.nav{
width: 100%;
height: 300px;
background-color: #2b2b2b;
display: flex;
justify-content: center;
align-items: center;
}

a img{
height: 150px;
}


let a = document.querySelector("a");
a.addEventListener("click", function (e) {
if (!confirm("Are you sure you would like to visit google?")) {
e.cancelBubble = true;
e.preventDefault();
}
});

`,
{ asList: true }
)
);
```

## Supports

This function supports the following:

- Elements
- Scripts
- Styles
- Self-closing
- Attributes
- Single quotes
- Double quotes
- No quotes
- No value attributes
- Comments
- Text Nodes