Permalink
Browse files

v0.0.2

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent a3c2aea commit 8dfaaf331499c3f88ed8a8f73ac56d32c4dfe960 @ncb000gt committed Feb 1, 2011
Showing with 19 additions and 18 deletions.
  1. +18 −17 lib/bbcode.js
  2. +1 −1 package.json
View
@@ -221,7 +221,7 @@ function textToHtmlCB(mstr, m1, m2, m3, m4, offset, string)
// post must be HTML-encoded
//
BBCode.prototype.parse = function(post, cb) {
- var result, endtags, tag;
+ var result = '', endtags, tag;
// convert CRLF to <br> by default
crlf2br = true;
@@ -231,27 +231,28 @@ BBCode.prototype.parse = function(post, cb) {
opentags = new Array(0);
// 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
- if(noparse)
- noparse = false;
+ // reset noparse, if it was unbalanced
+ if(noparse)
+ noparse = false;
- // if there are any unbalanced tags, make sure to close them
- if(opentags.length) {
- endtags = new String();
+ // if there are any unbalanced tags, make sure to close them
+ if(opentags.length) {
+ endtags = new String();
- // if there's an open [url] at the top, close it
- if(opentags[opentags.length-1].bbtag == "url") {
- opentags.pop();
- endtags += "\">" + post.substr(urlstart, post.length-urlstart) + "</a>";
- }
+ // if there's an open [url] at the top, close it
+ if(opentags[opentags.length-1].bbtag == "url") {
+ opentags.pop();
+ endtags += "\">" + post.substr(urlstart, post.length-urlstart) + "</a>";
+ }
- // close remaining open tags
- while(opentags.length)
- endtags += opentags.pop().etag;
+ // close remaining open tags
+ while(opentags.length)
+ endtags += opentags.pop().etag;
+ }
}
-
var ret = endtags ? result + endtags : result;
if (cb) {
cb(ret);
View
@@ -2,7 +2,7 @@
"name": "bbcode",
"description": "A BBCode Parser for NodeJS",
"main": "./lib/bbcode",
- "version": "0.0.1",
+ "version": "0.0.2",
"author": "Nick Campbell (http://github.com/ncb000gt)",
"engines": { "node": ">= 0.1.100" },
"repository": {

0 comments on commit 8dfaaf3

Please sign in to comment.