diff --git a/app/assets/javascripts/discourse/dialects/code_dialect.js b/app/assets/javascripts/discourse/dialects/code_dialect.js index e7322a4abeb..2594cd8316d 100644 --- a/app/assets/javascripts/discourse/dialects/code_dialect.js +++ b/app/assets/javascripts/discourse/dialects/code_dialect.js @@ -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; diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index e80e5e96710..1614c1c0f19 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -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; } diff --git a/test/javascripts/lib/bbcode-test.js.es6 b/test/javascripts/lib/bbcode-test.js.es6 index 385569c9c05..7aa30ed91bb 100644 --- a/test/javascripts/lib/bbcode-test.js.es6 +++ b/test/javascripts/lib/bbcode-test.js.es6 @@ -160,6 +160,13 @@ test("quote formatting", function() { "", "handles mismatched nested quote tags"); + + formatQ("[quote=\"Alice, post:1, topic:1\"]\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]", + "", + "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]", + "", + "quotes can have code blocks with leading newline"); }); test("quotes with trailing formatting", function() {