@linkorgs/html-template

simple html template engine

Usage no npm install needed!

<script type="module">
  import linkorgsHtmlTemplate from 'https://cdn.skypack.dev/@linkorgs/html-template';
</script>

README

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