aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-12-15 19:24:47 +0100
committerache <ache@ache.one>2019-12-15 19:24:47 +0100
commit1f7a9066bc69292c9f62538c9c042a2df746e0f0 (patch)
treefc9e41b6dd2e9f244f0684fad1057a4fc2eefb08
parentUpdate version (diff)
Support for custom data attributes
-rw-r--r--__tests__/index.js10
-rw-r--r--dist/index.js2
-rw-r--r--src/index.js2
3 files changed, 12 insertions, 2 deletions
diff --git a/__tests__/index.js b/__tests__/index.js
index f6d265e..fd55430 100644
--- a/__tests__/index.js
+++ b/__tests__/index.js
@@ -182,3 +182,13 @@ This is an awesome code
</code></pre>`));
});
+test('global custom attribute', 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" data-id="2"></p>`));
+});
+
diff --git a/dist/index.js b/dist/index.js
index c4ab6f6..e5782b4 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]{3,24}$/);
+ return htmlElemAttr['*'].indexOf(p) >= 0 || p.match(/^aria-[a-z]{2,24}$/) || p.match(/^data-[a-z]{2,24}$/);
};
var inScope = function inScope(_) {
diff --git a/src/index.js b/src/index.js
index 6b8a9de..3d8728b 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]{3,24}$/);
+ const isGlobal = p => htmlElemAttr['*'].indexOf(p) >= 0 || p.match(/^aria-[a-z]{2,24}$/) || p.match(/^data-[a-z]{2,24}$/);
let inScope = _ => false;