Skip to content

Commit

Permalink
Create a helper forEach method
Browse files Browse the repository at this point in the history
Sadly IE doesn't have forEach yet :(
  • Loading branch information
ashb committed Apr 9, 2012
1 parent 69c5107 commit c360714
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/markdown.js
Expand Up @@ -627,9 +627,7 @@ Markdown.dialects.Gruber = {
// Deal with code blocks or properly nested lists
if (contained.length > 0) {
// Make sure all listitems up the stack are paragraphs
for (i = 0, l = stack.length; i < l; i++) {
paragraphify.call( this, stack[i], i, stack);
}
forEach( stack, paragraphify, this);

last_li.push.apply( last_li, this.toTree( contained, [] ) );
}
Expand All @@ -648,9 +646,7 @@ Markdown.dialects.Gruber = {
}

// Make sure all listitems up the stack are paragraphs
for (i = 0, l = stack.length; i < l; i++) {
paragraphify.call( this, stack[i], i, stack );
}
forEach( stack, paragraphify, this);

loose = true;
continue loose_search;
Expand Down Expand Up @@ -784,9 +780,7 @@ Markdown.dialects.Gruber.inline = {
re.lastIndex += ( len - m[2].length );

// Add children
for (var i = 0, l = res.length; i < l; i++) {
add(res[i]);
}
forEach( res, add);

lastIndex = re.lastIndex;
}
Expand Down Expand Up @@ -1197,6 +1191,21 @@ var isArray = Array.isArray || function(obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
};

var forEach;
// Don't mess with Array.prototype. Its not friendly
if ( Array.prototype.forEach ) {
forEach = function( arr, cb, thisp ) {
return arr.forEach( cb, thisp );
};
}
else {
forEach = function(arr, cb, thisp) {
for (var i = 0; i < arr.length; i++) {
cb.call(thisp || arr, arr[i], i, arr);
}
}
}

function extract_attr( jsonml ) {
return isArray(jsonml)
&& jsonml.length > 1
Expand Down

0 comments on commit c360714

Please sign in to comment.