/** * Tests the github extension for showdown * */ /*globals describe, it */ var testUtils = require('../utils'), should = require('should'), // Stuff we are testing ghPath = "../../shared/vendor/showdown/extensions/github.js", github = require(ghPath); function _ExecuteExtension(ext, text) { if (ext.regex) { var re = new RegExp(ext.regex, 'g'); return text.replace(re, ext.replace); } else if (ext.filter) { return ext.filter(text); } } function _ConvertPhrase(testPhrase) { return github().reduce(function (text, ext) { return _ExecuteExtension(ext, text); }, testPhrase); } describe("Github showdown extensions", function () { /*jslint regexp: true */ it("should export an array of methods for processing", function () { github.should.be.a.function; github().should.be.an.Array; github().forEach(function (processor) { processor.should.be.an.Object; processor.should.have.property("type"); processor.type.should.be.a.String; }); }); it("should replace showdown strike through with html", function () { var testPhrase = {input: "~T~Tfoo_bar~T~T", output: /foo_bar<\/del>/}, processedMarkup = _ConvertPhrase(testPhrase.input); // The image is the entire markup, so the image box should be too processedMarkup.should.match(testPhrase.output); }); it("should auto-link URL in text with markdown syntax", function () { var testPhrases = [ { input: "http://google.co.uk", output: /^http:\/\/google.co.uk<\/a>$/ }, { input: "https://atest.com/fizz/buzz?baz=fizzbuzz", output: /^https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz<\/a>$/ }, { input: "Some text http://www.google.co.uk some other text", output: /^Some text http:\/\/www.google.co.uk<\/a> some other text$/ }, { input: "Some [ text http://www.google.co.uk some other text", output: /^Some \[ text http:\/\/www.google.co.uk<\/a> some other text$/ }, { input: "Some [ text (http://www.google.co.uk) some other text", output: /^Some \[ text \(http:\/\/www.google.co.uk<\/a>\) some other text$/ }, { input: " http://google.co.uk ", output: /^ http:\/\/google.co.uk<\/a> $/ }, { input: ">http://google.co.uk", output: /^>http:\/\/google.co.uk<\/a>$/ }, { input: "> http://google.co.uk", output: /^> http:\/\/google.co.uk<\/a>$/ }, { input: "<>>> http://google.co.uk", output: /^<>>> http:\/\/google.co.uk<\/a>$/ }, { input: "<>>>http://google.co.uk", output: /^<>>>http:\/\/google.co.uk<\/a>$/ }, { input: ">>http://google.co.uk", output: /^>>http:\/\/google.co.uk<\/a>$/ }, { input: "http://google.co.uk", output: /^http:\/\/google.co.uk<\/a>$/ }, { input: "# http://google.co.uk", output: /^# http:\/\/google.co.uk<\/a>$/ }, { input: "#http://google.co.uk", output: /^#http:\/\/google.co.uk<\/a>$/ }, { input: "* http://google.co.uk", output: /^\* http:\/\/google.co.uk<\/a>$/ } ], processedMarkup; testPhrases.forEach(function (testPhrase) { processedMarkup = _ConvertPhrase(testPhrase.input); processedMarkup.should.match(testPhrase.output); }); }); it("should auto-link Email", function () { var testPhrase = {input: "info@tryghost.org", output: /^info@tryghost.org<\/a>$/}, processedMarkup = _ConvertPhrase(testPhrase.input); processedMarkup.should.match(testPhrase.output); }); it("should NOT auto-link URL in HTML", function () { var testPhrases = [ { input: '', output: /^$/ }, { input: '', output: /^$/ }, { input: '', output: /^