From 3d62df51a61211f1e97e7544e6c9a145a45b9e37 Mon Sep 17 00:00:00 2001
From: Robin Ward
Date: Tue, 11 Feb 2014 17:27:01 -0500
Subject: [PATCH] FIX: Broken MDTest + Fix for removing leading spaces in a
code block
---
.../discourse/dialects/github_code_dialect.js | 19 ++++++++++++++++---
.../Markdown Documentation - Syntax.xhtml | 2 +-
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/app/assets/javascripts/discourse/dialects/github_code_dialect.js b/app/assets/javascripts/discourse/dialects/github_code_dialect.js
index c4f38f814a9..d3898bc24ce 100644
--- a/app/assets/javascripts/discourse/dialects/github_code_dialect.js
+++ b/app/assets/javascripts/discourse/dialects/github_code_dialect.js
@@ -29,7 +29,20 @@ Discourse.Dialect.replaceBlock({
// Ensure that content in a code block is fully escaped. This way it's not white listed
// and we can use HTML and Javascript examples.
-Discourse.Dialect.postProcessTag('code', function (contents) {
- return Handlebars.Utils.escapeExpression(contents.replace(/^ +| +$/g,''));
-});
+Discourse.Dialect.on('parseNode', function (event) {
+ var node = event.node,
+ path = event.path;
+ if (node[0] === 'code') {
+ var contents = node[node.length-1],
+ regexp;
+
+ if (path && path[path.length-1] && path[path.length-1][0] && path[path.length-1][0] === "pre") {
+ regexp = / +$/g;
+
+ } else {
+ regexp = /^ +| +$/g;
+ }
+ node[node.length-1] = Handlebars.Utils.escapeExpression(contents.replace(regexp,''));
+ }
+});
diff --git a/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml b/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml
index 5c6b9e32b7c..2a83541bdcd 100755
--- a/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml
+++ b/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml
@@ -524,7 +524,7 @@ easy to include example HTML source code using Markdown -- just paste
it and indent it, and Markdown will handle the hassle of encoding the
ampersands and angle brackets. For example, this:
-<div class="footer">
+ <div class="footer">
© 2004 Foo Corporation
</div>