The simplest html
template engine
npm install @linkorgs/html-template
or
yarn add @linkorgs/html-template
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>
}()
Use new Render (options?: object) for initialization and return an instance of Render.
mini
: Whether to compresshtml
content. As with theminify
attribute ofhtml-webpack-plugin
, usehtml-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
set (html: string)
: set the template string to be renderedcompiler (template?: string)
: Returns a prepared array of templates for therender
function to compilerender (template?: string)
: render template string and return
Detailed changes for each release are documented in the release notes.