FIX: [quote] without params was failing.

This commit is contained in:
Robin Ward 2013-10-21 11:11:54 -04:00
parent f565766b1e
commit 1783089d64
2 changed files with 26 additions and 12 deletions

View File

@ -6,19 +6,24 @@ Discourse.Dialect.replaceBlock({
stop: '[/quote]',
emitter: function(blockContents, matches, options) {
var paramsString = matches[1].replace(/\"/g, ''),
params = {'class': 'quote'},
paramsSplit = paramsString.split(/\, */),
username = paramsSplit[0];
var params = {'class': 'quote'},
username;
paramsSplit.forEach(function(p,i) {
if (i > 0) {
var assignment = p.split(':');
if (assignment[0] && assignment[1]) {
params['data-' + assignment[0]] = assignment[1].trim();
if (matches[1]) {
var paramsString = matches[1].replace(/\"/g, ''),
paramsSplit = paramsString.split(/\, */);
username = paramsSplit[0];
paramsSplit.forEach(function(p,i) {
if (i > 0) {
var assignment = p.split(':');
if (assignment[0] && assignment[1]) {
params['data-' + assignment[0]] = assignment[1].trim();
}
}
}
});
});
}
var avatarImg;
if (options.lookupAvatarByPostNumber) {
@ -41,11 +46,15 @@ Discourse.Dialect.replaceBlock({
});
}
if (!username) {
return ['p', ['aside', params, contents ]];
}
return ['p', ['aside', params,
['div', {'class': 'title'},
['div', {'class': 'quote-controls'}],
avatarImg ? ['__RAW', avatarImg] : "",
I18n.t('user.said', {username: username})
username ? I18n.t('user.said', {username: username}) : ""
],
contents
]];

View File

@ -74,6 +74,11 @@ test("quotes", function() {
formatQuote("this is <not> a bug",
"[quote=\"eviltrout, post:1, topic:2\"]\nthis is &lt;not&gt; a bug\n[/quote]\n\n",
"it escapes the contents of the quote");
format("[quote]test[/quote]",
"<aside class=\"quote\"><blockquote><p>test</p></blockquote></aside>",
"it supports quotes without params");
});
test("quote formatting", function() {