Эх сурвалжийг харах

chore(): code fix to pass jscs linter

Estevão Soares dos Santos 10 жил өмнө
parent
commit
0da9626408

+ 2 - 7
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:
      * <div sd-md-to-html-model="markdownText" ></div>
      *
-     * @param $showdown
+     * @param {showdown.Converter} $showdown
      * @returns {*}
      */
     function markdownToHtmlDirective($showdown) {

+ 46 - 58
src/helpers.js

@@ -1,13 +1,27 @@
 /**
- * Created by Estevao on 11-01-2015.
+ * showdownjs helper functions
  */
 
-function isString(a) {
+if (!showdown.hasOwnProperty('helper')) {
+  showdown.helper = {};
+}
+
+/**
+ * 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);
-}
+};
 
-function forEach(obj, callback) {
+/**
+ * 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,64 +31,17 @@ function forEach(obj, callback) {
       callback(obj[i], i, obj);
     }
   }
-}
-
-function isArray(a) {
-  'use strict';
-  return a.constructor === Array;
-}
-
-function isUndefined(value) {
-  'use strict';
-  return typeof value === 'undefined';
-}
-
-var escapeCharactersCallback = function (wholeMatch, m1) {
-  'use strict';
-  var charCodeToEscape = m1.charCodeAt(0);
-  return '~E' + charCodeToEscape + 'E';
-};
-
-var escapeCharacters = function (text, charsToEscape, afterBackslash) {
-  'use strict';
-  // First we have to escape the escape characters so that
-  // we can build a character class out of them
-  var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
-
-  if (afterBackslash) {
-    regexString = '\\\\' + regexString;
-  }
-
-  var regex = new RegExp(regexString, 'g');
-  text = text.replace(regex, escapeCharactersCallback);
-
-  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;
+showdown.helper.isArray = function isArray(a) {
+  'use strict';
+  return a.constructor === Array;
+};
 
 /**
  * Check if value is undefined
@@ -83,7 +50,10 @@ showdown.helper.isArray = isArray;
  * @param {*} value The value to check.
  * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  */
-showdown.helper.isUndefined = isUndefined;
+showdown.helper.isUndefined = function isUndefined(value) {
+  'use strict';
+  return typeof value === 'undefined';
+};
 
 /**
  * Callback used to escape characters when passing through String.replace
@@ -91,7 +61,11 @@ showdown.helper.isUndefined = isUndefined;
  * @param {string} m1
  * @returns {string}
  */
-showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
+showdown.helper.escapeCharactersCallback = function escapeCharactersCallback(wholeMatch, m1) {
+  'use strict';
+  var charCodeToEscape = m1.charCodeAt(0);
+  return '~E' + charCodeToEscape + 'E';
+};
 
 /**
  * Escape characters in a string
@@ -101,4 +75,18 @@ showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
  * @param {boolean} afterBackslash
  * @returns {XML|string|void|*}
  */
-showdown.helper.escapeCharacters = escapeCharacters;
+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
+  var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
+
+  if (afterBackslash) {
+    regexString = '\\\\' + regexString;
+  }
+
+  var regex = new RegExp(regexString, 'g');
+  text = text.replace(regex, escapeCharactersCallback);
+
+  return text;
+};

+ 4 - 8
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;
 }

+ 5 - 9
src/subParsers/anchors.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 11-01-2015.
- */
-
 /**
  * Turn Markdown link shortcuts into XHTML <a> 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 = '<a href="' + url + '"';
 
     if (title !== '' && title !== null) {
       title = title.replace(/"/g, '&quot;');
-      title = showdown.helper.escapeCharacters(title, '*_');
+      title = showdown.helper.escapeCharacters(title, '*_', false);
       result += ' title="' + title + '"';
     }
 
@@ -121,11 +117,11 @@ showdown.subParser('anchors', function (text, config, globals) {
 
   /*
    text = text.replace(/
-   (		 					// wrap whole match in $1
+   (                // wrap whole match in $1
    \[
-   ([^\[\]]+)				// link text = $2; can't contain '[' or ']'
+   ([^\[\]]+)       // link text = $2; can't contain '[' or ']'
    \]
-   )()()()()()					// pad rest of backreferences
+   )()()()()()      // pad rest of backreferences
    /g, writeAnchorTag);
    */
   text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);

+ 0 - 4
src/subParsers/autoLinks.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 12-01-2015.
- */
-
 showdown.subParser('autoLinks', function (text) {
   'use strict';
 

+ 1 - 5
src/subParsers/blockGamut.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 11-01-2015.
- */
-
 /**
  * These are all the transformations that form block-level
  * tags like paragraphs, headers, and list items.
@@ -29,5 +25,5 @@ showdown.subParser('blockGamut', function (text, options, globals) {
   text = showdown.subParser('paragraphs')(text, options, globals);
 
   return text;
-});
 
+});

+ 0 - 4
src/subParsers/blockQuotes.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 12-01-2015.
- */
-
 showdown.subParser('blockQuotes', function (text, options, globals) {
   'use strict';
 

+ 0 - 4
src/subParsers/codeBlocks.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 12-01-2015.
- */
-
 /**
  * Process Markdown `<pre><code>` blocks.
  */

+ 0 - 4
src/subParsers/codeSpans.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 11-01-2015.
- */
-
 /**
  *
  *   *  Backtick quotes are used for <code></code> spans.

+ 0 - 4
src/subParsers/detab.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 11-01-2015.
- */
-
 /**
  * Convert all tabs to spaces
  */

+ 0 - 4
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.
  */

+ 0 - 4
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.
  *

+ 0 - 4
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,

+ 0 - 4
src/subParsers/encodeEmailAddress.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 12-01-2015.
- */
-
 /**
  *  Input: an email address, e.g. "foo@example.com"
  *

+ 1 - 5
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;
   });
 

+ 0 - 4
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

+ 0 - 4
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, '');

+ 0 - 4
src/subParsers/hashElement.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 11-01-2015.
- */
-
 showdown.subParser('hashElement', function (text, options, globals) {
   'use strict';
 

+ 0 - 4
src/subParsers/hashHTMLBlocks.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 11-01-2015.
- */
-
 showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
   'use strict';
 

+ 0 - 4
src/subParsers/headers.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 11-01-2015.
- */
-
 showdown.subParser('headers', function (text, options, globals) {
   'use strict';
 

+ 1 - 5
src/subParsers/images.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 11-01-2015.
- */
-
 /**
  * Turn Markdown image shortcuts into <img> tags.
  */
@@ -40,7 +36,7 @@ showdown.subParser('images', function (text, options, globals) {
     }
 
     altText = altText.replace(/"/g, '&quot;');
-    url = showdown.helper.escapeCharacters(url, '*_');
+    url = showdown.helper.escapeCharacters(url, '*_', false);
     var result = '<img src="' + url + '" alt="' + altText + '"';
 
     // attacklab: Markdown.pl adds empty title attributes to images.

+ 0 - 4
src/subParsers/italicsAndBold.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 12-01-2015.
- */
-
 showdown.subParser('italicsAndBold', function (text) {
   'use strict';
   // <strong> must go first:

+ 1 - 5
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) {

+ 0 - 4
src/subParsers/outdent.js

@@ -1,7 +1,3 @@
-/**
- * Created by Estevao on 12-01-2015.
- */
-
 /**
  * Remove one level of line-leading tabs or spaces
  */

+ 3 - 7
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 <p> tags
 
-  /** Wrap <p> tags. */
-  var end = grafs.length;
   for (var i = 0; i < end; i++) {
     var str = grafs[i];
 

+ 0 - 4
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.

+ 0 - 4
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

+ 0 - 4
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.

+ 0 - 4
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.
  */

+ 14 - 5
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,