From 75eacf9f5d977a35c5283fe32d1de676b3ee3a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C3=87ak=C4=B1l?= Date: Fri, 30 Nov 2018 13:41:40 +0300 Subject: [PATCH 1/4] Added custom JSX attribute generation --- format/html.js | 4 +++- test/index.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/format/html.js b/format/html.js index a57c745..a3dcb18 100644 --- a/format/html.js +++ b/format/html.js @@ -229,7 +229,9 @@ function formatAttributes(outNode, profile) { attrValue = outNode.renderFields(attr.value); } - return ` ${attrName}=${profile.quote(attrValue)}`; + return attr.options.before && attr.options.after + ? ` ${attrName}={${attr.value}}` + : ` ${attrName}=${profile.quote(attrValue)}`; }).join(''); } diff --git a/test/index.js b/test/index.js index 2272c61..ae13069 100644 --- a/test/index.js +++ b/test/index.js @@ -15,5 +15,6 @@ describe('Main formatter', () => { assert.equal(expand('a>b', 'html'), ''); assert.equal(expand('a>b', 'slim'), 'a\n\tb'); assert.equal(expand('a>b', 'haml'), '%a\n\t%b'); + assert.equal(expand('a[foo={bar}]>b[foo=foo]', 'html'), ''); }); }); From 7054fa33b1686a34d0f741cd8fbc27e0da152a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C3=87ak=C4=B1l?= Date: Fri, 30 Nov 2018 17:00:28 +0300 Subject: [PATCH 2/4] Update html.js --- format/html.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/format/html.js b/format/html.js index a3dcb18..8185dc0 100644 --- a/format/html.js +++ b/format/html.js @@ -230,7 +230,7 @@ function formatAttributes(outNode, profile) { } return attr.options.before && attr.options.after - ? ` ${attrName}={${attr.value}}` + ? ` ${attrName}={${attrValue}}` : ` ${attrName}=${profile.quote(attrValue)}`; }).join(''); } @@ -315,4 +315,4 @@ function getFormatOptions(options) { const format = Object.assign({}, options && options.format); format.comment = Object.assign({}, commentOptions, format.comment); return format; -} \ No newline at end of file +} From 787e9678732c897de6e8d2588474a54c64c11dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C3=87ak=C4=B1l?= Date: Fri, 30 Nov 2018 17:34:55 +0300 Subject: [PATCH 3/4] Format document for indentation --- format/html.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/format/html.js b/format/html.js index 8185dc0..819c74a 100644 --- a/format/html.js +++ b/format/html.js @@ -229,9 +229,9 @@ function formatAttributes(outNode, profile) { attrValue = outNode.renderFields(attr.value); } - return attr.options.before && attr.options.after - ? ` ${attrName}={${attrValue}}` - : ` ${attrName}=${profile.quote(attrValue)}`; + return attr.options.before && attr.options.after + ? ` ${attrName}={${attrValue}}` + : ` ${attrName}=${profile.quote(attrValue)}`; }).join(''); } From c9a379c4b0144c4135f524d39682ec19e09a3fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C3=87ak=C4=B1l?= Date: Sat, 1 Dec 2018 04:13:58 +0300 Subject: [PATCH 4/4] Mimics profile.quote method --- format/html.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format/html.js b/format/html.js index 819c74a..b7f06d2 100644 --- a/format/html.js +++ b/format/html.js @@ -230,7 +230,7 @@ function formatAttributes(outNode, profile) { } return attr.options.before && attr.options.after - ? ` ${attrName}={${attrValue}}` + ? ` ${attrName}=${attr.options.before+attrValue+attr.options.after}` : ` ${attrName}=${profile.quote(attrValue)}`; }).join(''); }