Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #468 from stephanebachelier/svg-fragment
Browse files Browse the repository at this point in the history
Add support for svg fragment
  • Loading branch information
sindresorhus committed Nov 2, 2014
2 parents eebe086 + b095375 commit 1b5fcef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _defaultPatterns = {
'Update the HTML with the new css filenames'
],
[
/<img[^\>]*[^\>\S]+src=['"]([^"']+)["']/gm,
/<img[^\>]*[^\>\S]+src=['"]([^'"\)#]+)(#.+)?["']/gm,
'Update the HTML with the new img filenames'
],
[
Expand Down Expand Up @@ -65,16 +65,20 @@ var _defaultPatterns = {
'Update the HTML with the new object filenames'
],
[
/<image[^\>]*[^\>\S]+xlink:href=['"]([^"']+)["']/gm,
/<image[^\>]*[^\>\S]+xlink:href=['"]([^"'#]+)(#.+)?["']/gm,
'Update the HTML with the new image filenames for svg xlink:href links'
],
[
/<image[^\>]*[^\>\S]+src=['"]([^"']+)["']/gm,
/<image[^\>]*[^\>\S]+src=['"]([^'"\)#]+)(#.+)?["']/gm,
'Update the HTML with the new image filenames for src links'
],
[
/<(?:img|source)[^\>]*[^\>\S]+srcset=['"]([^"'\s]+)(?:\s\d[mx])["']/gm,
'Update the HTML with the new image filenames for srcset links'
],
[
/<(?:use|image)[^\>]*[^\>\S]+xlink:href=['"]([^'"\)#]+)(#.+)?["']/gm,
'Update the HTML within the <use> tag when referencing an external url with svg sprites as in svg4everybody'
]
],
css: [
Expand Down
24 changes: 24 additions & 0 deletions test/test-fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,30 @@ describe('FileProcessor', function () {
replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<source srcset="' + filemapping['app/[email protected]'] + ' 2x" />');
});

it('should replace svg src reference with revved version for img tag', function () {
var content = '<img src="image.svg#symbol">';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<img src="' + filemapping['app/image.svg'] + '#symbol">');
});

it('should replace svg src reference with revved version for image tag', function () {
var content = '<image src="image.svg#symbol">';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<image src="' + filemapping['app/image.svg'] + '#symbol">');
});

it('should replace use xlink:href reference with revved version for svg <use> tag', function () {
var content = '<svg><use xlink:href="image.svg#symbol"></svg>';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<svg><use xlink:href="' + filemapping['app/image.svg'] + '#symbol"></svg>');
});

it('should replace image xlink:href reference with revved version for svg <image> tag', function () {
var content = '<svg><image xlink:href="image.svg#symbol"></svg>';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<svg><image xlink:href="' + filemapping['app/image.svg'] + '#symbol"></svg>');
});
});

describe('css type', function () {
Expand Down

0 comments on commit 1b5fcef

Please sign in to comment.