From 0da96264080ea3cabd1f40d8417b91d8bd842c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Soares=20dos=20Santos?= Date: Mon, 19 Jan 2015 14:57:43 +0000 Subject: [PATCH] chore(): code fix to pass jscs linter --- src/angular.js | 9 +- src/helpers.js | 116 ++++++++---------- src/loader.js | 12 +- src/subParsers/anchors.js | 14 +-- src/subParsers/autoLinks.js | 4 - src/subParsers/blockGamut.js | 6 +- src/subParsers/blockQuotes.js | 4 - src/subParsers/codeBlocks.js | 4 - src/subParsers/codeSpans.js | 4 - src/subParsers/detab.js | 4 - src/subParsers/encodeAmpsAndAngles.js | 4 - src/subParsers/encodeBackslashEscapes.js | 4 - src/subParsers/encodeCode.js | 4 - src/subParsers/encodeEmailAddress.js | 4 - .../escapeSpecialCharsWithinTagAttributes.js | 6 +- src/subParsers/githubCodeBlocks.js | 4 - src/subParsers/hashBlock.js | 4 - src/subParsers/hashElement.js | 4 - src/subParsers/hashHTMLBlocks.js | 4 - src/subParsers/headers.js | 4 - src/subParsers/images.js | 6 +- src/subParsers/italicsAndBold.js | 4 - src/subParsers/lists.js | 6 +- src/subParsers/outdent.js | 4 - src/subParsers/paragraphs.js | 10 +- src/subParsers/spanGamut.js | 4 - src/subParsers/stripBlankLines.js | 4 - src/subParsers/stripLinkDefinitions.js | 4 - src/subParsers/unescapeSpecialChars.js | 4 - test/node/Container/testMakeHtml.js | 19 ++- 30 files changed, 84 insertions(+), 200 deletions(-) diff --git a/src/angular.js b/src/angular.js index f652dbc..46220f1 100644 --- a/src/angular.js +++ b/src/angular.js @@ -1,8 +1,3 @@ -/** - * Created by Tivie on 04-11-2014. - */ - - //Check if AngularJs and Showdown is defined and only load ng-Showdown if both are present if (typeof angular !== 'undefined' && typeof showdown !== 'undefined') { @@ -11,7 +6,7 @@ if (typeof angular !== 'undefined' && typeof showdown !== 'undefined') { module .provider('$showdown', provider) - .directive('sdModelToHtml',['$showdown', markdownToHtmlDirective]) + .directive('sdModelToHtml', ['$showdown', markdownToHtmlDirective]) .filter('sdStripHtml', stripHtmlFilter); /** @@ -104,7 +99,7 @@ if (typeof angular !== 'undefined' && typeof showdown !== 'undefined') { * Usage example: *
* - * @param $showdown + * @param {showdown.Converter} $showdown * @returns {*} */ function markdownToHtmlDirective($showdown) { diff --git a/src/helpers.js b/src/helpers.js index c0000f5..1e82b87 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,13 +1,27 @@ /** - * Created by Estevao on 11-01-2015. + * showdownjs helper functions */ -function isString(a) { - 'use strict'; - return (typeof a === 'string' || a instanceof String); +if (!showdown.hasOwnProperty('helper')) { + showdown.helper = {}; } -function forEach(obj, callback) { +/** + * Check if var is string + * @param {string} a + * @returns {boolean} + */ +showdown.helper.isString = function isString(a) { + 'use strict'; + return (typeof a === 'string' || a instanceof String); +}; + +/** + * ForEach helper function + * @param {*} obj + * @param {function} callback + */ +showdown.helper.forEach = function forEach(obj, callback) { 'use strict'; if (typeof obj.forEach === 'function') { obj.forEach(callback); @@ -17,25 +31,51 @@ function forEach(obj, callback) { callback(obj[i], i, obj); } } -} +}; -function isArray(a) { +/** + * isArray helper function + * @param {*} a + * @returns {boolean} + */ +showdown.helper.isArray = function isArray(a) { 'use strict'; return a.constructor === Array; -} +}; -function isUndefined(value) { +/** + * Check if value is undefined + * + * @static + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. + */ +showdown.helper.isUndefined = function isUndefined(value) { 'use strict'; return typeof value === 'undefined'; -} +}; -var escapeCharactersCallback = function (wholeMatch, m1) { +/** + * Callback used to escape characters when passing through String.replace + * @param {string} wholeMatch + * @param {string} m1 + * @returns {string} + */ +showdown.helper.escapeCharactersCallback = function escapeCharactersCallback(wholeMatch, m1) { 'use strict'; var charCodeToEscape = m1.charCodeAt(0); return '~E' + charCodeToEscape + 'E'; }; -var escapeCharacters = function (text, charsToEscape, afterBackslash) { +/** + * Escape characters in a string + * + * @param {string} text + * @param {string} charsToEscape + * @param {boolean} afterBackslash + * @returns {XML|string|void|*} + */ +showdown.helper.escapeCharacters = function escapeCharacters(text, charsToEscape, afterBackslash) { 'use strict'; // First we have to escape the escape characters so that // we can build a character class out of them @@ -50,55 +90,3 @@ var escapeCharacters = function (text, charsToEscape, afterBackslash) { return text; }; - -if (!showdown.hasOwnProperty('helper')) { - showdown.helper = {}; -} - -/** - * isString helper function - * @param a - * @returns {boolean} - */ -showdown.helper.isString = isString; - -/** - * ForEach helper function - * @param {*} obj - * @param callback - */ -showdown.helper.forEach = forEach; - -/** - * isArray helper function - * @param {*} a - * @returns {boolean} - */ -showdown.helper.isArray = isArray; - -/** - * Check if value is undefined - * - * @static - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. - */ -showdown.helper.isUndefined = isUndefined; - -/** - * Callback used to escape characters when passing through String.replace - * @param {string} wholeMatch - * @param {string} m1 - * @returns {string} - */ -showdown.helper.escapeCharactersCallback = escapeCharactersCallback; - -/** - * Escape characters in a string - * - * @param {string} text - * @param {string} charsToEscape - * @param {boolean} afterBackslash - * @returns {XML|string|void|*} - */ -showdown.helper.escapeCharacters = escapeCharacters; diff --git a/src/loader.js b/src/loader.js index 6fceaa5..255ed92 100644 --- a/src/loader.js +++ b/src/loader.js @@ -1,21 +1,17 @@ -/** - * Created by Estevao on 15-01-2015. - */ - var root = this; // CommonJS/nodeJS Loader if (typeof module !== 'undefined' && module.exports) { module.exports = showdown; -} + // AMD Loader -else if (typeof define === 'function' && define.amd) { +} else if (typeof define === 'function' && define.amd) { define('showdown', function () { 'use strict'; return showdown; }); -} + // Regular Browser loader -else { +} else { root.showdown = showdown; } diff --git a/src/subParsers/anchors.js b/src/subParsers/anchors.js index d54a674..6551384 100644 --- a/src/subParsers/anchors.js +++ b/src/subParsers/anchors.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Turn Markdown link shortcuts into XHTML tags. */ @@ -40,12 +36,12 @@ showdown.subParser('anchors', function (text, config, globals) { } } - url = showdown.helper.escapeCharacters(url, '*_'); + url = showdown.helper.escapeCharacters(url, '*_', false); var result = '` blocks. */ diff --git a/src/subParsers/codeSpans.js b/src/subParsers/codeSpans.js index a2feb9b..639ffa8 100644 --- a/src/subParsers/codeSpans.js +++ b/src/subParsers/codeSpans.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * * * Backtick quotes are used for spans. diff --git a/src/subParsers/detab.js b/src/subParsers/detab.js index 08ba0db..b3c6d65 100644 --- a/src/subParsers/detab.js +++ b/src/subParsers/detab.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Convert all tabs to spaces */ diff --git a/src/subParsers/encodeAmpsAndAngles.js b/src/subParsers/encodeAmpsAndAngles.js index 370aff0..984cd2e 100644 --- a/src/subParsers/encodeAmpsAndAngles.js +++ b/src/subParsers/encodeAmpsAndAngles.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Smart processing for ampersands and angle brackets that need to be encoded. */ diff --git a/src/subParsers/encodeBackslashEscapes.js b/src/subParsers/encodeBackslashEscapes.js index cbf4817..ee2cce2 100644 --- a/src/subParsers/encodeBackslashEscapes.js +++ b/src/subParsers/encodeBackslashEscapes.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Returns the string, with after processing the following backslash escape sequences. * diff --git a/src/subParsers/encodeCode.js b/src/subParsers/encodeCode.js index 9feb4f2..0ae9645 100644 --- a/src/subParsers/encodeCode.js +++ b/src/subParsers/encodeCode.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Encode/escape certain characters inside Markdown code runs. * The point is that in code, these characters are literals, diff --git a/src/subParsers/encodeEmailAddress.js b/src/subParsers/encodeEmailAddress.js index 6a7b734..925b3cc 100644 --- a/src/subParsers/encodeEmailAddress.js +++ b/src/subParsers/encodeEmailAddress.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 12-01-2015. - */ - /** * Input: an email address, e.g. "foo@example.com" * diff --git a/src/subParsers/escapeSpecialCharsWithinTagAttributes.js b/src/subParsers/escapeSpecialCharsWithinTagAttributes.js index 46dac21..a363f19 100644 --- a/src/subParsers/escapeSpecialCharsWithinTagAttributes.js +++ b/src/subParsers/escapeSpecialCharsWithinTagAttributes.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Within tags -- meaning between < and > -- encode [\ ` * _] so they * don't conflict with their use in Markdown for code, italics and strong. @@ -15,7 +11,7 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) { text = text.replace(regex, function (wholeMatch) { var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g, '$1`'); - tag = showdown.helper.escapeCharacters(tag, '\\`*_'); + tag = showdown.helper.escapeCharacters(tag, '\\`*_', false); return tag; }); diff --git a/src/subParsers/githubCodeBlocks.js b/src/subParsers/githubCodeBlocks.js index 2bbaa6e..c59a2b0 100644 --- a/src/subParsers/githubCodeBlocks.js +++ b/src/subParsers/githubCodeBlocks.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Handle github codeblocks prior to running HashHTML so that * HTML contained within the codeblock gets escaped properly diff --git a/src/subParsers/hashBlock.js b/src/subParsers/hashBlock.js index ccd0c1a..3196f1d 100644 --- a/src/subParsers/hashBlock.js +++ b/src/subParsers/hashBlock.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - showdown.subParser('hashBlock', function (text, options, globals) { 'use strict'; text = text.replace(/(^\n+|\n+$)/g, ''); diff --git a/src/subParsers/hashElement.js b/src/subParsers/hashElement.js index 6a836d7..7bf1291 100644 --- a/src/subParsers/hashElement.js +++ b/src/subParsers/hashElement.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - showdown.subParser('hashElement', function (text, options, globals) { 'use strict'; diff --git a/src/subParsers/hashHTMLBlocks.js b/src/subParsers/hashHTMLBlocks.js index 013f4d6..27aa8b6 100644 --- a/src/subParsers/hashHTMLBlocks.js +++ b/src/subParsers/hashHTMLBlocks.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - showdown.subParser('hashHTMLBlocks', function (text, options, globals) { 'use strict'; diff --git a/src/subParsers/headers.js b/src/subParsers/headers.js index a4ab4c4..e723098 100644 --- a/src/subParsers/headers.js +++ b/src/subParsers/headers.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - showdown.subParser('headers', function (text, options, globals) { 'use strict'; diff --git a/src/subParsers/images.js b/src/subParsers/images.js index 0367559..8c3d811 100644 --- a/src/subParsers/images.js +++ b/src/subParsers/images.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Turn Markdown image shortcuts into tags. */ @@ -40,7 +36,7 @@ showdown.subParser('images', function (text, options, globals) { } altText = altText.replace(/"/g, '"'); - url = showdown.helper.escapeCharacters(url, '*_'); + url = showdown.helper.escapeCharacters(url, '*_', false); var result = '' + altText + ' must go first: diff --git a/src/subParsers/lists.js b/src/subParsers/lists.js index ef9e2ca..ddd223a 100644 --- a/src/subParsers/lists.js +++ b/src/subParsers/lists.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 12-01-2015. - */ - /** * Form HTML ordered (numbered) and unordered (bulleted) lists. */ @@ -11,7 +7,7 @@ showdown.subParser('lists', function (text, options, globals) { /** * Process the contents of a single ordered or unordered list, splitting it * into individual list items. - * @param listStr + * @param {string} listStr * @returns {string|*} */ var processListItems = function (listStr) { diff --git a/src/subParsers/outdent.js b/src/subParsers/outdent.js index ae9ed09..d27db2e 100644 --- a/src/subParsers/outdent.js +++ b/src/subParsers/outdent.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 12-01-2015. - */ - /** * Remove one level of line-leading tabs or spaces */ diff --git a/src/subParsers/paragraphs.js b/src/subParsers/paragraphs.js index dc2db8e..2fb1f42 100644 --- a/src/subParsers/paragraphs.js +++ b/src/subParsers/paragraphs.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 12-01-2015. - */ - /** * */ @@ -12,10 +8,10 @@ showdown.subParser('paragraphs', function (text, options, globals) { text = text.replace(/^\n+/g, ''); text = text.replace(/\n+$/g, ''); - var grafs = text.split(/\n{2,}/g), grafsOut = []; + var grafs = text.split(/\n{2,}/g), + grafsOut = [], + end = grafs.length; // Wrap

tags - /** Wrap

tags. */ - var end = grafs.length; for (var i = 0; i < end; i++) { var str = grafs[i]; diff --git a/src/subParsers/spanGamut.js b/src/subParsers/spanGamut.js index 2d9374b..0193c3d 100644 --- a/src/subParsers/spanGamut.js +++ b/src/subParsers/spanGamut.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * These are all the transformations that occur *within* block-level * tags like paragraphs, headers, and list items. diff --git a/src/subParsers/stripBlankLines.js b/src/subParsers/stripBlankLines.js index 42407dc..c507d5a 100644 --- a/src/subParsers/stripBlankLines.js +++ b/src/subParsers/stripBlankLines.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Strip any lines consisting only of spaces and tabs. * This makes subsequent regexs easier to write, because we can diff --git a/src/subParsers/stripLinkDefinitions.js b/src/subParsers/stripLinkDefinitions.js index 7e7dad4..754ddc5 100644 --- a/src/subParsers/stripLinkDefinitions.js +++ b/src/subParsers/stripLinkDefinitions.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 11-01-2015. - */ - /** * Strips link definitions from text, stores the URLs and titles in * hash references. diff --git a/src/subParsers/unescapeSpecialChars.js b/src/subParsers/unescapeSpecialChars.js index 4776d1f..1873f43 100644 --- a/src/subParsers/unescapeSpecialChars.js +++ b/src/subParsers/unescapeSpecialChars.js @@ -1,7 +1,3 @@ -/** - * Created by Estevao on 12-01-2015. - */ - /** * Swap back in all the special characters we've hidden. */ diff --git a/test/node/Container/testMakeHtml.js b/test/node/Container/testMakeHtml.js index c12e6a1..cd74bfe 100644 --- a/test/node/Container/testMakeHtml.js +++ b/test/node/Container/testMakeHtml.js @@ -8,7 +8,15 @@ require('source-map-support').install(); require('chai').should(); - var fs = require('fs'), showdown = require('../../../dist/showdown.js'), converter = new showdown.Converter(), cases = fs.readdirSync('test/cases/').filter(filter()).map(map('test/cases/')), issues = fs.readdirSync('test/issues/').filter(filter()).map(map('test/issues/')); + var fs = require('fs'), + showdown = require('../../../dist/showdown.js'), + converter = new showdown.Converter(), + cases = fs.readdirSync('test/cases/') + .filter(filter()) + .map(map('test/cases/')), + issues = fs.readdirSync('test/issues/') + .filter(filter()) + .map(map('test/issues/')); //Tests describe('Converter.makeHtml() simple testcases', function () { @@ -23,7 +31,6 @@ } }); - function filter() { return function (file) { var ext = file.slice(-3); @@ -33,9 +40,11 @@ function map(dir) { return function (file) { - var name = file.replace('.md', ''), htmlPath = dir + name + '.html', html = fs.readFileSync(htmlPath, - 'utf8'), mdPath = dir + name + '.md', md = fs.readFileSync(mdPath, - 'utf8'); + var name = file.replace('.md', ''), + htmlPath = dir + name + '.html', + html = fs.readFileSync(htmlPath, 'utf8'), + mdPath = dir + name + '.md', + md = fs.readFileSync(mdPath, 'utf8'); return { name: name,