/** * Tests the github extension for showdown * */ /*globals describe, it */ /*jshint expr:true*/ var should = require('should'), // Stuff we are testing ghostgfm = require('../../shared/lib/showdown/extensions/ghostgfm'); // To stop jshint complaining should.equal(true, true); 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 ghostgfm().reduce(function (text, ext) { return _ExecuteExtension(ext, text); }, testPhrase); } describe('Ghost GFM showdown extension', function () { /*jslint regexp: true */ it('should export an array of methods for processing', function () { ghostgfm.should.be.a.function; ghostgfm().should.be.an.Array; ghostgfm().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 honour escaped tildes', function () { /*jshint -W044 */ var testPhrase = {input: '\\~T\\~Tfoo_bar\\~T\\~T', output: /~T~Tfoo_bar~T~T/}, /*jshint +W044 */ processedMarkup = _ConvertPhrase(testPhrase.input); // The image is the entire markup, so the image box should be too processedMarkup.should.match(testPhrase.output); }); it('should allow 4 underscores', function () { var testPhrase = {input: 'Ghost ____', output: /Ghost\s(?:_){4}$/}, processedMarkup = _ConvertPhrase(testPhrase.input); 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 NOT auto-link URL in HTML', function () { var testPhrases = [ { input: '', output: /^$/ }, { input: '', output: /^$/ }, { input: '', output: /^