aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-12-16 17:41:06 +0100
committerache <ache@ache.one>2019-12-16 17:41:06 +0100
commitbae8eecdb821b80f4bfc6555b477fa340c3de0f6 (patch)
tree5823af1aaffe7c7653f01d615b07315c3b2c3504
parentSupport for custom data attributes (diff)
Better attribut name convention
-rw-r--r--__tests__/index.js39
-rw-r--r--dist/index.js2
-rw-r--r--src/index.js2
3 files changed, 41 insertions, 2 deletions
diff --git a/__tests__/index.js b/__tests__/index.js
index fd55430..d6f1ed9 100644
--- a/__tests__/index.js
+++ b/__tests__/index.js
@@ -190,5 +190,44 @@ This is a test image : ![test](img.jpg){data-id=2}
const {contents} = renderExtended(extentedString);
t.deepEqual(parse(contents), parse(`<p><em>Wait</em> !
This is a test image : <img src="img.jpg" alt="test" data-id="2"></p>`));
+
+ t.notDeepEqual(parse(contents), parse(`<p><em>Wait</em> !
+This is a test image : <img src="img.jpg" alt="test"></p>`));
+});
+
+test('global custom attributes 2', t => {
+ const renderExtended = generateExtendParser({extends: {image: ['quality']}});
+ const extentedString = `*Wait* !
+This is a test image : ![test](img.jpg){data-id-node=2}
+`;
+ const {contents} = renderExtended(extentedString);
+ t.deepEqual(parse(contents), parse(`<p><em>Wait</em> !
+This is a test image : <img src="img.jpg" alt="test" data-id-node="2"></p>`));
+
+ t.notDeepEqual(parse(contents), parse(`<p><em>Wait</em> !
+This is a test image : <img src="img.jpg" alt="test"></p>`));
+});
+
+test('global custom attributes 3', t => {
+ const renderExtended = generateExtendParser({extends: {image: ['quality']}});
+ const extentedString = `*Wait* !
+This is a test image : ![test](img.jpg){data--id=2}
+`;
+ const {contents} = renderExtended(extentedString);
+ t.deepEqual(parse(contents), parse(`<p><em>Wait</em> !
+This is a test image : <img src="img.jpg" alt="test"></p>`));
+});
+
+test('global custom attributes 4', t => {
+ const renderExtended = generateExtendParser({extends: {image: ['quality']}});
+ const extentedString = `*Wait* !
+This is a test image : ![test](img.jpg){data-i=2}
+`;
+ const {contents} = renderExtended(extentedString);
+ t.deepEqual(parse(contents), parse(`<p><em>Wait</em> !
+This is a test image : <img src="img.jpg" alt="test" data-i=2></p>`));
+
+ t.notDeepEqual(parse(contents), parse(`<p><em>Wait</em> !
+This is a test image : <img src="img.jpg" alt="test"></p>`));
});
diff --git a/dist/index.js b/dist/index.js
index e5782b4..b857126 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -128,7 +128,7 @@ function filterAttributes(prop, config, type) {
};
var isGlobal = function isGlobal(p) {
- return htmlElemAttr['*'].indexOf(p) >= 0 || p.match(/^aria-[a-z]{2,24}$/) || p.match(/^data-[a-z]{2,24}$/);
+ return htmlElemAttr['*'].indexOf(p) >= 0 || p.match(/^aria-[a-z][a-z.-_0-9]*$/) || p.match(/^data-[a-z][a-z_.-0-9]*$/);
};
var inScope = function inScope(_) {
diff --git a/src/index.js b/src/index.js
index 3d8728b..9f5fd12 100644
--- a/src/index.js
+++ b/src/index.js
@@ -114,7 +114,7 @@ function filterAttributes(prop, config, type) {
const isDangerous = p => DOMEventHandler.indexOf(p) >= 0;
const isSpecific = p => type in specific && specific[type].indexOf(p) >= 0;
- const isGlobal = p => htmlElemAttr['*'].indexOf(p) >= 0 || p.match(/^aria-[a-z]{2,24}$/) || p.match(/^data-[a-z]{2,24}$/);
+ const isGlobal = p => htmlElemAttr['*'].indexOf(p) >= 0 || p.match(/^aria-[a-z][a-z.-_0-9]*$/) || p.match(/^data-[a-z][a-z_.-0-9]*$/);
let inScope = _ => false;