All Projects → AntonioVdlC → html-template-tag

AntonioVdlC / html-template-tag

Licence: MIT license
📄 - ES6 Tagged Template for compiling HTML template strings

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to html-template-tag

Oboe
🗄 A simple tool to convert an Obsidian vault into a static directory of HTML files.
Stars: ✭ 168 (+273.33%)
Mutual labels:  html-template
Html Templates
100 (one hundred) simple and elegant HTML templates 💯
Stars: ✭ 240 (+433.33%)
Mutual labels:  html-template
iDocs
iDocs is one page documentation html template which helps you to create your offline and online documentation for your themes, templates, plugins and software.
Stars: ✭ 75 (+66.67%)
Mutual labels:  html-template
Startmin
Admin dashboard template for Bootstrap
Stars: ✭ 192 (+326.67%)
Mutual labels:  html-template
Fatfree
A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
Stars: ✭ 2,504 (+5464.44%)
Mutual labels:  html-template
Resume
🐳 一个简洁的橙色调个人简介
Stars: ✭ 60 (+33.33%)
Mutual labels:  html-template
Common Tags
🔖 Useful template literal tags for dealing with strings in ES2015+
Stars: ✭ 1,761 (+3813.33%)
Mutual labels:  html-template
Aris
Aris - A fast and powerful tool to write HTML in JS easily. Includes syntax highlighting, templates, SVG, CSS autofixing, debugger support and more...
Stars: ✭ 61 (+35.56%)
Mutual labels:  html-template
Horrorshow Rs
A macro-based html builder for rust
Stars: ✭ 228 (+406.67%)
Mutual labels:  html-template
static-html-template
静态页面网站快速开发环境,支持自动刷新页面,less样式预处理。
Stars: ✭ 19 (-57.78%)
Mutual labels:  html-template
Gentelella Rtl
Free RTL Bootstrap 3 Admin Template
Stars: ✭ 194 (+331.11%)
Mutual labels:  html-template
Ionic Starter Template
Reinventing the wheel, again! Sorry Ionic Team... but there are many newbies learning on Youtube!
Stars: ✭ 208 (+362.22%)
Mutual labels:  html-template
about.me
Single Page Resume Template
Stars: ✭ 20 (-55.56%)
Mutual labels:  html-template
Express Es6 Template Engine
Rendering engine for Express that uses ES6 javascript string templates as syntax.
Stars: ✭ 175 (+288.89%)
Mutual labels:  html-template
Nginxy
FancyIndex Theme for Nginx same appearance of Apaxy for apache
Stars: ✭ 34 (-24.44%)
Mutual labels:  html-template
Instapack
All-in-one TypeScript and Sass compiler for web applications! 📦 🚀
Stars: ✭ 131 (+191.11%)
Mutual labels:  html-template
RazorTemplating
Razor Templating Engine to render Razor Views(.cshtml files) to String in Console, Web, Service, Desktop workloads in .NET Core 3+
Stars: ✭ 216 (+380%)
Mutual labels:  html-template
template-string-optimize-loader
template string optimize loader module for webpack
Stars: ✭ 15 (-66.67%)
Mutual labels:  template-string
crawler-project
Google资深工程师深度讲解Go语言 爬虫项目。
Stars: ✭ 54 (+20%)
Mutual labels:  html-template
HTML-templating-with-Google-Apps-Script
Use data from your spreadsheets to build a webpage or a client-side app ✨
Stars: ✭ 55 (+22.22%)
Mutual labels:  html-template

html-template-tag

version issues downloads license

ES6 Tagged Template for compiling HTML template strings.

Installation

This package is distributed via npm:

npm install html-template-tag

Usage

String Interpolation

At its core, this module just performs simple ES6 string interpolation.

var html = require("html-template-tag");
// - or - import { html } from "html-template-tag";

var name = `Antonio`;
var string = html`Hello, ${name}!`;
// "Hello, Antonio!"

Nevertheless, it escapes HTML special characters without refraining its use in loops!

var html = require("html-template-tag");
// - or - import { html } from "html-template-tag";

var names = ["Antonio", "Megan", "/><script>alert('xss')</script>"];
var string = html`
	<ul>
		${names.map((name) => html`
			<li>Hello, ${name}!</li>
		`)}
	</ul>
`;
// "<ul><li>Hello, Antonio!</li><li>Hello, Megan!</li><li>Hello, /&gt;&lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;!</li></ul>"

Skip autoscaping

You can use double dollar signs in interpolation to mark the value as safe (which means that this variable will not be escaped).

var name = `<strong>Antonio</strong>`;
var string = html`Hello, $${name}!`;
// "Hello, <strong>Antonio</strong>!"

HTML Template Pre-Compiling

This small module can also be used to pre-compile HTML templates:

var html = require("html-template-tag");
// - or - import { html } from "html-template-tag";

var data = {
	count: 2,
	names: ["Antonio", "Megan"]
};

var template = ({names}) => html`
	<ul>
		${names.map((name) => html`
			<li>Hello, ${name}!</li>
		`)}
	</ul>
`;

var string = template(data);
/* 
	"
	<ul>
		<li>Hello, Antonio!</li>
		<li>Hello, Megan!</li>
	</ul>
	"
*/

NB: The formating of the string literal is kept.

License

MIT

Thanks

The code for this module has been heavily inspired on Axel Rauschmayer's post on HTML templating with ES6 template strings and Stefan Bieschewski's comment.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].