Merge pull request #3715 from gwwar/quote_newline_code
workaround for code block being parsed before quote block.
This commit is contained in:
commit
1c90f77d09
|
@ -33,6 +33,7 @@ function codeFlattenBlocks(blocks) {
|
|||
Discourse.Dialect.replaceBlock({
|
||||
start: /^`{3}([^\n\[\]]+)?\n?([\s\S]*)?/gm,
|
||||
stop: /^```$/gm,
|
||||
withoutLeading: /\[quote/gm, //if leading text contains a quote this should not match
|
||||
emitter: function(blockContents, matches) {
|
||||
|
||||
var klass = Discourse.SiteSettings.default_code_lang;
|
||||
|
|
|
@ -501,6 +501,12 @@ Discourse.Dialect = {
|
|||
var pos = args.start.lastIndex - match[0].length,
|
||||
leading = block.slice(0, pos),
|
||||
trailing = match[2] ? match[2].replace(/^\n*/, "") : "";
|
||||
|
||||
if(args.withoutLeading && args.withoutLeading.test(leading)) {
|
||||
//The other leading block should be processed first! eg a code block wrapped around a code block.
|
||||
return;
|
||||
}
|
||||
|
||||
// just give up if there's no stop tag in this or any next block
|
||||
args.stop.lastIndex = block.length - trailing.length;
|
||||
if (!args.stop.exec(block) && lastChance()) { return; }
|
||||
|
|
|
@ -160,6 +160,13 @@ test("quote formatting", function() {
|
|||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:" +
|
||||
"</div><blockquote><p>[quote=\"Bob, post:2, topic:1\"]</p></blockquote></aside>",
|
||||
"handles mismatched nested quote tags");
|
||||
|
||||
formatQ("[quote=\"Alice, post:1, topic:1\"]\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:</div><blockquote><p><pre><code class=\"lang-javascript\">var foo ='foo';\nvar bar = 'bar';</code></pre></p></blockquote></aside>",
|
||||
"quotes can have code blocks without leading newline");
|
||||
formatQ("[quote=\"Alice, post:1, topic:1\"]\n\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:</div><blockquote><p><pre><code class=\"lang-javascript\">var foo ='foo';\nvar bar = 'bar';</code></pre></p></blockquote></aside>",
|
||||
"quotes can have code blocks with leading newline");
|
||||
});
|
||||
|
||||
test("quotes with trailing formatting", function() {
|
||||
|
|
Loading…
Reference in New Issue