diff --git a/app/assets/javascripts/discourse/dialects/github_code_dialect.js b/app/assets/javascripts/discourse/dialects/code_dialect.js similarity index 84% rename from app/assets/javascripts/discourse/dialects/github_code_dialect.js rename to app/assets/javascripts/discourse/dialects/code_dialect.js index d3898bc24..8f0ff739a 100644 --- a/app/assets/javascripts/discourse/dialects/github_code_dialect.js +++ b/app/assets/javascripts/discourse/dialects/code_dialect.js @@ -1,9 +1,5 @@ /** - Support for github style code blocks, here you begin with three backticks and supply a language, - The language is made into a class on the resulting `` element. - - @event register - @namespace Discourse.Dialect + Support for various code blocks **/ var acceptableCodeClasses = @@ -46,3 +42,14 @@ Discourse.Dialect.on('parseNode', function (event) { node[node.length-1] = Handlebars.Utils.escapeExpression(contents.replace(regexp,'')); } }); + +Discourse.Dialect.replaceBlock({ + start: /(]*\>)([\s\S]*)/igm, + stop: '', + rawContents: true, + skipIfTradtionalLinebreaks: true, + + emitter: function(blockContents) { + return ['p', ['pre', blockContents.join("\n")]]; + } +}); diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index cd86601b4..2ed99d769 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -333,6 +333,12 @@ Discourse.Dialect = { replaceBlock: function(args) { this.registerBlock(args.start.toString(), function(block, next) { + var linebreaks = dialect.options.traditional_markdown_linebreaks || + Discourse.SiteSettings.traditional_markdown_linebreaks; + + // Some replacers should not be run with traditional linebreaks + if (linebreaks && args.skipIfTradtionalLinebreaks) { return; } + args.start.lastIndex = 0; var m = (args.start).exec(block); diff --git a/test/javascripts/lib/markdown_test.js b/test/javascripts/lib/markdown_test.js index d375e256c..1b7665570 100644 --- a/test/javascripts/lib/markdown_test.js +++ b/test/javascripts/lib/markdown_test.js @@ -282,6 +282,10 @@ test("links with full urls", function() { test("Code Blocks", function() { + cooked("
\nhello\n
\n", + "

\nhello

", + "pre blocks don't include extra lines"); + cooked("```\na\nb\nc\n\nd\n```", "

a\nb\nc\n\nd

", "it treats new lines properly");