mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 19:08:10 -05:00
FIX: Quotes with new lines were broken
This commit is contained in:
parent
d7596840e5
commit
a3757016d9
4 changed files with 86 additions and 47 deletions
|
@ -107,16 +107,29 @@ Discourse.Dialect.on("register", function(event) {
|
||||||
@return {Array} the JsonML containing the markup or undefined if nothing changed.
|
@return {Array} the JsonML containing the markup or undefined if nothing changed.
|
||||||
@namespace Discourse.Dialect
|
@namespace Discourse.Dialect
|
||||||
**/
|
**/
|
||||||
dialect.inline["[quote="] = function bbcodeQuote(text, orig_match) {
|
dialect.block['quote'] = function bbcodeQuote(block, next) {
|
||||||
var bbcodePattern = new RegExp("\\[quote=?([^\\[\\]]+)?\\]([\\s\\S]*?)\\[\\/quote\\]", "igm"),
|
var m = new RegExp("\\[quote=?([^\\[\\]]+)?\\]([\\s\\S]*)", "igm").exec(block);
|
||||||
m = bbcodePattern.exec(text);
|
if (m) {
|
||||||
|
|
||||||
if (!m) { return; }
|
|
||||||
var paramsString = m[1].replace(/\"/g, ''),
|
var paramsString = m[1].replace(/\"/g, ''),
|
||||||
params = {'class': 'quote'},
|
params = {'class': 'quote'},
|
||||||
paramsSplit = paramsString.split(/\, */),
|
paramsSplit = paramsString.split(/\, */),
|
||||||
username = paramsSplit[0],
|
username = paramsSplit[0],
|
||||||
opts = dialect.options;
|
opts = dialect.options,
|
||||||
|
startPos = block.indexOf(m[0]),
|
||||||
|
leading,
|
||||||
|
quoteContents = [],
|
||||||
|
result = [];
|
||||||
|
|
||||||
|
if (startPos > 0) {
|
||||||
|
leading = block.slice(0, startPos);
|
||||||
|
|
||||||
|
var para = ['p'];
|
||||||
|
this.processInline(leading).forEach(function (l) {
|
||||||
|
para.push(l);
|
||||||
|
});
|
||||||
|
|
||||||
|
result.push(para);
|
||||||
|
}
|
||||||
|
|
||||||
paramsSplit.forEach(function(p,i) {
|
paramsSplit.forEach(function(p,i) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
@ -137,16 +150,37 @@ Discourse.Dialect.on("register", function(event) {
|
||||||
avatarImg = opts.lookupAvatar(username);
|
avatarImg = opts.lookupAvatar(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
var quote = ['aside', params,
|
if (m[2]) { next.unshift(MD.mk_block(m[2])); }
|
||||||
|
|
||||||
|
while (next.length > 0) {
|
||||||
|
var b = next.shift(),
|
||||||
|
n = b.match(/([\s\S]*)\[\/quote\]([\s\S]*)/m);
|
||||||
|
|
||||||
|
if (n) {
|
||||||
|
if (n[2]) {
|
||||||
|
next.unshift(MD.mk_block(n[2]));
|
||||||
|
}
|
||||||
|
quoteContents.push(n[1]);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
quoteContents.push(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var contents = this.processInline(quoteContents.join(" \n \n"));
|
||||||
|
contents.unshift('blockquote');
|
||||||
|
|
||||||
|
|
||||||
|
result.push(['p', ['aside', params,
|
||||||
['div', {'class': 'title'},
|
['div', {'class': 'title'},
|
||||||
['div', {'class': 'quote-controls'}],
|
['div', {'class': 'quote-controls'}],
|
||||||
avatarImg ? avatarImg + "\n" : "",
|
avatarImg ? avatarImg + "\n" : "",
|
||||||
I18n.t('user.said',{username: username})
|
I18n.t('user.said',{username: username})
|
||||||
],
|
],
|
||||||
['blockquote'].concat(this.processInline(m[2]))
|
contents
|
||||||
];
|
]]);
|
||||||
|
return result;
|
||||||
return [m[0].length, quote];
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -192,11 +192,14 @@ Discourse.ComposerView = Discourse.View.extend({
|
||||||
|
|
||||||
this.editor = editor = Discourse.Markdown.createEditor({
|
this.editor = editor = Discourse.Markdown.createEditor({
|
||||||
lookupAvatarByPostNumber: function(postNumber) {
|
lookupAvatarByPostNumber: function(postNumber) {
|
||||||
var quotedPost = composerView.get('controller.controllers.topic.postStream.posts').findProperty("post_number", postNumber);
|
var posts = composerView.get('controller.controllers.topic.postStream.posts');
|
||||||
|
if (posts) {
|
||||||
|
var quotedPost = posts.findProperty("post_number", postNumber);
|
||||||
if (quotedPost) {
|
if (quotedPost) {
|
||||||
return Discourse.Utilities.tinyAvatar(quotedPost.get("avatar_template"));
|
return Discourse.Utilities.tinyAvatar(quotedPost.get("avatar_template"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var $uploadTarget = $('#reply-control');
|
var $uploadTarget = $('#reply-control');
|
||||||
|
|
|
@ -88,15 +88,9 @@ test("quote formatting", function() {
|
||||||
|
|
||||||
format("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]\nhello",
|
format("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]\nhello",
|
||||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout said:" +
|
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout said:" +
|
||||||
"</div><blockquote>abc</blockquote></aside><br/>\nhello",
|
"</div><blockquote>abc</blockquote></aside></p>\n\n<p>\nhello",
|
||||||
"handles new lines properly");
|
"handles new lines properly");
|
||||||
|
|
||||||
format("before[quote=\"eviltrout, post:1, topic:1\"]first[/quote]middle[quote=\"eviltrout, post:2, topic:2\"]second[/quote]after",
|
|
||||||
"before<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout said:</div><blockquote>" +
|
|
||||||
"first</blockquote></aside><br/>middle<aside class=\"quote\" data-post=\"2\" data-topic=\"2\"><div class=\"title\"><div class=\"quote-controls\"></div>" +
|
|
||||||
"eviltrout said:</div><blockquote>second</blockquote></aside><br/>after",
|
|
||||||
"can handle more than one quote");
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -85,15 +85,23 @@ test("Links", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Quotes", function() {
|
test("Quotes", function() {
|
||||||
|
|
||||||
|
cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n[/quote]",
|
||||||
|
{ topicId: 2 },
|
||||||
|
"<p><aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout said:</div><blockquote>\n" +
|
||||||
|
"a quote<br/><br/>second line<br/></blockquote></aside></p>",
|
||||||
|
"works with multiple lines");
|
||||||
|
|
||||||
cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||||
{ topicId: 2, lookupAvatar: function(name) { return "" + name; } },
|
{ topicId: 2, lookupAvatar: function(name) { return "" + name; } },
|
||||||
"<p>1<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob\n" +
|
"<p>1</p>\n\n<p><aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob\n" +
|
||||||
"bob said:</div><blockquote>my quote</blockquote></aside><br/>2</p>",
|
"bob said:</div><blockquote>my quote</blockquote></aside></p>\n\n<p>2</p>",
|
||||||
"handles quotes properly");
|
"handles quotes properly");
|
||||||
|
|
||||||
cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||||
{ topicId: 2, lookupAvatar: function(name) { } },
|
{ topicId: 2, lookupAvatar: function(name) { } },
|
||||||
"<p>1<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob said:</div><blockquote>my quote</blockquote></aside><br/>2</p>",
|
"<p>1</p>\n\n<p><aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob said:" +
|
||||||
|
"</div><blockquote>my quote</blockquote></aside></p>\n\n<p>2</p>",
|
||||||
"includes no avatar if none is found");
|
"includes no avatar if none is found");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue