Skip to content

Commit c334ef2

Browse files
committed
fix: incorrect detect json format
1 parent e2f6cb5 commit c334ef2

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import isJSON from 'is-json';
12
import {Attributes, NodeText, NodeTag} from 'posthtml-parser';
23
import {closingSingleTagOptionEnum, closingSingleTagTypeEnum, Options, quoteStyleEnum} from '../types/index.d';
34

@@ -182,13 +183,8 @@ function render(tree?: Node | Node[], options: Options = {}): string {
182183

183184
for (const [key, value] of Object.entries(object)) {
184185
if (typeof value === 'string') {
185-
let json;
186-
try {
187-
json = JSON.parse(value);
188-
} catch {}
189-
190-
if (json) {
191-
attr += ` ${key}='${value}'`;
186+
if (isJSON(value)) {
187+
attr += makeAttr(key, value);
192188
} else if (quoteAllAttributes || ATTRIBUTE_QUOTES_REQUIRED.test(value)) {
193189
let attrValue = value;
194190

0 commit comments

Comments
 (0)