diff --git a/app/assets/javascripts/discourse/dialects/bbcode_dialect.js b/app/assets/javascripts/discourse/dialects/bbcode_dialect.js index 53016958921..74f2968b9a1 100644 --- a/app/assets/javascripts/discourse/dialects/bbcode_dialect.js +++ b/app/assets/javascripts/discourse/dialects/bbcode_dialect.js @@ -108,6 +108,7 @@ Discourse.Dialect.replaceBlock({ rawContents: true, emitter: function(blockContents) { - return ['p', ['pre'].concat(blockContents.join("\n"))]; + var inner = blockContents.join("\n").replace(/^\s+/,''); + return ['p', ['pre', ['code', {'class': Discourse.SiteSettings.default_code_lang}, inner]]]; } }); diff --git a/test/javascripts/lib/bbcode_test.js b/test/javascripts/lib/bbcode_test.js index 10f1d14aa61..9cf12fdfa7e 100644 --- a/test/javascripts/lib/bbcode_test.js +++ b/test/javascripts/lib/bbcode_test.js @@ -25,9 +25,9 @@ test('invalid bbcode', function() { }); test('code', function() { - format("[code]\nx++\n[/code]", "
\nx++
", "makes code into pre"); - format("[code]\nx++\ny++\nz++\n[/code]", "
\nx++\ny++\nz++
", "makes code into pre"); - format("[code]abc\n#def\n[/code]", '
abc\n#def
', 'it handles headings in a [code] block'); + format("[code]\nx++\n[/code]", "
x++
", "makes code into pre"); + format("[code]\nx++\ny++\nz++\n[/code]", "
x++\ny++\nz++
", "makes code into pre"); + format("[code]abc\n#def\n[/code]", '
abc\n#def
', 'it handles headings in a [code] block'); }); test('spoiler', function() {