Comparing version 0.1.3 to 0.1.4
// ----------------------------------------------------------------------- | ||
// Copyright (c) 2008, Stone Steps Inc. | ||
// Copyright (c) 2008, Stone Steps Inc. | ||
// All rights reserved | ||
@@ -7,7 +7,7 @@ // http://www.stonesteps.ca/legal/bsd-license/ | ||
// This is a BBCode parser written in JavaScript. The parser is intended | ||
// to demonstrate how to parse text containing BBCode tags in one pass | ||
// to demonstrate how to parse text containing BBCode tags in one pass | ||
// using regular expressions. | ||
// | ||
// The parser may be used as a backend component in ASP or in the browser, | ||
// after the text containing BBCode tags has been served to the client. | ||
// The parser may be used as a backend component in ASP or in the browser, | ||
// after the text containing BBCode tags has been served to the client. | ||
// | ||
@@ -35,5 +35,5 @@ // Following BBCode expressions are recognized: | ||
// | ||
// [pre]formatted | ||
// [pre]formatted | ||
// text[/pre] | ||
// [code]if(a == b) | ||
// [code]if(a == b) | ||
// print("done");[/code] | ||
@@ -56,3 +56,3 @@ // | ||
// aceptable BBcode tags, optionally prefixed with a slash | ||
var tagname_re = /^\/?(?:b|i|u|pre|samp|code|colou?r|size|noparse|url|link|s|q|blockquote|img|u?list|li)$/; | ||
var tagname_re = /^\/?(?:b|i|u|pre|samp|code|colou?r|size|noparse|url|link|s|q|blockquote|img|u?list|li)$/i; | ||
@@ -116,2 +116,4 @@ // color names or hex color | ||
if(isValidTag(m2)) { | ||
var m2l = m2.toLowerCase(); | ||
// if in the noparse state, just echo the tag | ||
@@ -125,5 +127,5 @@ if(noparse) | ||
switch (m2) { | ||
switch (m2l) { | ||
case "code": | ||
opentags.push(new taginfo_t(m2, "</code></pre>")); | ||
opentags.push(new taginfo_t(m2l, "</code></pre>")); | ||
crlf2br = false; | ||
@@ -133,3 +135,3 @@ return "<pre><code>"; | ||
case "pre": | ||
opentags.push(new taginfo_t(m2, "</pre>")); | ||
opentags.push(new taginfo_t(m2l, "</pre>")); | ||
crlf2br = false; | ||
@@ -142,3 +144,3 @@ return "<pre>"; | ||
m3 = "inherit"; | ||
opentags.push(new taginfo_t(m2, "</span>")); | ||
opentags.push(new taginfo_t(m2l, "</span>")); | ||
return "<span style=\"color: " + m3 + "\">"; | ||
@@ -149,7 +151,7 @@ | ||
m3 = "1"; | ||
opentags.push(new taginfo_t(m2, "</span>")); | ||
opentags.push(new taginfo_t(m2l, "</span>")); | ||
return "<span style=\"font-size: " + Math.min(Math.max(m3, 0.7), 3) + "em\">"; | ||
case "s": | ||
opentags.push(new taginfo_t(m2, "</span>")); | ||
opentags.push(new taginfo_t(m2l, "</span>")); | ||
return "<span style=\"text-decoration: line-through\">"; | ||
@@ -163,3 +165,3 @@ | ||
case "url": | ||
opentags.push(new taginfo_t(m2, "</a>")); | ||
opentags.push(new taginfo_t(m2l, "</a>")); | ||
@@ -173,3 +175,3 @@ // check if there's a valid option | ||
// otherwise, remember the URL offset | ||
// otherwise, remember the URL offset | ||
urlstart = mstr.length + offset; | ||
@@ -180,15 +182,15 @@ | ||
case "img": | ||
opentags.push(new taginfo_t(m2, "\" />")); | ||
opentags.push(new taginfo_t(m2l, "\" />")); | ||
if (m3 && uri_re.test(m3)) { | ||
urlstart = -1; | ||
return "<" + m2 + " src=\"" + m3 + ""; | ||
return "<" + m2l + " src=\"" + m3 + ""; | ||
} | ||
return "<"+m2+" src=\""; | ||
return "<"+m2l+" src=\""; | ||
case "q": | ||
case "blockquote": | ||
opentags.push(new taginfo_t(m2, "</" + m2 + ">")); | ||
return m3 && m3.length && uri_re.test(m3) ? "<" + m2 + " cite=\"" + m3 + "\">" : "<" + m2 + ">"; | ||
opentags.push(new taginfo_t(m2l, "</" + m2l + ">")); | ||
return m3 && m3.length && uri_re.test(m3) ? "<" + m2l + " cite=\"" + m3 + "\">" : "<" + m2l + ">"; | ||
@@ -202,7 +204,7 @@ case "list": | ||
return '<ul>'; | ||
case "b": | ||
opentags.push(new taginfo_t('b', '</strong>')); | ||
return '<strong>'; | ||
case "i": | ||
@@ -214,4 +216,4 @@ opentags.push(new taginfo_t('i', '</em>')); | ||
// [samp] and [u] don't need special processing | ||
opentags.push(new taginfo_t(m2, "</" + m2 + ">")); | ||
return "<" + m2 + ">"; | ||
opentags.push(new taginfo_t(m2l, "</" + m2l + ">")); | ||
return "<" + m2l + ">"; | ||
@@ -225,2 +227,4 @@ } | ||
if(isValidTag(m4)) { | ||
var m4l = m4.toLowerCase(); | ||
if(noparse) { | ||
@@ -238,6 +242,6 @@ // if it's the closing noparse tag, flip the noparse state | ||
// highlight mismatched end tags | ||
if(!opentags.length || opentags[opentags.length-1].bbtag != m4) | ||
if(!opentags.length || opentags[opentags.length-1].bbtag != m4l) | ||
return "<span style=\"color: red\">[/" + m4 + "]</span>"; | ||
if(m4 == "url" || m4 == "link") { | ||
if(m4l == "url" || m4l == "link") { | ||
// if there was no option, use the content of the [url] tag | ||
@@ -250,3 +254,3 @@ if(urlstart > 0) | ||
} | ||
else if(m4 == "code" || m4 == "pre") | ||
else if(m4l == "code" || m4l == "pre") | ||
crlf2br = true; | ||
@@ -253,0 +257,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"main": "./lib/bbcode", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"author": "Nick Campbell (http://github.com/ncb000gt)", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -192,3 +192,21 @@ var bbcode = require('../lib/bbcode'); | ||
}); | ||
describe('should parse uppercase tags properly - ', function() { | ||
it('should parse uppercase [I] to <em>', function() { | ||
bbcode.parse('[I]italics[/I]', function(parse) { | ||
parse.should.equal('<em>italics</em>'); | ||
}); | ||
}); | ||
it('should parse uppercase [IMG] to <img>', function() { | ||
bbcode.parse('[IMG]http://example.com/img.png[/IMG]', function(parse) { | ||
parse.should.equal('<img src="http://example.com/img.png" />'); | ||
}); | ||
}); | ||
it('should parse mixed case [IMG][/img] to <img>', function() { | ||
bbcode.parse('[Img]http://example.com/img.png[/img]', function(parse) { | ||
parse.should.equal('<img src="http://example.com/img.png" />'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
17889
424
0