From e2f6cb5cb197cf93aa810444945ba0eff1fc1b4b Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Fri, 11 Jun 2021 09:56:36 +0300 Subject: [PATCH 1/6] test: change to number with quote --- test/test-core.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-core.spec.ts b/test/test-core.spec.ts index 622a110..79aef9f 100644 --- a/test/test-core.spec.ts +++ b/test/test-core.spec.ts @@ -547,8 +547,8 @@ test('{QuoteStyle} for width/height attrs in img', t => { tag: 'img', attrs: { src: 'https://example.com/example.png', - width: 20, - height: 20 + width: '20', + height: '20' } }; const expected = ''; From c334ef2e2695f16ea7bc80907be8d539f6fb109e Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Fri, 11 Jun 2021 09:57:18 +0300 Subject: [PATCH 2/6] fix: incorrect detect json format --- src/index.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index b975be6..0f448e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import isJSON from 'is-json'; import {Attributes, NodeText, NodeTag} from 'posthtml-parser'; import {closingSingleTagOptionEnum, closingSingleTagTypeEnum, Options, quoteStyleEnum} from '../types/index.d'; @@ -182,13 +183,8 @@ function render(tree?: Node | Node[], options: Options = {}): string { for (const [key, value] of Object.entries(object)) { if (typeof value === 'string') { - let json; - try { - json = JSON.parse(value); - } catch {} - - if (json) { - attr += ` ${key}='${value}'`; + if (isJSON(value)) { + attr += makeAttr(key, value); } else if (quoteAllAttributes || ATTRIBUTE_QUOTES_REQUIRED.test(value)) { let attrValue = value; From 76c0752b2fe388c8e91e278843a82982c3d7dcf3 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Fri, 11 Jun 2021 09:57:28 +0300 Subject: [PATCH 3/6] build: update depdev --- package-lock.json | 5 +++++ package.json | 3 +++ 2 files changed, 8 insertions(+) diff --git a/package-lock.json b/package-lock.json index 5344c33..2eefe47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6966,6 +6966,11 @@ "js-types": "^1.0.0" } }, + "is-json": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-json/-/is-json-2.0.1.tgz", + "integrity": "sha1-a+Fm0USCihMdaGiRuYPfYsOUkf8=" + }, "is-negated-glob": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-negated-glob/-/is-negated-glob-1.0.0.tgz", diff --git a/package.json b/package.json index 1eb1689..ed9e45b 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,9 @@ "html", "xml" ], + "dependencies": { + "is-json": "^2.0.1" + }, "devDependencies": { "@antfu/eslint-config-ts": "^0.6.4", "@commitlint/cli": "^12.1.1", From 85b7beca1805b53ed21612169281cb00891a8a8f Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Fri, 11 Jun 2021 10:01:54 +0300 Subject: [PATCH 4/6] fix: is-json not declare --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index 0f448e1..d74ceda 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +// @ts-ignore import isJSON from 'is-json'; import {Attributes, NodeText, NodeTag} from 'posthtml-parser'; import {closingSingleTagOptionEnum, closingSingleTagTypeEnum, Options, quoteStyleEnum} from '../types/index.d'; From aaab81da86849029ae300eeefd33f8aa16f225b1 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Fri, 11 Jun 2021 10:07:01 +0300 Subject: [PATCH 5/6] style: ignore ts error --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index d74ceda..e507ebb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -// @ts-ignore +// @ts-expect-error import isJSON from 'is-json'; import {Attributes, NodeText, NodeTag} from 'posthtml-parser'; import {closingSingleTagOptionEnum, closingSingleTagTypeEnum, Options, quoteStyleEnum} from '../types/index.d'; From aa66af1eb236694649f2e04fc76019a3ee274c6b Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Fri, 11 Jun 2021 10:08:14 +0300 Subject: [PATCH 6/6] 2.0.6 --- changelog.md | 11 +++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 6f716c1..703ae9e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,16 @@ +## 2.0.6 (2021-06-11) + +* style: ignore ts error ([aaab81d](https://github.com/posthtml/posthtml-render/commit/aaab81d)) +* fix: incorrect detect json format ([c334ef2](https://github.com/posthtml/posthtml-render/commit/c334ef2)) +* fix: is-json not declare ([85b7bec](https://github.com/posthtml/posthtml-render/commit/85b7bec)) +* build: update depdev ([76c0752](https://github.com/posthtml/posthtml-render/commit/76c0752)) +* test: change to number with quote ([e2f6cb5](https://github.com/posthtml/posthtml-render/commit/e2f6cb5)) + + + ## 2.0.5 (2021-06-10) +* 2.0.5 ([efc4a41](https://github.com/posthtml/posthtml-render/commit/efc4a41)) * test: for long test ([d019534](https://github.com/posthtml/posthtml-render/commit/d019534)) * test: invalid in htmlnano travis ([69d666b](https://github.com/posthtml/posthtml-render/commit/69d666b)) * test: more tests ([4dfa92e](https://github.com/posthtml/posthtml-render/commit/4dfa92e)) diff --git a/package-lock.json b/package-lock.json index 2eefe47..3bf1f94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "posthtml-render", - "version": "2.0.5", + "version": "2.0.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ed9e45b..90d8bab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "posthtml-render", - "version": "2.0.5", + "version": "2.0.6", "description": "Renders PostHTML Tree to HTML/XML", "license": "MIT", "repository": "posthtml/posthtml-render",