From 6d10551ac4fe8f1715473d8c68ea4b975915e709 Mon Sep 17 00:00:00 2001 From: thomsj Date: Mon, 6 Nov 2017 03:52:11 +0000 Subject: [PATCH] Add plugin to cleanup XML namespaces Added plugin to cleanup (remove unused and minify used) XML namespaces. Replaced 'removeUnusedNS' plugin with new plugin ('cleanupNS'). Fixed bug in 'cleanupIDs' which would allow a generated minified ID to be the same as a preserved ID. --- .svgo.yml | 2 +- plugins/cleanupIDs.js | 30 +- plugins/cleanupNS.js | 346 ++++++++++++++++++ plugins/removeUnusedNS.js | 107 ------ test/plugins/cleanupIDs.12.svg | 25 ++ ...removeUnusedNS.01.svg => cleanupNS.01.svg} | 0 ...removeUnusedNS.02.svg => cleanupNS.02.svg} | 4 + ...removeUnusedNS.03.svg => cleanupNS.03.svg} | 4 + ...removeUnusedNS.04.svg => cleanupNS.04.svg} | 4 + ...removeUnusedNS.05.svg => cleanupNS.05.svg} | 4 + ...removeUnusedNS.06.svg => cleanupNS.06.svg} | 4 + test/plugins/cleanupNS.07.svg | 13 + test/plugins/cleanupNS.08.svg | 17 + test/plugins/cleanupNS.09.svg | 17 + test/plugins/cleanupNS.10.svg | 13 + test/plugins/cleanupNS.11.svg | 19 + test/plugins/cleanupNS.12.svg | 23 ++ test/plugins/cleanupNS.13.svg | 19 + test/plugins/cleanupNS.14.svg | 23 ++ test/plugins/cleanupNS.15.svg | 17 + test/plugins/cleanupNS.16.svg | 21 ++ test/plugins/cleanupNS.17.svg | 17 + test/plugins/cleanupNS.18.svg | 17 + test/plugins/cleanupNS.19.svg | 13 + test/plugins/cleanupNS.20.svg | 17 + test/plugins/cleanupNS.21.svg | 17 + test/plugins/cleanupNS.22.svg | 23 ++ 27 files changed, 702 insertions(+), 114 deletions(-) create mode 100644 plugins/cleanupNS.js delete mode 100644 plugins/removeUnusedNS.js create mode 100644 test/plugins/cleanupIDs.12.svg rename test/plugins/{removeUnusedNS.01.svg => cleanupNS.01.svg} (100%) rename test/plugins/{removeUnusedNS.02.svg => cleanupNS.02.svg} (92%) rename test/plugins/{removeUnusedNS.03.svg => cleanupNS.03.svg} (94%) rename test/plugins/{removeUnusedNS.04.svg => cleanupNS.04.svg} (95%) rename test/plugins/{removeUnusedNS.05.svg => cleanupNS.05.svg} (94%) rename test/plugins/{removeUnusedNS.06.svg => cleanupNS.06.svg} (95%) create mode 100644 test/plugins/cleanupNS.07.svg create mode 100644 test/plugins/cleanupNS.08.svg create mode 100644 test/plugins/cleanupNS.09.svg create mode 100644 test/plugins/cleanupNS.10.svg create mode 100644 test/plugins/cleanupNS.11.svg create mode 100644 test/plugins/cleanupNS.12.svg create mode 100644 test/plugins/cleanupNS.13.svg create mode 100644 test/plugins/cleanupNS.14.svg create mode 100644 test/plugins/cleanupNS.15.svg create mode 100644 test/plugins/cleanupNS.16.svg create mode 100644 test/plugins/cleanupNS.17.svg create mode 100644 test/plugins/cleanupNS.18.svg create mode 100644 test/plugins/cleanupNS.19.svg create mode 100644 test/plugins/cleanupNS.20.svg create mode 100644 test/plugins/cleanupNS.21.svg create mode 100644 test/plugins/cleanupNS.22.svg diff --git a/.svgo.yml b/.svgo.yml index 313bf7c68..b9cb71454 100644 --- a/.svgo.yml +++ b/.svgo.yml @@ -49,7 +49,7 @@ plugins: - removeEmptyAttrs - removeEmptyContainers - mergePaths - - removeUnusedNS + - cleanupNS - sortAttrs - removeTitle - removeDesc diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index 2b61b93f7..070901ddb 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -29,14 +29,16 @@ var referencesProps = new Set(require('./_collections').referencesProps), * Remove unused and minify used IDs * (only if there are no any + + test + + + +@@@ + + + + + test + + diff --git a/test/plugins/cleanupNS.12.svg b/test/plugins/cleanupNS.12.svg new file mode 100644 index 000000000..8faa9e62c --- /dev/null +++ b/test/plugins/cleanupNS.12.svg @@ -0,0 +1,23 @@ + + + + test + + + +@@@ + + + + + test + + + +@@@ + +{"force": false} diff --git a/test/plugins/cleanupNS.13.svg b/test/plugins/cleanupNS.13.svg new file mode 100644 index 000000000..4abfd94d0 --- /dev/null +++ b/test/plugins/cleanupNS.13.svg @@ -0,0 +1,19 @@ + + + + test + + + +@@@ + + + + + test + + diff --git a/test/plugins/cleanupNS.14.svg b/test/plugins/cleanupNS.14.svg new file mode 100644 index 000000000..2e4ed7d89 --- /dev/null +++ b/test/plugins/cleanupNS.14.svg @@ -0,0 +1,23 @@ + + + + test + + + +@@@ + + + + + test + + + +@@@ + +{"force": false} diff --git a/test/plugins/cleanupNS.15.svg b/test/plugins/cleanupNS.15.svg new file mode 100644 index 000000000..1f467a94d --- /dev/null +++ b/test/plugins/cleanupNS.15.svg @@ -0,0 +1,17 @@ + + + test + + + +@@@ + + + + test + + + +@@@ + +{"remove": false} diff --git a/test/plugins/cleanupNS.16.svg b/test/plugins/cleanupNS.16.svg new file mode 100644 index 000000000..8ff776e15 --- /dev/null +++ b/test/plugins/cleanupNS.16.svg @@ -0,0 +1,21 @@ + + + + test + + + + +@@@ + + + + + test + + + + +@@@ + +{"preserve": "test2"} diff --git a/test/plugins/cleanupNS.17.svg b/test/plugins/cleanupNS.17.svg new file mode 100644 index 000000000..6aaab924f --- /dev/null +++ b/test/plugins/cleanupNS.17.svg @@ -0,0 +1,17 @@ + + + test + + + +@@@ + + + + test + + + +@@@ + +{"preserve": "test2"} diff --git a/test/plugins/cleanupNS.18.svg b/test/plugins/cleanupNS.18.svg new file mode 100644 index 000000000..a1b7af27f --- /dev/null +++ b/test/plugins/cleanupNS.18.svg @@ -0,0 +1,17 @@ + + + test + + + +@@@ + + + + test + + + +@@@ + +{"preserve": "xmlns"} diff --git a/test/plugins/cleanupNS.19.svg b/test/plugins/cleanupNS.19.svg new file mode 100644 index 000000000..b2c81e70d --- /dev/null +++ b/test/plugins/cleanupNS.19.svg @@ -0,0 +1,13 @@ + + + test + + + +@@@ + + + + test + + diff --git a/test/plugins/cleanupNS.20.svg b/test/plugins/cleanupNS.20.svg new file mode 100644 index 000000000..8658c666b --- /dev/null +++ b/test/plugins/cleanupNS.20.svg @@ -0,0 +1,17 @@ + + + test + + + +@@@ + + + + test + + + +@@@ + +{"preserve": "xml"} diff --git a/test/plugins/cleanupNS.21.svg b/test/plugins/cleanupNS.21.svg new file mode 100644 index 000000000..d7ed24762 --- /dev/null +++ b/test/plugins/cleanupNS.21.svg @@ -0,0 +1,17 @@ + + + test + + + +@@@ + + + + test + + + +@@@ + +{"preserve": "a"} diff --git a/test/plugins/cleanupNS.22.svg b/test/plugins/cleanupNS.22.svg new file mode 100644 index 000000000..97c478385 --- /dev/null +++ b/test/plugins/cleanupNS.22.svg @@ -0,0 +1,23 @@ + + + test + + + + test + + + + +@@@ + + + + test + + + + test + + +