Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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(' ');
}

});
}

Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/with-ids.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions tests/svg-inline-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=/g).length === 1 );
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 () {
Expand Down