mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: <pre>
blocks were adding too many new lines.
This commit is contained in:
parent
68d323faaf
commit
ff55a30dd7
3 changed files with 22 additions and 5 deletions
|
@ -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")]];
|
||||
}
|
||||
});
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue