1 | 'use strict';
|
2 |
|
3 | exports.type = 'perItem';
|
4 |
|
5 | exports.active = true;
|
6 |
|
7 | exports.description = 'cleanups attributes from newlines, trailing and repeating spaces';
|
8 |
|
9 | exports.params = {
|
10 | newlines: true,
|
11 | trim: true,
|
12 | spaces: true
|
13 | };
|
14 |
|
15 | var regNewlinesNeedSpace = /(\S)\r?\n(\S)/g,
|
16 | regNewlines = /\r?\n/g,
|
17 | regSpaces = /\s{2,}/g;
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | exports.fn = function(item, params) {
|
29 |
|
30 | if (item.isElem()) {
|
31 |
|
32 | item.eachAttr(function(attr) {
|
33 |
|
34 | if (params.newlines) {
|
35 |
|
36 | attr.value = attr.value.replace(regNewlinesNeedSpace, function(match, p1, p2) {
|
37 | return p1 + ' ' + p2;
|
38 | });
|
39 |
|
40 |
|
41 | attr.value = attr.value.replace(regNewlines, '');
|
42 | }
|
43 |
|
44 | if (params.trim) {
|
45 | attr.value = attr.value.trim();
|
46 | }
|
47 |
|
48 | if (params.spaces) {
|
49 | attr.value = attr.value.replace(regSpaces, ' ');
|
50 | }
|
51 |
|
52 | });
|
53 |
|
54 | }
|
55 |
|
56 | };
|