Permalink
Browse files

Added img support.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent 8dfaaf3 commit 1c78a786212b1767a28ece9d624d271550a841ac @ncb000gt committed Feb 1, 2011
Showing with 26 additions and 1 deletion.
  1. +10 −1 lib/bbcode.js
  2. +16 −0 tests.js
View
@@ -47,7 +47,7 @@ var noparse = false; // ignore BBCode tags?
var urlstart = -1; // beginning of the URL if zero or greater (ignored if -1)
// aceptable BBcode tags, optionally prefixed with a slash
-var tagname_re = /^\/?(?:b|i|u|pre|samp|code|colou?r|size|noparse|url|s|q|blockquote)$/;
+var tagname_re = /^\/?(?:b|i|u|pre|samp|code|colou?r|size|noparse|url|s|q|blockquote|img)$/;
// color names or hex color
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;
@@ -166,6 +166,15 @@ function textToHtmlCB(mstr, m1, m2, m3, m4, offset, string)
// and treat the text following [url] as a URL
return "<a href=\"";
+ case "img":
+ opentags.push(new taginfo_t(m2, "\" />"));
+
+ if (m3 && uri_re.test(m3)) {
+ urlstart = -1;
+ return "<" + m2 + " src=\"" + m3 + "";
+ }
+
+ return "<"+m2+" src=\"";
case "q":
case "blockquote":
View
@@ -241,6 +241,22 @@ module.exports = testCase(
assert.done();
});
},
+ 'test img with =': function(assert) {
+ assert.expect(1);
+ var bbcode = new bbcode_lib({});
+ bbcode.parse('[img=http://example.com/img.png][/img]', function(data) {
+ assert.equals('<img src="http://example.com/img.png" />', data);
+ assert.done();
+ });
+ },
+ 'test img as content': function(assert) {
+ assert.expect(1);
+ var bbcode = new bbcode_lib({});
+ bbcode.parse('[img]http://example.com/img.png[/img]', function(data) {
+ assert.equals('<img src="http://example.com/img.png" />', data);
+ assert.done();
+ });
+ },
'test quote': function(assert) {
assert.expect(1);

0 comments on commit 1c78a78

Please sign in to comment.