2013-09-12 03:52:37 +08:00
|
|
|
module("MDTest", {
|
|
|
|
setup: function() {
|
|
|
|
Discourse.SiteSettings.traditional_markdown_linebreaks = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// This is cheating, but the trivial differences between sanitization
|
2014-03-04 02:14:11 +08:00
|
|
|
// do not affect formatting.
|
2013-09-12 03:52:37 +08:00
|
|
|
function normalize(str) {
|
|
|
|
return str.replace(/\n\s*/g, '').
|
2014-07-04 04:54:56 +08:00
|
|
|
replace(/ \/\>/g, '>').
|
2013-09-12 03:52:37 +08:00
|
|
|
replace(/ ?/g, "\t").
|
|
|
|
replace(/"/g, '"');
|
|
|
|
}
|
|
|
|
|
2014-07-04 04:54:56 +08:00
|
|
|
// We use a custom sanitizer for MD test that hoists out comments. In Discourse
|
|
|
|
// they are stripped, but to be compliant with the spec they should not be.
|
|
|
|
function hoistingSanitizer(result) {
|
|
|
|
var hoisted,
|
|
|
|
m = result.match(/<!--[\s\S]*?-->/g);
|
|
|
|
if (m && m.length) {
|
|
|
|
hoisted = [];
|
|
|
|
for (var i=0; i<m.length; i++) {
|
|
|
|
var c = m[i],
|
2014-07-05 02:14:50 +08:00
|
|
|
id = md5("discourse:hoisted-comment:" + i);
|
2014-07-04 04:54:56 +08:00
|
|
|
result = result.replace(c, id);
|
|
|
|
hoisted.push([c, id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = Discourse.Markdown.sanitize(result);
|
|
|
|
|
|
|
|
if (hoisted) {
|
|
|
|
hoisted.forEach(function(tuple) {
|
|
|
|
result = result.replace(tuple[1], tuple[0]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-12 03:52:37 +08:00
|
|
|
var md = function(input, expected, text) {
|
2014-07-04 04:54:56 +08:00
|
|
|
var result = Discourse.Markdown.cook(input, {
|
|
|
|
sanitizerFunction: hoistingSanitizer,
|
|
|
|
traditional_markdown_linebreaks: true
|
|
|
|
}),
|
2013-09-12 03:52:37 +08:00
|
|
|
resultNorm = normalize(result),
|
|
|
|
expectedNorm = normalize(expected),
|
|
|
|
same = (result === expected) || (resultNorm === expectedNorm);
|
|
|
|
|
|
|
|
if (same) {
|
|
|
|
ok(same, text);
|
|
|
|
} else {
|
|
|
|
console.log(resultNorm);
|
|
|
|
console.log(expectedNorm);
|
|
|
|
equal(resultNorm, expectedNorm, text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
test("first", function(){
|
|
|
|
equal(1, 1, "cool")
|
|
|
|
});
|
|
|
|
|
|
|
|
<%
|
|
|
|
def mdtest_suite
|
|
|
|
result = ""
|
|
|
|
Dir.glob("#{Rails.root}/test/javascripts/mdtest/fixtures/*.text").each do |f|
|
|
|
|
|
|
|
|
filename_no_ext = f.sub(/\.text$/, '')
|
|
|
|
filename = Pathname.new(filename_no_ext)
|
|
|
|
|
|
|
|
text = File.read(f)
|
2013-10-19 03:20:27 +08:00
|
|
|
html = File.read("#{filename_no_ext}.xhtml");
|
2013-09-12 03:52:37 +08:00
|
|
|
result << "test(\"#{filename}\", function() { md(#{text.to_json}, #{html.to_json}, 'passes MDTest'); });\n"
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
%>
|
|
|
|
|
2014-02-12 07:00:53 +08:00
|
|
|
<%= mdtest_suite %>
|