html-template-tag
Version:
ES6 Tagged Template for compiling HTML template strings.
2 lines (1 loc) • 1.04 kB
JavaScript
import t from"html-es6cape";import{htmlElementAttributes as e}from"html-element-attributes";var r=Object.values(e).flat();function n(t){return r.some((function(e){return t.endsWith("".concat(e,"="))}))}var a=["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"],o=function(t){return a.some((function(e){return t.endsWith("".concat(e,"="))||t.endsWith("".concat(e,'="'))}))};function i(e){for(var r=[],a=1;a<arguments.length;a++)r[a-1]=arguments[a];return e.raw.reduce((function(a,i,c){var s=r[c-1];return Array.isArray(s)?s=s.join(""):e.raw[c-1]&&e.raw[c-1].endsWith("$")?a=a.slice(0,-1):s=t(s),n(a)&&(a+='"',i='"'+i),o(a)&&(console.warn("[html-template-tag] Trying to interpolate inside an URI attribute. This can lead to security vulnerabilities. The interpolation has been removed.",{acc:a,subst:s,lit:i}),s=""),a+s+i}))}export{i as default};