posthtml-render
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -0,3 +1,21 @@ | ||
## <small>1.3.1 (2021-03-12)</small> | ||
* 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)) | ||
* Delete test.html ([0dea643](https://github.com/posthtml/posthtml-render/commit/0dea643)) | ||
* Update funding.yml ([86f2c9d](https://github.com/posthtml/posthtml-render/commit/86f2c9d)) | ||
## 1.3.0 (2020-11-12) | ||
* 1.3.0 ([334705d](https://github.com/posthtml/posthtml-render/commit/334705d)) | ||
* ci: package lock for ci ([4c85131](https://github.com/posthtml/posthtml-render/commit/4c85131)) | ||
@@ -4,0 +22,0 @@ * ci: remove windows ([34aa3c2](https://github.com/posthtml/posthtml-render/commit/34aa3c2)) |
@@ -27,2 +27,16 @@ declare namespace render { | ||
quoteAllAttributes: 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: 0 | 1 | 2 | ||
}; | ||
@@ -29,0 +43,0 @@ |
@@ -62,2 +62,7 @@ const SINGLE_TAGS = [ | ||
let {quoteStyle} = options; | ||
if (quoteStyle === undefined) { | ||
quoteStyle = 2; | ||
} | ||
return html(tree); | ||
@@ -68,6 +73,6 @@ | ||
if (singleRegExp.length > 0) { | ||
return singleRegExp.some(reg => reg.test(tag)) | ||
return singleRegExp.some(reg => reg.test(tag)); | ||
} | ||
if (!singleTags.includes(tag)) { | ||
if (!singleTags.includes(tag.toLowerCase())) { | ||
return false; | ||
@@ -92,3 +97,3 @@ } | ||
attr += ' ' + key + '="' + attrValue + '"'; | ||
attr += makeAttr(key, attrValue, quoteStyle); | ||
} else if (object[key] === '') { | ||
@@ -102,3 +107,3 @@ attr += ' ' + key; | ||
} else if (typeof object[key] === 'number') { | ||
attr += ' ' + key + '="' + object[key] + '"'; | ||
attr += makeAttr(key, object[key], quoteStyle); | ||
} | ||
@@ -119,2 +124,22 @@ } | ||
/** @private */ | ||
function makeAttr(key, attrValue, quoteStyle = 1) { | ||
if (quoteStyle === 1) { | ||
// Single Quote | ||
return ` ${key}='${attrValue}'`; | ||
} | ||
if (quoteStyle === 2) { | ||
// Double Quote | ||
return ` ${key}="${attrValue}"`; | ||
} | ||
// Smart Quote | ||
if (attrValue.includes('"')) { | ||
return ` ${key}='${attrValue}'`; | ||
} | ||
return ` ${key}="${attrValue}"`; | ||
} | ||
/** | ||
@@ -137,6 +162,6 @@ * HTML Stringifier | ||
if (node === undefined || | ||
node === null || | ||
node === false || | ||
node.length === 0 || | ||
Number.isNaN(node)) { | ||
node === null || | ||
node === false || | ||
node.length === 0 || | ||
Number.isNaN(node)) { | ||
return; | ||
@@ -143,0 +168,0 @@ } |
{ | ||
"name": "posthtml-render", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Renders PostHTML Tree to HTML/XML", | ||
@@ -28,15 +28,15 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-angular": "^11.0.0", | ||
"c8": "^7.3.5", | ||
"chai": "^4.2.0", | ||
"@commitlint/cli": "^12.0.1", | ||
"@commitlint/config-angular": "^12.0.1", | ||
"c8": "^7.6.0", | ||
"chai": "^4.3.3", | ||
"clinton": "^0.14.0", | ||
"conventional-changelog-cli": "^2.1.1", | ||
"husky": "^4.3.0", | ||
"jsdoc-to-markdown": "^6.0.1", | ||
"lint-staged": "^10.5.1", | ||
"mocha": "^8.2.1", | ||
"xo": "^0.34.2" | ||
"husky": "^5.1.3", | ||
"jsdoc-to-markdown": "^7.0.0", | ||
"lint-staged": "^10.5.4", | ||
"mocha": "^8.3.2", | ||
"xo": "^0.38.2" | ||
}, | ||
"types": "lib/index.d.ts" | ||
} |
[![npm][npm]][npm-url] | ||
[![node]]() | ||
[![deps][deps]][deps-url] | ||
[![tests][tests]][tests-url] | ||
[![coverage][cover]][cover-url] | ||
[![chat][chat]][chat-url] | ||
@@ -92,2 +90,3 @@ <div align="center"> | ||
|**[`replaceQuote`](#replaceQuote)**|`{Boolean}`|[`true`](#default)|Replaces quotes in attribute values with `"e;`.| | ||
|**[`quoteStyle`](#quoteStyle)**|`{0|1|2}`|[`2`](#default)|Specify the style of quote arround the attribute values| | ||
@@ -204,2 +203,29 @@ ### `singleTags` | ||
### `quoteStyle` | ||
##### `2 (Default)` | ||
Attribute values are wrapped in double quotes: | ||
```html | ||
<img src="https://example.com/example.png" onload="testFunc("test")"> | ||
``` | ||
##### `1` | ||
Attribute values are wrapped in single quote: | ||
```html | ||
<img src='https://example.com/example.png' onload='testFunc("test")'> | ||
``` | ||
##### `0` | ||
Quote style is based on attribute values (an alternative for `replaceQuote` option): | ||
```html | ||
<img src="https://example.com/example.png" onload='testFunc("test")'> | ||
``` | ||
[npm]: https://img.shields.io/npm/v/posthtml-render.svg | ||
@@ -211,5 +237,2 @@ [npm-url]: https://npmjs.com/package/posthtml-render | ||
[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 | ||
@@ -220,4 +243,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 |
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
25371
244
240