diff --git a/lib/transformer.js b/lib/transformer.js index cef721d..1df7d67 100644 --- a/lib/transformer.js +++ b/lib/transformer.js @@ -116,13 +116,13 @@ function createClassPrefix(classPrefix) { //Prefix classes when multiple classes are present var classes = tag.attributes[classIdx][1]; var prefixedClassString = ""; - + classes = classes.replace(/[ ]+/,' '); classes = classes.split(' '); classes.forEach(function(classI){ prefixedClassString += classPrefix + classI + ' '; }); - + tag.attributes[classIdx][1] = prefixedClassString; } } @@ -155,8 +155,11 @@ function createIdPrefix(idPrefix) { var id = match.substring(5, match.length -1); return "url(#" + idPrefix + id + ")"; }); + } else if (attr[0] === 'aria-labelledby') { + attr[1] = attr[1].split(' ').map(function (id) { + return idPrefix + id; + }).join(' '); } - }); } diff --git a/tests/fixtures/with-ids.svg b/tests/fixtures/with-ids.svg index 822b61c..ca2e064 100644 --- a/tests/fixtures/with-ids.svg +++ b/tests/fixtures/with-ids.svg @@ -1,5 +1,7 @@ - + + A title + A description diff --git a/tests/svg-inline-loader.test.js b/tests/svg-inline-loader.test.js index 1081245..e0e199b 100644 --- a/tests/svg-inline-loader.test.js +++ b/tests/svg-inline-loader.test.js @@ -56,12 +56,14 @@ describe('getExtractedSVG()', function(){ var svgWithStyle = require('raw!./fixtures/with-ids.svg'); var processedStyleInsertedSVG = SVGInlineLoader.getExtractedSVG(svgWithStyle, { idPrefix: 'test.prefix-' }); - - assert.isTrue( processedStyleInsertedSVG.match(/test\.prefix-foo/g).length === 3 ); + assert.isTrue( processedStyleInsertedSVG.match(/test\.prefix-foo/g).length === 7 ); // // replaces xlink:href= assert.isTrue( processedStyleInsertedSVG.match(/xlink:href="#test.prefix-foo"/g).length === 1 ); // // replaces url(#foo) assert.isTrue( processedStyleInsertedSVG.match(/url\(#test\.prefix-foo\)/g).length === 1 ); + // replaces aria-labelledby + assert.isTrue( processedStyleInsertedSVG.match( + /aria-labelledby="test\.prefix-foo-title test\.prefix-foo-description"/g).length === 1 ); }); it('should be able to specify tags to be removed by `removingTags` option', function () {