diff --git a/plugins/removeHiddenElems.js b/plugins/removeHiddenElems.js
index 87aa5fc62..efa1be430 100644
--- a/plugins/removeHiddenElems.js
+++ b/plugins/removeHiddenElems.js
@@ -1,6 +1,7 @@
'use strict';
const { computeStyle } = require('../lib/style.js');
+const { parsePathData } = require('../lib/path.js');
exports.type = 'perItem';
@@ -27,8 +28,6 @@ exports.params = {
polygonEmptyPoints: true,
};
-var regValidPath = /M\s*(?:[-+]?(?:\d*\.\d+|\d+(?:\.|(?!\.)))([eE][-+]?\d+)?(?!\d)\s*,?\s*){2}\D*\d/i;
-
/**
* Remove hidden elements with disabled rendering:
* - display="none"
@@ -229,12 +228,23 @@ exports.fn = function (item, params) {
// https://www.w3.org/TR/SVG11/paths.html#DAttribute
//
//
- if (
- params.pathEmptyD &&
- item.isElem('path') &&
- (!item.hasAttr('d') || !regValidPath.test(item.attr('d').value))
- ) {
- return false;
+ if (params.pathEmptyD && item.isElem('path')) {
+ if (item.hasAttr('d') === false) {
+ return false;
+ }
+ const pathData = parsePathData(item.attr('d').value);
+ if (pathData.length === 0) {
+ return false;
+ }
+ // keep single point paths for markers
+ if (
+ pathData.length === 1 &&
+ computedStyle['marker-start'] == null &&
+ computedStyle['marker-end'] == null
+ ) {
+ return false;
+ }
+ return true;
}
// Polyline with empty points
diff --git a/test/plugins/removeHiddenElems.08.svg b/test/plugins/removeHiddenElems.08.svg
index 010950dc0..52d7d9e0d 100644
--- a/test/plugins/removeHiddenElems.08.svg
+++ b/test/plugins/removeHiddenElems.08.svg
@@ -3,6 +3,7 @@
+
@@ -10,6 +11,10 @@
+
+
+
+
@@ -23,5 +28,7 @@
+
+