From 645908923bb163e177023ca21fe04a380fade126 Mon Sep 17 00:00:00 2001 From: Mike Street Date: Mon, 3 Apr 2017 11:48:56 +0100 Subject: [PATCH] Allow element seperator to be changed in config This resolves #557 as you can pass in a different character for element seperation (e.g. `^` --- plugins/removeAttrs.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/removeAttrs.js b/plugins/removeAttrs.js index bd2fca62..c8968c20 100644 --- a/plugins/removeAttrs.js +++ b/plugins/removeAttrs.js @@ -1,6 +1,6 @@ 'use strict'; -var ELEM_SEP = ':'; +var DEFAULT_SEPARATOR = ':'; exports.type = 'perItem'; @@ -9,12 +9,16 @@ exports.active = false; exports.description = 'removes specified attributes'; exports.params = { + elemSeparator: DEFAULT_SEPARATOR, attrs: [] }; /** * Remove attributes * + * @param elemSeparator + * format: string + * * @param attrs: * * format: [ element* : attribute* ] @@ -72,17 +76,18 @@ exports.fn = function(item, params) { } if (item.isElem()) { + var elemSeparator = typeof params.elemSeparator == 'string' ? params.elemSeparator : DEFAULT_SEPARATOR; // prepare patterns var patterns = params.attrs.map(function(pattern) { // apply to all elements if specifc element is omitted - if (pattern.indexOf(ELEM_SEP) === -1) { - pattern = ['.*', ELEM_SEP, pattern].join(''); + if (pattern.indexOf(elemSeparator) === -1) { + pattern = ['.*', elemSeparator, pattern].join(''); } // create regexps for element and attribute name - return pattern.split(ELEM_SEP) + return pattern.split(elemSeparator) .map(function(value) { // adjust single * to match anything