Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

url alias "link" & [tag="attribute"] (quotes)

Updated to handle 2 cases:
Added "link" as an alias for "url" tag.
Added support for quotes and single quotes around attributes.
  • Loading branch information...
commit f9579e6cfbc5331922cbcfc5646e2de361a20adb 1 parent a859651
scotthovestadt authored November 30, 2012

Showing 1 changed file with 9 additions and 7 deletions. Show diff stats Hide diff stats

  1. 16  lib/bbcode.js
16  lib/bbcode.js
@@ -24,6 +24,7 @@
24 24
 //
25 25
 // [url]http://blogs.stonesteps.ca/showpost.asp?pid=33[/url]
26 26
 // [url=http://blogs.stonesteps.ca/showpost.asp?pid=33][b]BBCode[/b] Parser[/url]
  27
+// [url="http://blogs.stonesteps.ca/showpost.asp?pid=33"][b]BBCode[/b] Parser[/url]
27 28
 //
28 29
 // [q=http://blogs.stonesteps.ca/showpost.asp?pid=33]inline quote[/q]
29 30
 // [q]inline quote[/q]
@@ -50,7 +51,7 @@ exports.parse = function(post, cb) {
50 51
   var urlstart = -1;      // beginning of the URL if zero or greater (ignored if -1)
51 52
 
52 53
   // aceptable BBcode tags, optionally prefixed with a slash
53  
-  var tagname_re = /^\/?(?:b|i|u|pre|samp|code|colou?r|size|noparse|url|s|q|blockquote|img|u?list|li)$/;
  54
+  var tagname_re = /^\/?(?:b|i|u|pre|samp|code|colou?r|size|noparse|url|link|s|q|blockquote|img|u?list|li)$/;
54 55
 
55 56
   // color names or hex color
56 57
   var color_re = /^(:?black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua|#(?:[0-9a-f]{3})?[0-9a-f]{3})$/i;
@@ -61,8 +62,8 @@ exports.parse = function(post, cb) {
61 62
   // reserved, unreserved, escaped and alpha-numeric [RFC2396]
62 63
   var uri_re = /^[-;\/\?:@&=\+\$,_\.!~\*'\(\)%0-9a-z]{1,512}$/i;
63 64
 
64  
-  // main regular expression: CRLF, [tag=option], [tag] or [/tag]
65  
-  var postfmt_re = /([\r\n])|(?:\[([a-z]{1,16})(?:=([^\x00-\x1F"'\(\)<>\[\]]{1,256}))?\])|(?:\[\/([a-z]{1,16})\])/ig;
  65
+  // main regular expression: CRLF, [tag=option], [tag="option"] [tag] or [/tag]
  66
+  var postfmt_re = /([\r\n])|(?:\[([a-z]{1,16})(?:=(?:"|'|)([^\x00-\x1F"'\(\)<>\[\]]{1,256}))?(?:"|'|)\])|(?:\[\/([a-z]{1,16})\])/ig;
66 67
 
67 68
   // stack frame object
68 69
   function taginfo_t(bbtag, etag)
@@ -114,7 +115,7 @@ exports.parse = function(post, cb) {
114 115
         return "[" + m2 + "]";
115 116
 
116 117
       // ignore any tags if there's an open option-less [url] tag
117  
-      if(opentags.length && opentags[opentags.length-1].bbtag == "url" && urlstart >= 0)
  118
+      if(opentags.length && (opentags[opentags.length-1].bbtag == "url" || opentags[opentags.length-1].bbtag == "link") && urlstart >= 0)
118 119
         return "[" + m2 + "]";
119 120
 
120 121
       switch (m2) {
@@ -149,6 +150,7 @@ exports.parse = function(post, cb) {
149 150
           noparse = true;
150 151
           return "";
151 152
 
  153
+        case "link":
152 154
         case "url":
153 155
           opentags.push(new taginfo_t(m2, "</a>"));
154 156
 
@@ -214,7 +216,7 @@ exports.parse = function(post, cb) {
214 216
       if(!opentags.length || opentags[opentags.length-1].bbtag != m4)
215 217
         return "<span style=\"color: red\">[/" + m4 + "]</span>";
216 218
 
217  
-      if(m4 == "url") {
  219
+      if(m4 == "url" || m4 == "link") {
218 220
         // if there was no option, use the content of the [url] tag
219 221
         if(urlstart > 0)
220 222
           return "\">" + string.substr(urlstart, offset-urlstart) + opentags.pop().etag;
@@ -262,7 +264,7 @@ exports.parse = function(post, cb) {
262 264
       endtags = new String();
263 265
 
264 266
       // if there's an open [url] at the top, close it
265  
-      if(opentags[opentags.length-1].bbtag == "url") {
  267
+      if(opentags[opentags.length-1].bbtag == "url" || opentags[opentags.length-1].bbtag == "link") {
266 268
         opentags.pop();
267 269
         endtags += "\">" + post.substr(urlstart, post.length-urlstart) + "</a>";
268 270
       }
@@ -278,4 +280,4 @@ exports.parse = function(post, cb) {
278 280
   } else {
279 281
     return ret;
280 282
   }
281  
-}
  283
+}

0 notes on commit f9579e6

Please sign in to comment.
Something went wrong with that request. Please try again.