From 2fd96d2bb7e4fe5a9210d924d8670ffad78a73e2 Mon Sep 17 00:00:00 2001 From: mathematicalcoffee Date: Fri, 28 Dec 2012 15:03:35 +1000 Subject: [PATCH 1/2] fix: env.conf.markdown.hardwrap is now respected. --- .../scripts/showdown.js | 2 +- test/specs/jsdoc/util/markdown.js | 74 ++++++++++++++----- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/node_modules/github-flavored-markdown/scripts/showdown.js b/node_modules/github-flavored-markdown/scripts/showdown.js index 0f506eb0..4efc3e0f 100644 --- a/node_modules/github-flavored-markdown/scripts/showdown.js +++ b/node_modules/github-flavored-markdown/scripts/showdown.js @@ -151,7 +151,7 @@ this.makeHtml = function(text, gh) { g_html_blocks = new Array(); // benblank - Allow hardwrapping to be disabled. - g_hardwrap = typeof this.hardwrap === "undefined" || this.hardwrap; + g_hardwrap = (typeof exports.hardwrap === "undefined" || exports.hardwrap); // attacklab: Replace ~ with ~T // This lets us use tilde as an escape char to avoid md5 hashes diff --git a/test/specs/jsdoc/util/markdown.js b/test/specs/jsdoc/util/markdown.js index f6ae402a..ba759861 100644 --- a/test/specs/jsdoc/util/markdown.js +++ b/test/specs/jsdoc/util/markdown.js @@ -13,6 +13,31 @@ describe('jsdoc/util/markdown', function() { }); describe('getParser', function() { + // couple of convenience functions letting me set conf variables and restore + // them back to the originals later. + function setMarkdownConf(hash) { + if (!env.conf.markdown) { + env.conf.markdown = {}; + } + var keys = Object.keys(hash); + var storage = {}; + for (var i = 0; i < keys.length; ++i) { + storage[keys[i]] = env.conf.markdown[keys[i]]; + // works because hash[key] is a scalar not an array/object + env.conf.markdown[keys[i]] = hash[keys[i]]; + } + return storage; + } + + function restoreMarkdownConf(storage) { + var keys = Object.keys(storage); + for (var i = 0; i < keys.length; ++i) { + env.conf.markdown[keys[i]] = storage[keys[i]]; + } + if (keys.length === 0) { + delete env.conf.markdown; + } + } xit('should retrieve a function when called with default settings', function() { // TODO }); @@ -30,39 +55,52 @@ describe('jsdoc/util/markdown', function() { }); it('should not apply formatting to inline tags when the evilstreak parser is enabled', function() { - // store the old configuration - var old = (env.conf.markdown ? env.conf.markdown.parser : undefined); - env.conf.markdown = {parser: 'evilstreak'}; + var storage = setMarkdownConf({parser: 'evilstreak'}); // get the evilstreak parser and do the test var parser = markdown.getParser(); expect(parser('{@link MyClass#_x} and {@link MyClass#_y}')).toEqual( '

{@link MyClass#_x} and {@link MyClass#_y}

'); - // restore the old value - if (old === undefined) { - env.conf.markdown.parser = old; - } else { - delete env.conf.markdown; - } + restoreMarkdownConf(storage); }); it('should not apply formatting to inline tags when the GFM parser is enabled', function() { - // store the old configuration - var old = (env.conf.markdown ? env.conf.markdown.parser : undefined); - env.conf.markdown = {parser: 'gfm'}; + var storage = setMarkdownConf({parser: 'gfm'}); // get the gfm parser and do the test var parser = markdown.getParser(); expect(parser('{@link MyClass#_x} and {@link MyClass#_y}')).toEqual( '

{@link MyClass#_x} and {@link MyClass#_y}

'); - // restore the old value - if (old === undefined) { - env.conf.markdown.parser = old; - } else { - delete env.conf.markdown; - } + restoreMarkdownConf(storage); }); + + it('GFM parser with no conf.markdown.hardwrap has it to false', function() { + var storage = setMarkdownConf({parser: 'gfm'}); + + var parser = markdown.getParser(); + expect(parser('Testing\nhardwrap')).toEqual('

Testing\nhardwrap

'); + + restoreMarkdownConf(storage); + }); + + it('GFM parser respects conf.markdown.hardwrap=false', function() { + var storage = setMarkdownConf({parser: 'gfm', hardwrap: false}); + + var parser = markdown.getParser(); + expect(parser('Testing\nhardwrap')).toEqual('

Testing\nhardwrap

'); + + restoreMarkdownConf(storage); + }); + + it('GFM parser respects conf.markdown.hardwrap=true', function() { + var storage = setMarkdownConf({parser: 'gfm', hardwrap: true}); + + var parser = markdown.getParser(); + expect(parser('Testing\nhardwrap')).toEqual('

Testing
hardwrap

'); + + restoreMarkdownConf(storage); + }); }); }); From 24a3c6b448332986ef45c3126ef1f9ef2d2b1e72 Mon Sep 17 00:00:00 2001 From: mathematicalcoffee Date: Fri, 28 Dec 2012 23:53:07 +1000 Subject: [PATCH 2/2] filled out markdown tests for getParser to test asking for specific parsers --- lib/jsdoc/util/markdown.js | 9 +++- test/specs/jsdoc/util/markdown.js | 70 +++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/lib/jsdoc/util/markdown.js b/lib/jsdoc/util/markdown.js index 0711d4d9..ae1350e5 100644 --- a/lib/jsdoc/util/markdown.js +++ b/lib/jsdoc/util/markdown.js @@ -48,6 +48,7 @@ function escapeUnderscores(source) { */ function getParseFunction(parser, conf) { conf = conf || {}; + var parse; if (parser === parsers.gfm) { parser = require(parser); @@ -61,19 +62,23 @@ function getParseFunction(parser, conf) { parser.hardwrap = !!conf.hardwrap; - return function(source) { + parse = function(source) { source = escapeUnderscores(source); return parser.parse(source, githubConf); }; + parse._parser = parsers.gfm; + return parse; } else if (parser === parsers.evilstreak) { parser = require(parser).markdown; - return function(source) { + parse = function(source) { source = escapeUnderscores(source); // evilstreak parser expects line endings to be \n source = source.replace(/\r\n|\r/g, '\n'); return parser.toHTML(source, conf.dialect); }; + parse._parser = parsers.evilstreak; + return parse; } else { throw new Error("unknown Markdown parser: '" + parser + "'"); } diff --git a/test/specs/jsdoc/util/markdown.js b/test/specs/jsdoc/util/markdown.js index ba759861..f4b2fe24 100644 --- a/test/specs/jsdoc/util/markdown.js +++ b/test/specs/jsdoc/util/markdown.js @@ -38,20 +38,74 @@ describe('jsdoc/util/markdown', function() { delete env.conf.markdown; } } - xit('should retrieve a function when called with default settings', function() { - // TODO + + it('should retrieve a function when called with default settings', function() { + var storage = setMarkdownConf({parser: 'evilstreak'}); + + var parser = markdown.getParser(); + expect(typeof parser).toEqual('function'); + + setMarkdownConf({parser: 'gfm'}); + parser = markdown.getParser(); + expect(typeof parser).toEqual('function'); + + restoreMarkdownConf(storage); }); - xit('should use the evilstreak parser when requested', function() { - // TODO + it('should use the evilstreak parser when requested', function() { + var storage = setMarkdownConf({parser: 'evilstreak'}); + var parser = markdown.getParser(); + expect(parser._parser).toEqual('markdown'); + restoreMarkdownConf(storage); }); - xit('should use the GFM parser when requested', function() { - // TODO + it('should use the GFM parser when requested', function() { + var storage = setMarkdownConf({parser: 'gfm'}); + var parser = markdown.getParser(); + expect(parser._parser).toEqual('github-flavored-markdown'); + restoreMarkdownConf(storage); }); - xit('should convert GitHub repo references to links when the correct options are defined', function() { - // TODO + it('should use GFM parser when parser is not specified but github owner and repo are', function() { + var storage = setMarkdownConf({githubRepoOwner: 'jsdoc', githubRepoName: 'jsdoc3'}); + var parser = markdown.getParser(); + expect(parser._parser).toEqual('github-flavored-markdown'); + restoreMarkdownConf(storage); + }); + + it('should convert GitHub repo references to links when the correct options are defined', function() { + var storage = setMarkdownConf({parser: 'gfm', githubRepoOwner: 'jsdoc', githubRepoName: 'jsdoc3'}); + var parser = markdown.getParser(); + expect(parser._parser).toEqual('github-flavored-markdown'); + + var sha = '228c940816b5f799a12f83f071a1c67cbb478f39'; + var sha7 = sha.substr(0, 7); + + // Auto-link sha1 if GitHub.nameWithOwner is defined + expect(parser(sha)).toEqual( + "

" + sha7 + "

"); + + // ** GFM ** Auto-link user@sha1 if GitHub.nameWithOwner is defined + expect(parser('mathematicalcoffee@' + sha)).toEqual( + "

mathematicalcoffee@" + sha7 + "

"); + + // ** GFM ** Auto-link user/repo@sha1 + expect(parser('jsdoc/jsdoc3@' + sha)).toEqual( + "

jsdoc/jsdoc3@" + sha7 + "

"); + + // ** GFM ** Auto-link #issue if GitHub.nameWithOwner is defined + expect(parser('Fixes #1')).toEqual( + "

Fixes #1

"); + + // ** GFM ** Auto-link user#issue if GitHub.nameWithOwner is defined + expect(parser('mathematicalcoffee#12')).toEqual( + "

mathematicalcoffee#12

"); + + // ** GFM ** Auto-link user/repo#issue + expect(parser('jsdoc/jsdoc3#1')).toEqual( + "

jsdoc/jsdoc3#1

"); + + restoreMarkdownConf(storage); }); it('should not apply formatting to inline tags when the evilstreak parser is enabled', function() {