Rewriting the count_lines function #67

Closed
wants to merge 2 commits into
from
View
4 lib/markdown.js
@@ -153,9 +153,7 @@ var mk_block = Markdown.mk_block = function(block, trail, line) {
};
function count_lines( str ) {
- var n = 0, i = -1;
- while ( ( i = str.indexOf('\n', i+1) ) !== -1) n++;
- return n;
+ return str.trim().split( /\n+/ ).length;
}
// Internal - split source into rough blocks