Skip to content

Commit 41160f3

Browse files
committed
Update htmlClean plugin, add twitter link in readme
1 parent 64cfe41 commit 41160f3

File tree

2 files changed

+70
-69
lines changed

2 files changed

+70
-69
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Author
6868
**Konrad Dzwinel**
6969

7070
+ https://github.com/kdzwinel
71+
+ https://twitter.com/kdzwinel
7172
+ http://www.linkedin.com/pub/konrad-dzwinel/53/599/366/en
7273

7374
License

js/libs/jquery.htmlClean.js

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/*
2-
HTML Clean for jQuery
3-
Anthony Johnston
4-
http://www.antix.co.uk
5-
6-
version 1.4.0
2+
HTML Clean for jQuery
3+
Anthony Johnston
4+
http://www.antix.co.uk
75
8-
$Revision: 99 $
6+
version 1.4.0
97
10-
requires jQuery http://jquery.com
8+
$Revision: 99 $
119
12-
Use and distibution http://www.opensource.org/licenses/bsd-license.php
10+
requires jQuery http://jquery.com
1311
14-
2010-04-02 allowedTags/removeTags added (white/black list) thanks to David Wartian (Dwartian)
15-
2010-06-30 replaceStyles added for replacement of bold, italic, super and sub styles on a tag
16-
2012-04-30 allowedAttributes added, an array of attributed allowed on the elements
17-
2013-02-25 now will push non-inline elements up the stack if nested in an inline element
18-
2013-02-25 comment element support added, removed by default, see AllowComments in options
19-
*/
12+
Use and distibution http://www.opensource.org/licenses/bsd-license.php
13+
14+
2010-04-02 allowedTags/removeTags added (white/black list) thanks to David Wartian (Dwartian)
15+
2010-06-30 replaceStyles added for replacement of bold, italic, super and sub styles on a tag
16+
2012-04-30 allowedAttributes added, an array of attributed allowed on the elements
17+
2013-02-25 now will push non-inline elements up the stack if nested in an inline element
18+
2013-02-25 comment element support added, removed by default, see AllowComments in options
19+
*/
2020
(function ($) {
2121
$.fn.htmlClean = function (options) {
2222
// iterate and html clean each matched element
@@ -61,7 +61,7 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
6161
if (text.length > 0) {
6262
var child = container.children[container.children.length - 1];
6363
if (container.children.length > 0
64-
&& isText(child = container.children[container.children.length - 1])) {
64+
&& isText(child = container.children[container.children.length - 1])) {
6565
// merge text
6666
container.children[container.children.length - 1] = child.concat(text);
6767
} else {
@@ -107,8 +107,8 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
107107
}
108108

109109
if (tag.allowedAttributes != null
110-
&& (tag.allowedAttributes.length == 0
111-
|| $.inArray(attrMatch[1], tag.allowedAttributes) > -1)) {
110+
&& (tag.allowedAttributes.length == 0
111+
|| $.inArray(attrMatch[1], tag.allowedAttributes) > -1)) {
112112
element.attributes.push(new Attribute(attrMatch[1], attrMatch[2]));
113113
}
114114
}
@@ -123,7 +123,7 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
123123
for (var tagIndex = 0; tagIndex < options.replace[repIndex][0].length; tagIndex++) {
124124
var byName = typeof (options.replace[repIndex][0][tagIndex]) == "string";
125125
if ((byName && options.replace[repIndex][0][tagIndex] == tag.name)
126-
|| (!byName && options.replace[repIndex][0][tagIndex].test(tagMatch))) {
126+
|| (!byName && options.replace[repIndex][0][tagIndex].test(tagMatch))) {
127127

128128
// set the name to the replacement
129129
tag.rename(options.replace[repIndex][1]);
@@ -142,7 +142,7 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
142142
container = stack[stack.length - 1];
143143
}
144144
} else if (container.tag.disallowNest && tag.disallowNest
145-
&& !tag.requiredParent) {
145+
&& !tag.requiredParent) {
146146
add = false;
147147
} else if (tag.requiredParent) {
148148
if (add = popToTagName(stack, tag.requiredParent)) {
@@ -198,7 +198,7 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
198198
format: false,
199199
// format indent to start on
200200
formatIndent: 0,
201-
// tags to replace, and what to replace with, tag name or regex to match the tag and attributes
201+
// tags to replace, and what to replace with, tag name or regex to match the tag and attributes
202202
replace: [
203203
[["b", "big"], "strong"],
204204
[["i"], "em"]
@@ -237,8 +237,8 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
237237
// don't render if not in allowedTags or in removeTags
238238
var renderTag
239239
= element.tag.render
240-
&& (options.allowedTags.length == 0 || $.inArray(element.tag.name, options.allowedTags) > -1)
241-
&& (options.removeTags.length == 0 || $.inArray(element.tag.name, options.removeTags) == -1);
240+
&& (options.allowedTags.length == 0 || $.inArray(element.tag.name, options.allowedTags) > -1)
241+
&& (options.removeTags.length == 0 || $.inArray(element.tag.name, options.removeTags) == -1);
242242

243243
if (!element.isRoot && renderTag) {
244244

@@ -251,16 +251,16 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
251251
var value = m[2];
252252
var valueQuote = m[1] || "'";
253253

254-
// check for classes allowed
254+
// check for classes allowed
255255
if (this.name == "class" && options.allowedClasses.length > 0) {
256256
value =
257-
$.grep(value.split(" "), function (c) {
258-
return $.grep(options.allowedClasses, function (a) {
259-
return a == c
260-
|| (a[0] == c && (a.length == 1 || $.inArray(element.tag.name, a[1]) > -1));
261-
}).length > 0;
262-
})
263-
.join(" ");
257+
$.grep(value.split(" "), function (c) {
258+
return $.grep(options.allowedClasses, function (a) {
259+
return a == c
260+
|| (a[0] == c && (a.length == 1 || $.inArray(element.tag.name, a[1]) > -1));
261+
}).length > 0;
262+
})
263+
.join(" ");
264264
}
265265

266266
if (value != null && (value.length > 0 || $.inArray(this.name, element.tag.requiredAttributes) > -1)) {
@@ -276,7 +276,7 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
276276
}
277277

278278
if (element.tag.isSelfClosing) {
279-
// self closing
279+
// self closing
280280
if (renderTag) output.push(" />");
281281
empty = false;
282282
} else if (element.tag.isNonClosing) {
@@ -301,7 +301,7 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
301301
var text = $.htmlClean.trim(textClean(isText(child) ? child : child.childrenToString()));
302302
if (isInline(child)) {
303303
if (i > 0 && text.length > 0
304-
&& (startsWithWhitespace(child) || endsWithWhitespace(element.children[i - 1]))) {
304+
&& (startsWithWhitespace(child) || endsWithWhitespace(element.children[i - 1]))) {
305305
outputChildren.push(" ");
306306
}
307307
}
@@ -365,7 +365,7 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
365365
if (test(element)) {
366366
return true;
367367
} else if (stack.length - index > 0
368-
&& pop(stack, test, index + 1)) {
368+
&& pop(stack, test, index + 1)) {
369369
stack.pop();
370370
return true;
371371
}
@@ -444,9 +444,9 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
444444
for (var i = 0; i < options.allowedAttributes.length; i++) {
445445
var attrName = options.allowedAttributes[i][0];
446446
if ((
447-
options.allowedAttributes[i].length == 1
447+
options.allowedAttributes[i].length == 1
448448
|| $.inArray(this.name, options.allowedAttributes[i][1]) > -1
449-
) && $.inArray(attrName, cacheItem) == -1) {
449+
) && $.inArray(attrName, cacheItem) == -1) {
450450
cacheItem.push(attrName);
451451
}
452452
}
@@ -537,48 +537,48 @@ Use and distibution http://www.opensource.org/licenses/bsd-license.php
537537
"tbody", ["table"],
538538
"tfoot", ["table"],
539539
"param", ["object"]
540-
];
540+
];
541541
var tagProtect = ["script", "style", "pre", "code"];
542542
// tags which self close e.g. <br />
543543
var tagSelfClosing = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
544544
// tags which do not close
545545
var tagNonClosing = ["!doctype", "?xml"];
546546
// attributes allowed on tags
547547
var tagAttributes = [
548-
["class"], // default, for all tags not mentioned
549-
"?xml", [],
550-
"!doctype", [],
551-
"a", ["accesskey", "class", "href", "name", "title", "rel", "rev", "type", "tabindex"],
552-
"abbr", ["class", "title"],
553-
"acronym", ["class", "title"],
554-
"blockquote", ["cite", "class"],
555-
"button", ["class", "disabled", "name", "type", "value"],
556-
"del", ["cite", "class", "datetime"],
557-
"form", ["accept", "action", "class", "enctype", "method", "name"],
558-
"iframe", ["class", "height", "name", "sandbox", "seamless", "src", "srcdoc", "width"],
559-
"input", ["accept", "accesskey", "alt", "checked", "class", "disabled", "ismap", "maxlength", "name", "size", "readonly", "src", "tabindex", "type", "usemap", "value"],
560-
"img", ["alt", "class", "height", "src", "width"],
561-
"ins", ["cite", "class", "datetime"],
562-
"label", ["accesskey", "class", "for"],
563-
"legend", ["accesskey", "class"],
564-
"link", ["href", "rel", "type"],
565-
"meta", ["content", "http-equiv", "name", "scheme", "charset"],
566-
"map", ["name"],
567-
"optgroup", ["class", "disabled", "label"],
568-
"option", ["class", "disabled", "label", "selected", "value"],
569-
"q", ["class", "cite"],
570-
"script", ["src", "type"],
571-
"select", ["class", "disabled", "multiple", "name", "size", "tabindex"],
572-
"style", ["type"],
573-
"table", ["class", "summary"],
574-
"th", ["class", "colspan", "rowspan"],
575-
"td", ["class", "colspan", "rowspan"],
576-
"textarea", ["accesskey", "class", "cols", "disabled", "name", "readonly", "rows", "tabindex"],
577-
"param", ["name", "value"],
578-
"embed", ["height", "src", "type", "width"]
579-
];
548+
["class"], // default, for all tags not mentioned
549+
"?xml", [],
550+
"!doctype", [],
551+
"a", ["accesskey", "class", "href", "name", "title", "rel", "rev", "type", "tabindex"],
552+
"abbr", ["class", "title"],
553+
"acronym", ["class", "title"],
554+
"blockquote", ["cite", "class"],
555+
"button", ["class", "disabled", "name", "type", "value"],
556+
"del", ["cite", "class", "datetime"],
557+
"form", ["accept", "action", "class", "enctype", "method", "name"],
558+
"iframe", ["class", "height", "name", "sandbox", "seamless", "src", "srcdoc", "width"],
559+
"input", ["accept", "accesskey", "alt", "checked", "class", "disabled", "ismap", "maxlength", "name", "size", "readonly", "src", "tabindex", "type", "usemap", "value"],
560+
"img", ["alt", "class", "height", "src", "width"],
561+
"ins", ["cite", "class", "datetime"],
562+
"label", ["accesskey", "class", "for"],
563+
"legend", ["accesskey", "class"],
564+
"link", ["href", "rel", "type"],
565+
"meta", ["content", "http-equiv", "name", "scheme", "charset"],
566+
"map", ["name"],
567+
"optgroup", ["class", "disabled", "label"],
568+
"option", ["class", "disabled", "label", "selected", "value"],
569+
"q", ["class", "cite"],
570+
"script", ["src", "type"],
571+
"select", ["class", "disabled", "multiple", "name", "size", "tabindex"],
572+
"style", ["type"],
573+
"table", ["class", "summary"],
574+
"th", ["class", "colspan", "rowspan"],
575+
"td", ["class", "colspan", "rowspan"],
576+
"textarea", ["accesskey", "class", "cols", "disabled", "name", "readonly", "rows", "tabindex"],
577+
"param", ["name", "value"],
578+
"embed", ["height", "src", "type", "width"]
579+
];
580580
var tagAttributesRequired = [[], "img", ["alt"]];
581581
// white space chars
582-
var whitespace = [" ", " ", "\t", "\n", "\r", "\f"];
582+
var whitespace = [" ", " ", "\t", "\n", "\r", "\f"];
583583

584584
})(jQuery);

0 commit comments

Comments
 (0)