Repository: svg/svgo
Pull request #688 (2017-03-23 16:47:39)

add removeScriptElement plugin
addresses https://github.com/svg/svgo/issues/395


Patch:
diff --git a/.svgo.yml b/.svgo.yml
index a2b6e52..a504b96 100644
--- a/.svgo.yml
+++ b/.svgo.yml
@@ -57,6 +57,7 @@ plugins:
   - removeElementsByAttr
   - addClassesToSVGElement
   - removeStyleElement
+  - removeScriptElement
   - addAttributesToSVGElement
 
 # configure the indent (default 4 spaces) used by `--pretty` here:
diff --git a/README.md b/README.md
index 73e3393..bd6db04 100644
--- a/README.md
+++ b/README.md
@@ -62,6 +62,7 @@ Today we have:
 | [addClassesToSVGElement](https://github.com/svg/svgo/blob/master/plugins/addClassesToSVGElement.js) | add classnames to an outer `<svg>` element (disabled by default) |
 | [addAttributesToSVGElement](https://github.com/svg/svgo/blob/master/plugins/addAttributesToSVGElement.js) | adds attributes to an outer `<svg>` element (disabled by default) |
 | [removeStyleElement](https://github.com/svg/svgo/blob/master/plugins/removeStyleElement.js) | remove `<style>` elements (disabled by default) |
+| [removeScriptElement](https://github.com/svg/svgo/blob/master/plugins/removeScriptElement.js) | remove `<script>` elements (disabled by default) |
 
 Want to know how it works and how to write your own plugin? [Of course you want to](https://github.com/svg/svgo/blob/master/docs/how-it-works/en.md). ([동작방법](https://github.com/svg/svgo/blob/master/docs/how-it-works/ko.md))
 
diff --git a/README.ru.md b/README.ru.md
index ef236f3..fd4da96 100644
--- a/README.ru.md
+++ b/README.ru.md
@@ -62,6 +62,7 @@ SVGO имеет расширяемую архитектуру, в которой
 | [addClassesToSVGElement](https://github.com/svg/svgo/blob/master/plugins/addClassesToSVGElement.js) | добавляет имена классов корневому элементу `<svg>` (выключено по умолчанию) |
 | [addAttributesToSVGElement](https://github.com/svg/svgo/blob/master/plugins/addAttributesToSVGElement.js) | добавляет атрибуты корневому элементу `<svg>` (выключено  |по умолчанию)
 | [removeStyleElement](https://github.com/svg/svgo/blob/master/plugins/removeStyleElement.js) | удаляет элементы `<style>` (выключено по умолчанию) |
+| [removeScriptElement](https://github.com/svg/svgo/blob/master/plugins/removeScriptElement.js) | удаляет элементы `<script>` (выключено по умолчанию) |
 
 Хотите узнать, как это работает и как написать свой плагин? [Конечно же, да!](https://github.com/svg/svgo/blob/master/docs/how-it-works/ru.md).
 
diff --git a/plugins/removeScriptElement.js b/plugins/removeScriptElement.js
new file mode 100644
index 0000000..f80410b
--- /dev/null
+++ b/plugins/removeScriptElement.js
@@ -0,0 +1,23 @@
+'use strict';
+
+exports.type = 'perItem';
+
+exports.active = false;
+
+exports.description = 'removes <script> elements (disabled by default)';
+
+/**
+ * Remove <script>.
+ *
+ * https://www.w3.org/TR/SVG/script.html
+ *
+ * @param {Object} item current iteration item
+ * @return {Boolean} if false, item will be filtered out
+ *
+ * @author Patrick Klingemann
+ */
+exports.fn = function(item) {
+
+    return !item.isElem('script');
+
+};


Test patch:
diff --git a/test/plugins/removeScriptElement.01.svg b/test/plugins/removeScriptElement.01.svg
new file mode 100644
index 0000000..b3655db
--- /dev/null
+++ b/test/plugins/removeScriptElement.01.svg
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-16"?>
+    <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" xml:space="preserve">
+        <script></script>
+        <circle class="st0" cx="50" cy="50" r="50" />
+    </svg>
+
+@@@
+
+<?xml version="1.0" encoding="utf-16"?>
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" xml:space="preserve">
+    <circle class="st0" cx="50" cy="50" r="50"/>
+</svg>