From c085114ebf075f3436f4a5eceacf7e96d5b89f40 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 31 Jul 2016 15:18:25 +0100 Subject: [PATCH] fix: ensure svg viewBox is kept Fixes #102 Use lowerCaseAttributeNames=false when SVG present --- lib/index.js | 7 ++++- lib/svgo-config.js | 39 -------------------------- lib/tasks/svg.js | 14 +++++---- test/fixtures/inline-svg.result.html | 2 +- test/fixtures/svg-compress.result.html | 2 +- test/fixtures/svg-viewbox.result.html | 1 + test/fixtures/svg-viewbox.src.html | 5 ++++ 7 files changed, 22 insertions(+), 48 deletions(-) delete mode 100644 lib/svgo-config.js create mode 100644 test/fixtures/svg-viewbox.result.html create mode 100644 test/fixtures/svg-viewbox.src.html diff --git a/lib/index.js b/lib/index.js index ff27167..c5af86a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -251,10 +251,15 @@ function main() { // if we spot some SVG elements in the source, // then we'll parse as XML to correctly get the SVG - if (body.indexOf(''; + // console.log(Object.keys(svg.attribs).map(_ => `${_}="${svg.attribs[_]}"`)); + var top = ''; source = top + source + ''; @@ -31,13 +31,15 @@ function resolve(inliner, todo, $) { debug('svg failed', result.error); return; } - debug('optimised again'); + debug('optimisation complete'); $svg.replaceWith(result.data); }); + inliner.jobs.done.svg(); + resolve(); }); }); -} \ No newline at end of file +} diff --git a/test/fixtures/inline-svg.result.html b/test/fixtures/inline-svg.result.html index 6618b9f..a54bc1b 100644 --- a/test/fixtures/inline-svg.result.html +++ b/test/fixtures/inline-svg.result.html @@ -1 +1 @@ - inline svg little red racing car + inline svg little red racing car diff --git a/test/fixtures/svg-compress.result.html b/test/fixtures/svg-compress.result.html index e6aa845..f3fab5a 100644 --- a/test/fixtures/svg-compress.result.html +++ b/test/fixtures/svg-compress.result.html @@ -1 +1 @@ - + diff --git a/test/fixtures/svg-viewbox.result.html b/test/fixtures/svg-viewbox.result.html new file mode 100644 index 0000000..0694db2 --- /dev/null +++ b/test/fixtures/svg-viewbox.result.html @@ -0,0 +1 @@ + diff --git a/test/fixtures/svg-viewbox.src.html b/test/fixtures/svg-viewbox.src.html new file mode 100644 index 0000000..c86aca3 --- /dev/null +++ b/test/fixtures/svg-viewbox.src.html @@ -0,0 +1,5 @@ +