html-template-tag
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _htmlEs6cape=require("html-es6cape");var _htmlEs6cape2=_interopRequireDefault(_htmlEs6cape);exports["default"]=function(literals){for(var _len=arguments.length,substs=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){substs[_key-1]=arguments[_key]}return literals.raw.reduce(function(acc,lit,i){var subst=substs[i-1];if(Array.isArray(subst)){subst=subst.join("")}else{subst=(0,_htmlEs6cape2["default"])(subst)}return acc+subst+lit})};module.exports=exports["default"]; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var _htmlEs6cape=require("html-es6cape");var _htmlEs6cape2=_interopRequireDefault(_htmlEs6cape);exports["default"]=function(literals){for(var _len=arguments.length,substs=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){substs[_key-1]=arguments[_key]}return literals.raw.reduce(function(acc,lit,i){var subst=substs[i-1];if(Array.isArray(subst)){subst=subst.join("")}else if(acc.endsWith("$")){acc=acc.slice(0,-1)}else{subst=(0,_htmlEs6cape2["default"])(subst)}return acc+subst+lit})};module.exports=exports["default"]; |
{ | ||
"name": "html-template-tag", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "ES6 Tagged Template for compiling HTML template strings.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -56,2 +56,14 @@ # html-template-tag | ||
### 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). | ||
```javascript | ||
var name = `<strong>Antonio</strong>`; | ||
var string = html`Hello, $${name}!`; | ||
// "Hello, <strong>Antonio</strong>!" | ||
``` | ||
### HTML Template Pre-Compiling | ||
@@ -58,0 +70,0 @@ |
@@ -7,6 +7,9 @@ // Inspired on http://www.2ality.com/2015/01/template-strings-html.html#comment-2078932192 | ||
return literals.raw.reduce((acc, lit, i) => { | ||
var subst = substs[i - 1]; | ||
let subst = substs[i - 1]; | ||
if (Array.isArray(subst)) { | ||
subst = subst.join(""); | ||
} else if (acc.endsWith('$')) { | ||
// If the interpolation is preceded by a dollar sign, | ||
// substitution is considered safe and will not be escaped | ||
acc = acc.slice(0, -1); | ||
} else { | ||
@@ -13,0 +16,0 @@ subst = htmlEscape(subst); |
@@ -34,2 +34,7 @@ import {expect} from "chai"; | ||
it("should skip escaping HTML special characters for substituitions with double $", () => { | ||
let safeString = "<strong>Antonio</strong>" | ||
expect(html`Hello, $${safeString}!`).to.equal("Hello, <strong>Antonio</strong>!"); | ||
}) | ||
it("should generate valid HTML with an array of values", () => { | ||
@@ -36,0 +41,0 @@ let names = ["Megan", "Tiphaine", "Florent", "Hoan"]; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8195
53
105
6