Skip to content

hq001/html-template

Repository files navigation

html-template

Build Status

html-template

The simplest html template engine

Installation

npm install @linkorgs/html-template

or

yarn add @linkorgs/html-template

Usage

import { Render } from "@linkorgs/html-template"                    // ESModule
// const { Render } = require("@linkorgs/html-template")            // commonjs 
const render = new Render()
render.render(`<div>{{ return null || '@linkorgs/html-template' }}</div>`)
// output: <div>@linkorgs/html-template</div>

2.0.1 starts to support asynchronous syntax, the basic usage is as follows

import { Render } from "@linkorgs/html-template"
const render = new Render({
  mini: true
})

void async function() {
  await render.render(`
    <div>
      {{
        return (async function() {
          return await Promise.resolve('@linkorgs/html-template')
        })();
      }}
    </div>
`)
  // output: <div>@linkorgs/html-template</div>
}()

Documentation

Use new Render (options?: object) for initialization and return an instance of Render.

options

  • mini: Whether to compress html content. As with the minify attribute of html-webpack-plugin, use html-minifier to compress HTML content. See List for optional values. The default values are as follows
{
  collapseWhitespace: true,
  removeComments: true,
  removeRedundantAttributes: true,
  removeScriptTypeAttributes: true,
  removeStyleLinkTypeAttributes: true,
  useShortDoctype: true
}

Note: If the value of mini is false, nothing will be compressed. If it is true, the above default value will be used

API

  • set (html: string): set the template string to be rendered
  • compiler (template?: string): Returns a prepared array of templates for the render function to compile
  • render (template?: string): render template string and return

Changelog

Detailed changes for each release are documented in the release notes.

LICENSE

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published