Socket
Socket
Sign inDemoInstall

posthtml-render

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml-render - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

43

changelog.md

@@ -0,4 +1,26 @@

## <small>2.0.1 (2021-05-24)</small>
* ci: drop support old node ([810c46c](https://github.com/posthtml/posthtml-render/commit/810c46c))
* ci: lock ([3c894d6](https://github.com/posthtml/posthtml-render/commit/3c894d6))
* build: add prepare script, close #53 ([dbc9b47](https://github.com/posthtml/posthtml-render/commit/dbc9b47)), closes [#53](https://github.com/posthtml/posthtml-render/issues/53)
* test: for string template ([1047ce5](https://github.com/posthtml/posthtml-render/commit/1047ce5))
* docs: typo ([fae9dad](https://github.com/posthtml/posthtml-render/commit/fae9dad))
## <small>1.3.1 (2021-03-12)</small>
* 1.3.1 ([b59d962](https://github.com/posthtml/posthtml-render/commit/b59d962))
* build: update dep dev ([acf654b](https://github.com/posthtml/posthtml-render/commit/acf654b))
* test: Case sensitivity breaks empty elements, issue #49 ([041774c](https://github.com/posthtml/posthtml-render/commit/041774c)), closes [#49](https://github.com/posthtml/posthtml-render/issues/49)
* test: Case sensitivity breaks empty elements, issue #49 ([16b00d4](https://github.com/posthtml/posthtml-render/commit/16b00d4)), closes [#49](https://github.com/posthtml/posthtml-render/issues/49)
* test: remove undefined write ([9d22fff](https://github.com/posthtml/posthtml-render/commit/9d22fff))
* fix: case sensitivity breaks empty elements, close #49 ([1a87466](https://github.com/posthtml/posthtml-render/commit/1a87466)), closes [#49](https://github.com/posthtml/posthtml-render/issues/49)
* docs: remove unused badges ([903037c](https://github.com/posthtml/posthtml-render/commit/903037c))
## 2.0.0 (2021-05-07)
* docs: add quoteStyle option ([38b2b04](https://github.com/posthtml/posthtml-render/commit/38b2b04))
* 2.0.0 ([3c898d4](https://github.com/posthtml/posthtml-render/commit/3c898d4))
* docs: description node property closeAs, issue #48 ([5979fc9](https://github.com/posthtml/posthtml-render/commit/5979fc9)), closes [#48](https://github.com/posthtml/posthtml-render/issues/48)

@@ -8,11 +30,24 @@ * type: add node property closeAs, issue #48 ([00ec9b0](https://github.com/posthtml/posthtml-render/commit/00ec9b0)), closes [#48](https://github.com/posthtml/posthtml-render/issues/48)

* test: node property closeAs, issue #48 ([f561e6b](https://github.com/posthtml/posthtml-render/commit/f561e6b)), closes [#48](https://github.com/posthtml/posthtml-render/issues/48)
* test: quoteStyle option ([18d31c0](https://github.com/posthtml/posthtml-render/commit/18d31c0))
* feat: add node property closeAs, close #48 ([6892ede](https://github.com/posthtml/posthtml-render/commit/6892ede)), closes [#48](https://github.com/posthtml/posthtml-render/issues/48)
* feat: add type definition for quoteStyle ([3ee8d58](https://github.com/posthtml/posthtml-render/commit/3ee8d58))
* feat: implement quoteStyle option ([903300f](https://github.com/posthtml/posthtml-render/commit/903300f))
* feat: JSON strings in data attributes, close #46 ([5539187](https://github.com/posthtml/posthtml-render/commit/5539187)), closes [#46](https://github.com/posthtml/posthtml-render/issues/46)
* merge: from master ([3ab5e82](https://github.com/posthtml/posthtml-render/commit/3ab5e82))
* refactor: migrate to typescript ([9eaaca4](https://github.com/posthtml/posthtml-render/commit/9eaaca4))
## <small>1.3.1 (2021-03-12)</small>
* 1.3.1 ([b59d962](https://github.com/posthtml/posthtml-render/commit/b59d962))
* Delete test.html ([0dea643](https://github.com/posthtml/posthtml-render/commit/0dea643))
* Update funding.yml ([86f2c9d](https://github.com/posthtml/posthtml-render/commit/86f2c9d))
* build: update dep dev ([acf654b](https://github.com/posthtml/posthtml-render/commit/acf654b))
* test: Case sensitivity breaks empty elements, issue #49 ([041774c](https://github.com/posthtml/posthtml-render/commit/041774c)), closes [#49](https://github.com/posthtml/posthtml-render/issues/49)
* test: Case sensitivity breaks empty elements, issue #49 ([16b00d4](https://github.com/posthtml/posthtml-render/commit/16b00d4)), closes [#49](https://github.com/posthtml/posthtml-render/issues/49)
* test: quoteStyle option ([18d31c0](https://github.com/posthtml/posthtml-render/commit/18d31c0))
* test: remove undefined write ([9d22fff](https://github.com/posthtml/posthtml-render/commit/9d22fff))
* fix: case sensitivity breaks empty elements, close #49 ([1a87466](https://github.com/posthtml/posthtml-render/commit/1a87466)), closes [#49](https://github.com/posthtml/posthtml-render/issues/49)
* docs: add quoteStyle option ([38b2b04](https://github.com/posthtml/posthtml-render/commit/38b2b04))
* docs: remove unused badges ([903037c](https://github.com/posthtml/posthtml-render/commit/903037c))
* feat: add type definition for quoteStyle ([3ee8d58](https://github.com/posthtml/posthtml-render/commit/3ee8d58))
* feat: implement quoteStyle option ([903300f](https://github.com/posthtml/posthtml-render/commit/903300f))

@@ -19,0 +54,0 @@

@@ -1,6 +0,75 @@

import { Node } from 'posthtml-parser';
import { Options } from './types';
import { NodeText, NodeTag } from 'posthtml-parser';
declare function render(tree: Node | Node[], options?: Options): string;
enum closingSingleTagOptionEnum {
tag = 'tag',
slash = 'slash',
default = 'default',
closeAs = 'closeAs'
}
enum closingSingleTagTypeEnum {
tag = 'tag',
slash = 'slash',
default = 'default'
}
enum quoteStyleEnum {
Smart,
Single,
Double
}
type Options = {
/**
* Custom single tags (selfClosing).
*
* @default []
*/
singleTags?: Array<string | RegExp>;
/**
* Closing format for single tag.
*
* Formats:
*
* tag: `<br></br>`, slash: `<br />`, default: `<br>`
*
*/
closingSingleTag?: closingSingleTagOptionEnum;
/**
* If all attributes should be quoted.
* Otherwise attributes will be unquoted when allowed.
*
* @default true
*/
quoteAllAttributes?: boolean;
/**
* Replaces quotes in attribute values with `&quote;`.
*
* @default true
*/
replaceQuote?: boolean;
/**
* Quote style
*
* 0 - Smart quotes
* <img src="https://example.com/example.png" onload='testFunc("test")'>
* 1 - Single quotes
* <img src='https://example.com/example.png' onload='testFunc("test")'>
* 2 - double quotes
* <img src="https://example.com/example.png" onload="testFunc("test")">
*
* @default 2
*/
quoteStyle?: quoteStyleEnum;
};
declare type Node = NodeText | NodeTag & {
closeAs?: closingSingleTagTypeEnum;
};
declare function render(tree?: Node | Node[], options?: Options): string;
export default render;

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkRNXZSRHUjs = require('./chunk-RNXZSRHU.js');var b=["area","base","br","col","command","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"],E=/[\t\n\f\r "'`=<>]/,k={singleTags:b,closingSingleTag:void 0,quoteAllAttributes:!0,replaceQuote:!0,quoteStyle:_chunkRNXZSRHUjs.c.Double};function N(f,o={}){var c;o=_chunkRNXZSRHUjs.a.call(void 0, _chunkRNXZSRHUjs.a.call(void 0, {},k),o);let{singleTags:i,closingSingleTag:m,quoteAllAttributes:d,replaceQuote:A,quoteStyle:a}=o,l=(c=i==null?void 0:i.filter(r=>r instanceof RegExp))!=null?c:[];return Array.isArray(f)||(f=[f]),s(f);function s(r){let e="";for(let t of r){if(t==null||typeof t=="string"&&t.length===0||Number.isNaN(t))break;if(Array.isArray(t)){e+=s(t);break}if(typeof t=="string"||typeof t=="number"){e+=t;break}if(!Array.isArray(t.content)){e+=t.content;break}if(t.tag===!1){e+=s(t.content);break}let n=typeof t.tag=="string"?t.tag:"div";if(e+=`<${n}`,t.attrs&&(e+=$(t.attrs)),y(n)){switch(m){case"tag":e+=`></${n}>`;break;case"slash":e+=" />";break;default:e+=">"}t.content&&(e+=s(t.content))}else e+=`>${s(t.content)}</${n}>`}return e}function y(r){return l.length>0?l.some(e=>e.test(r)):!!(i==null?void 0:i.includes(r))}function $(r){let e="";for(let t in r)if(typeof r[t]=="string")if(d||E.test(r[t])){let n=r[t];A&&(n=r[t].replace(/"/g,"&quot;")),e+=g(t,n,a)}else r[t]===""?e+=" "+t:e+=" "+t+"="+r[t];else r[t]==="true"?e+=` ${t}`:typeof r[t]=="number"&&(e+=g(t,r[t],a));return e}function g(r,e,t=1){return t===1?` ${r}='${e}'`:t===2?` ${r}="${e}"`:e.includes('"')?` ${r}='${e}'`:` ${r}="${e}"`}}var T=N;exports.default = T;
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var Q=Object.defineProperty;var w=Object.prototype.hasOwnProperty;var y=Object.getOwnPropertySymbols,D=Object.prototype.propertyIsEnumerable;var g=(a,f,r)=>f in a?Q(a,f,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[f]=r,p=(a,f)=>{for(var r in f||(f={}))w.call(f,r)&&g(a,r,f[r]);if(y)for(var r of y(f))D.call(f,r)&&g(a,r,f[r]);return a};var u;(function(l){l.tag="tag",l.slash="slash",l.default="default",l.closeAs="closeAs"})(u||(u={}));var i;(function(s){s.tag="tag",s.slash="slash",s.default="default"})(i||(i={}));var b;(function(s){s[s.Smart=0]="Smart",s[s.Single=1]="Single",s[s.Double=2]="Double"})(b||(b={}));var I=["area","base","br","col","command","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"],U=/[\t\n\f\r "'`=<>]/,_={singleTags:I,closingSingleTag:void 0,quoteAllAttributes:!0,replaceQuote:!0,quoteStyle:b.Double};function j(a,f={}){var x;f=p(p({},_),f);let{singleTags:r,closingSingleTag:s,quoteAllAttributes:l,replaceQuote:k,quoteStyle:$}=f,h=(x=r==null?void 0:r.filter(n=>n instanceof RegExp))!=null?x:[];return Array.isArray(a)||(a||(a=""),a=[a]),d(a);function d(n){let t="";for(let e of n){if(e==null||typeof e=="string"&&e.length===0||Number.isNaN(e))break;if(Array.isArray(e)){t+=d(e);break}if(typeof e=="string"||typeof e=="number"){t+=e;continue}if(Array.isArray(e.content)||(e.content||(e.content=""),e.content=[e.content]),e.tag===!1){t+=d(e.content);break}let o=typeof e.tag=="string"?e.tag:"div";t+=`<${o}`,e.attrs&&(t+=m(e.attrs));let c={[i.tag]:`></${o}>`,[i.slash]:" />",[i.default]:">"};if(R(o)){switch(s){case u.tag:t+=c[i.tag];break;case u.slash:t+=c[i.slash];break;case u.closeAs:t+=c[e.closeAs?i[e.closeAs]:i.default];break;default:t+=c[i.default]}e.content&&(t+=d(e.content))}else if(s===u.closeAs&&e.closeAs){let A=e.closeAs?i[e.closeAs]:i.default;t+=`${c[A]}${d(e.content)}`}else t+=`>${d(e.content)}</${o}>`}return t}function R(n){return h.length>0?h.some(t=>t.test(n)):!!(r==null?void 0:r.includes(n.toLowerCase()))}function m(n){let t="";for(let[e,o]of Object.entries(n))if(typeof o=="string"){let c;try{c=JSON.parse(o)}catch (e2){}if(c)t+=` ${e}='${o}'`;else if(l||U.test(o)){let A=o;k&&(A=o.replace(/"/g,"&quot;")),t+=N(e,A,$)}else o===""?t+=` ${e}`:t+=` ${e}=${o}`}else o===!0?t+=` ${e}`:typeof o=="number"&&(t+=N(e,o,$));return t}function N(n,t,e=1){return e===1?` ${n}='${t}'`:e===2?` ${n}="${t}"`:typeof t=="string"&&t.includes('"')?` ${n}='${t}'`:` ${n}="${t}"`}}var C=j;exports.default = C;
{
"name": "posthtml-render",
"version": "2.0.0",
"version": "2.0.1",
"description": "Renders PostHTML Tree to HTML/XML",

@@ -17,3 +17,4 @@ "license": "MIT",

"test": "xo && c8 ava",
"pretest": "clinton"
"pretest": "clinton",
"prepare": "npm run build"
},

@@ -20,0 +21,0 @@ "files": [

[![npm][npm]][npm-url]
[![node]]()
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]

@@ -251,5 +249,2 @@ <div align="center">

[deps]: https://david-dm.org/posthtml/posthtml-render.svg
[deps-url]: https://david-dm.org/posthtml/posthtml-render
[tests]: http://img.shields.io/travis/posthtml/posthtml-render.svg

@@ -260,4 +255,1 @@ [tests-url]: https://travis-ci.org/posthtml/posthtml-render

[cover-url]: https://coveralls.io/github/posthtml/posthtml-render
[chat]: https://badges.gitter.im/posthtml/posthtml.svg
[chat-url]: https://gitter.im/posthtml/posthtml
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡ī¸ by Socket Inc