FIX: `<pre>` blocks were adding too many new lines.
This commit is contained in:
parent
68d323faaf
commit
ff55a30dd7
|
@ -1,9 +1,5 @@
|
||||||
/**
|
/**
|
||||||
Support for github style code blocks, here you begin with three backticks and supply a language,
|
Support for various code blocks
|
||||||
The language is made into a class on the resulting `<code>` element.
|
|
||||||
|
|
||||||
@event register
|
|
||||||
@namespace Discourse.Dialect
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var acceptableCodeClasses =
|
var acceptableCodeClasses =
|
||||||
|
@ -46,3 +42,14 @@ Discourse.Dialect.on('parseNode', function (event) {
|
||||||
node[node.length-1] = Handlebars.Utils.escapeExpression(contents.replace(regexp,''));
|
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")]];
|
||||||
|
}
|
||||||
|
});
|
|
@ -333,6 +333,12 @@ Discourse.Dialect = {
|
||||||
replaceBlock: function(args) {
|
replaceBlock: function(args) {
|
||||||
this.registerBlock(args.start.toString(), function(block, next) {
|
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;
|
args.start.lastIndex = 0;
|
||||||
var m = (args.start).exec(block);
|
var m = (args.start).exec(block);
|
||||||
|
|
||||||
|
|
|
@ -282,6 +282,10 @@ test("links with full urls", function() {
|
||||||
|
|
||||||
test("Code Blocks", 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```",
|
cooked("```\na\nb\nc\n\nd\n```",
|
||||||
"<p><pre><code class=\"lang-auto\">a\nb\nc\n\nd</code></pre></p>",
|
"<p><pre><code class=\"lang-auto\">a\nb\nc\n\nd</code></pre></p>",
|
||||||
"it treats new lines properly");
|
"it treats new lines properly");
|
||||||
|
|
Loading…
Reference in New Issue