FIX: `<pre>` blocks were adding too many new lines.

This commit is contained in:
Robin Ward 2014-06-23 15:21:07 -04:00
parent 68d323faaf
commit ff55a30dd7
3 changed files with 22 additions and 5 deletions

View File

@ -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 `<code>` 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: /(<pre[^\>]*\>)([\s\S]*)/igm,
stop: '</pre>',
rawContents: true,
skipIfTradtionalLinebreaks: true,
emitter: function(blockContents) {
return ['p', ['pre', blockContents.join("\n")]];
}
});

View File

@ -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);

View File

@ -282,6 +282,10 @@ test("links with full urls", function() {
test("Code Blocks", function() {
cooked("<pre>\nhello\n</pre>\n",
"<p><pre>\nhello</pre></p>",
"pre blocks don't include extra lines");
cooked("```\na\nb\nc\n\nd\n```",
"<p><pre><code class=\"lang-auto\">a\nb\nc\n\nd</code></pre></p>",
"it treats new lines properly");