Skip to content

Commit

Permalink
Add support for [quote] element
Browse files Browse the repository at this point in the history
Some implementations of bbcode utilize the [quote] tag, instead of/in
addition to [blockquote]. This commit adds support for [quote], and
treats it the same as [blockquote].

http://bbcode.org/reference.php
  • Loading branch information
dpolivy committed Feb 6, 2014
1 parent b2c1cc2 commit ed897b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/bbcode.js
Expand Up @@ -28,6 +28,8 @@
//
// [q=http://blogs.stonesteps.ca/showpost.asp?pid=33]inline quote[/q]
// [q]inline quote[/q]
// [quote=http://blogs.stonesteps.ca/showpost.asp?pid=33]inline quote[/quote]
// [quote]inline quote[/quote]
// [blockquote=http://blogs.stonesteps.ca/showpost.asp?pid=33]block quote[/blockquote]
// [blockquote]block quote[/blockquote]
//
Expand All @@ -51,7 +53,7 @@ exports.parse = function(post, cb) {
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|center|samp|code|colou?r|size|noparse|url|link|s|q|blockquote|img|u?list|li)$/i;
var tagname_re = /^\/?(?:b|i|u|pre|center|samp|code|colou?r|size|noparse|url|link|s|q|(block)?quote|img|u?list|li)$/i;

// 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;
Expand Down Expand Up @@ -184,9 +186,11 @@ exports.parse = function(post, cb) {
return "<"+m2l+" src=\"";

case "q":
case "quote":
case "blockquote":
opentags.push(new taginfo_t(m2l, "</" + m2l + ">"));
return m3 && m3.length && uri_re.test(m3) ? "<" + m2l + " cite=\"" + m3 + "\">" : "<" + m2l + ">";
var tag = (m2l === "q") ? "q" : "blockquote";
opentags.push(new taginfo_t(m2l, "</" + tag + ">"));
return m3 && m3.length && uri_re.test(m3) ? "<" + tag + " cite=\"" + m3 + "\">" : "<" + tag + ">";

case "list":
opentags.push(new taginfo_t('list', '</ol>'));
Expand Down
6 changes: 6 additions & 0 deletions tests/parse.js
Expand Up @@ -139,6 +139,12 @@ describe('bcrypt', function() {
});
});

it('should parse [quote] as <blockquote>', function() {
bbcode.parse('[quote=person]quoted[/quote]', function(parse) {
parse.should.equal('<blockquote cite="person">quoted</blockquote>');
});
});

it('should try to fix broken markup', function() {
bbcode.parse('[b]test', function(parse) {
parse.should.equal('<strong>test</strong>');
Expand Down

0 comments on commit ed897b9

Please sign in to comment.