Skip to content

Commit

Permalink
feat: JSON strings in data attributes, close #46
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed May 6, 2021
1 parent 3ab5e82 commit 5539187
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ function render(tree?: Node | Node[], options: Options = {}): string {

for (const [key, value] of Object.entries(object)) {
if (typeof value === 'string') {
if (quoteAllAttributes || ATTRIBUTE_QUOTES_REQUIRED.test(value)) {
let json;
try {
json = JSON.parse(value);
} catch {}

if (json) {
attr += ` ${key}='${value}'`;
} else if (quoteAllAttributes || ATTRIBUTE_QUOTES_REQUIRED.test(value)) {
let attrValue = value;

if (replaceQuote) {
Expand Down

0 comments on commit 5539187

Please sign in to comment.