Skip to content

Commit

Permalink
v0.0.2
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information
ncb000gt committed Feb 1, 2011
1 parent a3c2aea commit 8dfaaf3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
35 changes: 18 additions & 17 deletions lib/bbcode.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function textToHtmlCB(mstr, m1, m2, m3, m4, offset, string)
// post must be HTML-encoded // post must be HTML-encoded
// //
BBCode.prototype.parse = function(post, cb) { BBCode.prototype.parse = function(post, cb) {
var result, endtags, tag; var result = '', endtags, tag;


// convert CRLF to <br> by default // convert CRLF to <br> by default
crlf2br = true; crlf2br = true;
Expand All @@ -231,27 +231,28 @@ BBCode.prototype.parse = function(post, cb) {
opentags = new Array(0); opentags = new Array(0);


// run the text through main regular expression matcher // run the text through main regular expression matcher
result = post.replace(postfmt_re, textToHtmlCB); if (post) {
result = post.replace(postfmt_re, textToHtmlCB);


// reset noparse, if it was unbalanced // reset noparse, if it was unbalanced
if(noparse) if(noparse)
noparse = false; noparse = false;


// if there are any unbalanced tags, make sure to close them // if there are any unbalanced tags, make sure to close them
if(opentags.length) { if(opentags.length) {
endtags = new String(); endtags = new String();


// if there's an open [url] at the top, close it // if there's an open [url] at the top, close it
if(opentags[opentags.length-1].bbtag == "url") { if(opentags[opentags.length-1].bbtag == "url") {
opentags.pop(); opentags.pop();
endtags += "\">" + post.substr(urlstart, post.length-urlstart) + "</a>"; endtags += "\">" + post.substr(urlstart, post.length-urlstart) + "</a>";
} }


// close remaining open tags // close remaining open tags
while(opentags.length) while(opentags.length)
endtags += opentags.pop().etag; endtags += opentags.pop().etag;
}
} }

var ret = endtags ? result + endtags : result; var ret = endtags ? result + endtags : result;
if (cb) { if (cb) {
cb(ret); cb(ret);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bbcode", "name": "bbcode",
"description": "A BBCode Parser for NodeJS", "description": "A BBCode Parser for NodeJS",
"main": "./lib/bbcode", "main": "./lib/bbcode",
"version": "0.0.1", "version": "0.0.2",
"author": "Nick Campbell (http://github.com/ncb000gt)", "author": "Nick Campbell (http://github.com/ncb000gt)",
"engines": { "node": ">= 0.1.100" }, "engines": { "node": ">= 0.1.100" },
"repository": { "repository": {
Expand Down

0 comments on commit 8dfaaf3

Please sign in to comment.