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

https://github.com/rohitnairtech/inhtml

Lightweight html generator to create sever-side-rendering pages with ease
https://github.com/rohitnairtech/inhtml

Last synced: about 2 months ago
JSON representation

Lightweight html generator to create sever-side-rendering pages with ease

Awesome Lists containing this project

README

        

# inHTML

![npm](https://img.shields.io/npm/v/inhtml?style=for-the-badge)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/inhtml?style=for-the-badge)
![npm](https://img.shields.io/npm/dt/inhtml?style=for-the-badge)
![NPM](https://img.shields.io/npm/l/inhtml?style=for-the-badge)

inHTML is a lightweight HTML templating engine written in NodeJS. It allows you to pre-render HTML templates with ease using simple placeholders and partials.

## Features

- Lightweight and fast HTML rendering
- Supports placeholders using `#{variableName}`
- Supports partial templates using `#{>partialName}`
- Optional HTML escaping to prevent XSS

## Installation

Use the package manager [npm](https://www.npmjs.com/) to install inHTML.

```bash
npm install inhtml
```

## Usage

### Basic Example

```html

Hi, #{name}


```

```javascript
const inHTML = require('inhtml');
const welcomePage = inHTML('./welcome.html');

const finalHTML = welcomePage.render({
link: 'https://github.com/rohitnairtech',
name: 'Rohit Nair'
});

console.log(finalHTML);
// Output: '

Hi, Rohit Nair

'
```

---

### Using Partials

You can reuse HTML templates using partials with `#{>partialName}`.

```html

Welcome, #{name}!


```

```html


#{>header}

Your profile is ready.



```

```javascript
const inHTML = require('inhtml');
const layoutPage = inHTML('./layout.html', {
partials: {
header: '

Welcome, #{name}!

'
}
});

const finalHTML = layoutPage.render({ name: 'Rohit' });
console.log(finalHTML);
// Output: '


Welcome, Rohit!


Your profile is ready.


'
```

---

### HTML Escaping

To prevent XSS attacks, you can enable HTML escaping.

```javascript
const inHTML = require('inhtml');
const page = inHTML('./welcome.html', { escapeHtml: true });

const finalHTML = page.render({
name: 'alert("XSS")',
link: 'https://example.com'
});

console.log(finalHTML);
// Output: '

Hi, <script>alert("XSS")</script>

'
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License

[ISC](https://www.isc.org/)