html-template-tag
Version:
ES6 Tagged Template for compiling HTML template strings.
2 lines (1 loc) • 1.13 kB
JavaScript
;var e=require("html-es6cape"),t=require("html-element-attributes");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(e),a=Object.values(t.htmlElementAttributes).flat();function i(e){return a.some((function(t){return e.endsWith("".concat(t,"="))}))}var o=["action","archive","background","cite","classid","codebase","content","data","dynsrc","formaction","href","icon","imagesrcset","longdesc","lowsrc","manifest","nohref","onload","poster","popovertargetaction","profile","src","srcset","style","usemap"],c=function(e){return o.some((function(t){return e.endsWith("".concat(t,"="))||e.endsWith("".concat(t,'="'))}))};module.exports=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return e.raw.reduce((function(r,a,o){var s=t[o-1];return Array.isArray(s)?s=s.join(""):e.raw[o-1]&&e.raw[o-1].endsWith("$")?r=r.slice(0,-1):s=n.default(s),i(r)&&(r+='"',a='"'+a),c(r)&&(console.warn("[html-template-tag] Trying to interpolate inside an URI attribute. This can lead to security vulnerabilities. The interpolation has been removed.",{acc:r,subst:s,lit:a}),s=""),r+s+a}))};