TagTag
Easy HTML templating with JS. Tagtag prints out HTML string, so it's especially useful with Node.js (works in browsers as well).
Install
npm i tagtag
Usage
Import / require
// If you're using ES modules: // If you're using CommonJS modules:const tag = ;
Using with express
// views/index.js const tag = ;const doctype html head meta title body h1 = taghtml; module ;
// server.js const express = ; const app = ; app;app;app; app;
tag(query)(...args)
'Hello world!'; // <h1>Hello world!</h1>String'world'; // <div class="hello">world</div>String'!'; // <div id="hello" class="world">!</div>
const doctype html head meta title body h1 = taghtml; String // <!DOCTYPE html><html><head><meta charset="utf-8"><title>Hello tagtag!</title></head><body><h1>Hello tagtag!</h1></body></html>
tag.html[tagName]
This gives you shortcut to tag(tagName)
for the standard HTML tag names.
tag.svg[tagName]
This gives you shortcut to tag(tagName)
for the standard SVG tag names.
Self-closing tags
Self-closing tags are detected automatically.
Escaping
Notice tagtag escapes text content and attributes by default! If you want to print out raw text, please use:
String;
or:
String;