Update dependencies to enable Greenkeeper 🌴 (#335)

adapt code to updated dependencies
This commit is contained in:
greenkeeper[bot] 2017-01-31 05:46:25 +00:00 committed by Estevão Soares dos Santos
parent 1832b7f721
commit b5e46fdb8d
34 changed files with 337 additions and 382 deletions

27
.eslintrc.json Normal file
View File

@ -0,0 +1,27 @@
{
"rules": {
"indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 2}],
"curly": [2, "all"],
"operator-linebreak": [2, "after"],
"camelcase": [2, {"properties": "never"}],
"quotes": [2, "single"],
"no-multi-str": 2,
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"space-unary-ops": [2,
{
"nonwords": false,
"overrides": {}
}
],
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"keyword-spacing": [2, {}],
"space-infix-ops": 2,
"space-before-blocks": [2, "always"],
"eol-last": 2,
"space-before-function-paren": [2, "always"],
"array-bracket-spacing": [2, "never", {"singleValue": false}],
"space-in-parens": [2, "never"],
"no-multiple-empty-lines": 2
}
}

3
.gitattributes vendored
View File

@ -3,12 +3,13 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.jscs.json export-ignore
.eslintrc.json export-ignore
.jshintignore export-ignore
.jshintrc
.travis.yml export-ignore
bower.json
Gruntfile.js export-ignore
performance.*
# Line endings control
CHANGELOG.md text

View File

@ -1,89 +0,0 @@
{
"validateIndentation": 2,
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireOperatorBeforeLineBreak": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"validateQuoteMarks": "'",
"disallowMultipleLineStrings": true,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"requireMultipleVarDecl": true,
"disallowKeywordsOnNewLine": ["else"],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBinaryOperators": [
"=",
"+=",
"-=",
"*=",
"/=",
"%=",
"<<=",
">>=",
">>>=",
"&=",
"|=",
"^=",
"+=",
"+",
"-",
"*",
"/",
"%",
"<<",
">>",
">>>",
"&",
"|",
"^",
"&&",
"||",
"===",
"==",
">=",
"<=",
"<",
">",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": true,
"requireSpacesInConditionalExpression": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpacesInForStatement": true,
"requireLineFeedAtFileEnd": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,
"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
},
"disallowMultipleLineBreaks": true,
"disallowNewlineBeforeBlockStatements": true
}

View File

@ -13,6 +13,10 @@ cache:
directories:
- node_modules
# scripts
script:
- 'if [ "$TRAVIS_NODE_VERSION" == "0.12" ]; then echo "Bypassing EsLint" && grunt test-old; else echo "Running normal tests" && grunt test; fi'
# hooks
notifications:
webhooks:

View File

@ -73,17 +73,15 @@ module.exports = function (grunt) {
]
},
jscs: {
eslint: {
options: {
config: '.jscs.json'
config: '.eslintrc.json'
},
files: {
src: [
'Gruntfile.js',
'src/**/*.js',
'test/**/*.js'
]
}
target: [
'Gruntfile.js',
'src/**/*.js',
'test/**/*.js'
]
},
conventionalChangelog: {
@ -171,7 +169,14 @@ module.exports = function (grunt) {
grunt.initConfig(config);
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-conventional-changelog');
grunt.loadNpmTasks('grunt-conventional-github-releaser');
grunt.loadNpmTasks('grunt-endline');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('single-test', function (grep) {
'use strict';
@ -195,8 +200,14 @@ module.exports = function (grunt) {
perf.generateLogs();
});
grunt.registerTask('lint', ['jshint', 'jscs']);
grunt.registerTask('lint', function () {
'use strict';
grunt.loadNpmTasks('grunt-eslint');
grunt.task.run('jshint', 'eslint');
});
grunt.registerTask('test', ['clean', 'lint', 'concat:test', 'simplemocha:node', 'clean']);
grunt.registerTask('test-old', ['concat:test', 'simplemocha:node', 'clean']);
grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']);
grunt.registerTask('build', ['test', 'concat:dist', 'uglify', 'endline']);
grunt.registerTask('prep-release', ['build', 'conventionalChangelog']);

View File

@ -1,6 +1,6 @@
![Showdown][sd-logo]
[![Build Status](https://travis-ci.org/showdownjs/showdown.svg?branch=master)](https://travis-ci.org/showdownjs/showdown) [![npm version](https://badge.fury.io/js/showdown.svg)](http://badge.fury.io/js/showdown) [![Bower version](https://badge.fury.io/bo/showdown.svg)](http://badge.fury.io/bo/showdown) [![Join the chat at https://gitter.im/showdownjs/showdown](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/showdownjs/showdown?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/showdownjs/showdown.svg?branch=master)](https://travis-ci.org/showdownjs/showdown) [![npm version](https://badge.fury.io/js/showdown.svg)](http://badge.fury.io/js/showdown) [![Bower version](https://badge.fury.io/bo/showdown.svg)](http://badge.fury.io/bo/showdown) [![Join the chat at https://gitter.im/showdownjs/showdown](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/showdownjs/showdown?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Greenkeeper badge](https://badges.greenkeeper.io/showdownjs/showdown.svg)](https://greenkeeper.io/)
------

150
dist/showdown.js vendored
View File

@ -4,7 +4,7 @@
* Created by Tivie on 13-07-2015.
*/
function getDefaultOpts(simple) {
function getDefaultOpts (simple) {
'use strict';
var defaultOptions = {
@ -131,7 +131,7 @@ function getDefaultOpts(simple) {
return ret;
}
function allOptionsOn() {
function allOptionsOn () {
'use strict';
var options = getDefaultOpts(true),
ret = {};
@ -382,14 +382,14 @@ showdown.resetExtensions = function () {
* @param {string} name
* @returns {{valid: boolean, error: string}}
*/
function validate(extension, name) {
function validate (extension, name) {
'use strict';
var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension',
ret = {
valid: true,
error: ''
};
ret = {
valid: true,
error: ''
};
if (!showdown.helper.isArray(extension)) {
extension = [extension];
@ -469,7 +469,7 @@ function validate(extension, name) {
if (showdown.helper.isString(ext.regex)) {
ext.regex = new RegExp(ext.regex, 'g');
}
if (!ext.regex instanceof RegExp) {
if (!(ext.regex instanceof RegExp)) {
ret.valid = false;
ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' + typeof ext.regex + ' given';
return ret;
@ -603,7 +603,7 @@ showdown.helper.stdExtName = function (s) {
return s.replace(/[_?*+\/\\.^-]/g, '').replace(/\s/g, '').toLowerCase();
};
function escapeCharactersCallback(wholeMatch, m1) {
function escapeCharactersCallback (wholeMatch, m1) {
'use strict';
var charCodeToEscape = m1.charCodeAt(0);
return '¨E' + charCodeToEscape + 'E';
@ -645,11 +645,11 @@ showdown.helper.escapeCharacters = function (text, charsToEscape, afterBackslash
var rgxFindMatchPos = function (str, left, right, flags) {
'use strict';
var f = flags || '',
g = f.indexOf('g') > -1,
x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
l = new RegExp(left, f.replace(/g/g, '')),
pos = [],
t, s, m, start, end;
g = f.indexOf('g') > -1,
x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
l = new RegExp(left, f.replace(/g/g, '')),
pos = [],
t, s, m, start, end;
do {
t = 0;
@ -713,7 +713,7 @@ showdown.helper.matchRecursiveRegExp = function (str, left, right, flags) {
'use strict';
var matchPos = rgxFindMatchPos (str, left, right, flags),
results = [];
results = [];
for (var i = 0; i < matchPos.length; ++i) {
results.push([
@ -897,7 +897,7 @@ showdown.Converter = function (converterOptions) {
* Converter constructor
* @private
*/
function _constructor() {
function _constructor () {
converterOptions = converterOptions || {};
for (var gOpt in globalOptions) {
@ -929,7 +929,7 @@ showdown.Converter = function (converterOptions) {
* @param {string} [name='']
* @private
*/
function _parseExtension(ext, name) {
function _parseExtension (ext, name) {
name = name || null;
// If it's a string, the extension was previously loaded
@ -993,7 +993,7 @@ showdown.Converter = function (converterOptions) {
* @param {*} ext
* @param {string} name
*/
function legacyExtensionLoading(ext, name) {
function legacyExtensionLoading (ext, name) {
if (typeof ext === 'function') {
ext = ext(new showdown.Converter());
}
@ -1025,7 +1025,7 @@ showdown.Converter = function (converterOptions) {
* @param {string} name
* @param {function} callback
*/
function listen(name, callback) {
function listen (name, callback) {
if (!showdown.helper.isString(name)) {
throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given');
}
@ -1040,7 +1040,7 @@ showdown.Converter = function (converterOptions) {
listeners[name].push(callback);
}
function rTrimInputText(text) {
function rTrimInputText (text) {
var rsp = text.match(/^\s*/)[0].length,
rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
return text.replace(rgx, '');
@ -1388,7 +1388,7 @@ showdown.subParser('autoLinks', function (text, options, globals) {
text = text.replace(simpleMailRegex, replaceMail);
}
function replaceLink(wm, link, m2, m3, trailingPunctuation) {
function replaceLink (wm, link, m2, m3, trailingPunctuation) {
var lnkTxt = link,
append = '';
if (/^www\./i.test(link)) {
@ -1400,7 +1400,7 @@ showdown.subParser('autoLinks', function (text, options, globals) {
return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
}
function replaceMail(wholeMatch, b, mail) {
function replaceMail (wholeMatch, b, mail) {
var href = 'mailto:';
b = b || '';
mail = showdown.subParser('unescapeSpecialChars')(mail, options, globals);
@ -1774,50 +1774,50 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
text = globals.converter._dispatch('hashHTMLBlocks.before', text, options, globals);
var blockTags = [
'pre',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'blockquote',
'table',
'dl',
'ol',
'ul',
'script',
'noscript',
'form',
'fieldset',
'iframe',
'math',
'style',
'section',
'header',
'footer',
'nav',
'article',
'aside',
'address',
'audio',
'canvas',
'figure',
'hgroup',
'output',
'video',
'p'
],
repFunc = function (wholeMatch, match, left, right) {
var txt = wholeMatch;
// check if this html element is marked as markdown
// if so, it's contents should be parsed as markdown
if (left.search(/\bmarkdown\b/) !== -1) {
txt = left + globals.converter.makeHtml(match) + right;
}
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
};
'pre',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'blockquote',
'table',
'dl',
'ol',
'ul',
'script',
'noscript',
'form',
'fieldset',
'iframe',
'math',
'style',
'section',
'header',
'footer',
'nav',
'article',
'aside',
'address',
'audio',
'canvas',
'figure',
'hgroup',
'output',
'video',
'p'
],
repFunc = function (wholeMatch, match, left, right) {
var txt = wholeMatch;
// check if this html element is marked as markdown
// if so, it's contents should be parsed as markdown
if (left.search(/\bmarkdown\b/) !== -1) {
txt = left + globals.converter.makeHtml(match) + right;
}
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
};
for (var i = 0; i < blockTags.length; ++i) {
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<' + blockTags[i] + '\\b[^>]*>', '</' + blockTags[i] + '>', 'gim');
@ -1923,7 +1923,7 @@ showdown.subParser('headers', function (text, options, globals) {
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
hLevel = headerLevelStart + 1,
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
return showdown.subParser('hashBlock')(hashBlock, options, globals);
});
@ -1945,7 +1945,7 @@ showdown.subParser('headers', function (text, options, globals) {
return showdown.subParser('hashBlock')(header, options, globals);
});
function headerId(m) {
function headerId (m) {
var title, escapedId;
if (ghHeaderId) {
@ -2261,7 +2261,7 @@ showdown.subParser('lists', function (text, options, globals) {
* @param {boolean} trimTrailing
* @returns {string}
*/
function parseConsecutiveLists(list, listType, trimTrailing) {
function parseConsecutiveLists (list, listType, trimTrailing) {
// check if we caught 2 or more consecutive lists by mistake
// we use the counterRgx, meaning if listType is UL we look for OL and vice versa
var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
@ -2270,7 +2270,7 @@ showdown.subParser('lists', function (text, options, globals) {
result = '';
if (list.search(counterRxg) !== -1) {
(function parseCL(txt) {
(function parseCL (txt) {
var pos = txt.search(counterRxg);
if (pos !== -1) {
// slice
@ -2419,7 +2419,7 @@ showdown.subParser('runExtension', function (ext, text, options, globals) {
} else if (ext.regex) {
// TODO remove this when old extension loading mechanism is deprecated
var re = ext.regex;
if (!re instanceof RegExp) {
if (!(re instanceof RegExp)) {
re = new RegExp(re, 'g');
}
text = text.replace(re, ext.replace);
@ -2530,7 +2530,7 @@ showdown.subParser('tables', function (text, options, globals) {
var tableRgx = /^ {0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|¨0)/gm;
function parseStyles(sLine) {
function parseStyles (sLine) {
if (/^:[ \t]*--*$/.test(sLine)) {
return ' style="text-align:left;"';
} else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) {
@ -2542,7 +2542,7 @@ showdown.subParser('tables', function (text, options, globals) {
}
}
function parseHeaders(header, style) {
function parseHeaders (header, style) {
var id = '';
header = header.trim();
if (options.tableHeaderId) {
@ -2553,12 +2553,12 @@ showdown.subParser('tables', function (text, options, globals) {
return '<th' + id + style + '>' + header + '</th>\n';
}
function parseCells(cell, style) {
function parseCells (cell, style) {
var subText = showdown.subParser('spanGamut')(cell, options, globals);
return '<td' + style + '>' + subText + '</td>\n';
}
function buildTable(headers, cells) {
function buildTable (headers, cells) {
var tb = '<table>\n<thead>\n<tr>\n',
tblLgn = headers.length;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -40,24 +40,24 @@
},
"devDependencies": {
"chai": "^3.5.0",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.6.0",
"grunt-conventional-changelog": "^4.0.0",
"grunt-conventional-github-releaser": "^0.3.0",
"grunt-endline": "^0.4.0",
"grunt-jscs": "^1.2.0",
"grunt": "^1.0.1",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^2.0.0",
"grunt-conventional-changelog": "^6.1.0",
"grunt-conventional-github-releaser": "^1.0.0",
"grunt-endline": "^0.6.1",
"grunt-eslint": "^19.0.0",
"grunt-simple-mocha": "^0.4.0",
"js-beautify": "^1.5.6",
"load-grunt-tasks": "^3.2.0",
"performance-now": "^0.2.0",
"performance-now": "^2.0.0",
"quiet-grunt": "^0.2.3",
"semver": "^5.0.0",
"semver-sort": "0.0.4",
"sinon": "^1.14.1",
"source-map-support": "^0.2.9"
"source-map-support": "^0.4.11"
},
"dependencies": {
"yargs": "^6.6.0"

File diff suppressed because one or more lines are too long

View File

@ -6,40 +6,40 @@
### Test Suite: Basic (50 cycles)
| test | avgTime | max | min |
|:-----|--------:|----:|----:|
|Simple "Hello World"|0.366|6.060|0.165|
|performance.testfile.md|26.820|47.685|24.495|
|Simple "Hello World"|0.388|6.064|0.174|
|performance.testfile.md|26.899|49.063|24.845|
### Test Suite: subParsers (20 cycles)
| test | avgTime | max | min |
|:-----|--------:|----:|----:|
|hashHTMLBlocks|2.660|9.402|1.874|
|anchors|0.502|3.829|0.256|
|autoLinks|0.097|0.244|0.073|
|blockQuotes|3.239|6.987|2.821|
|codeBlocks|0.195|0.382|0.174|
|codeSpans|0.267|0.814|0.157|
|detab|0.102|0.176|0.087|
|encodeAmpsAndAngles|0.042|0.070|0.038|
|encodeBackslashEscapes|0.076|0.125|0.068|
|encodeCode|0.919|1.457|0.823|
|escapeSpecialCharsWithinTagAttributes|0.276|0.638|0.242|
|githubCodeBlocks|0.189|0.821|0.137|
|hashBlock|0.119|1.526|0.036|
|hashElement|0.002|0.032|0.000|
|hashHTMLSpans|0.341|1.617|0.238|
|hashPreCodeTags|0.139|0.299|0.109|
|headers|0.955|2.204|0.803|
|horizontalRule|0.216|0.331|0.194|
|images|0.081|0.165|0.073|
|italicsAndBold|0.254|0.438|0.210|
|lists|5.076|5.787|4.679|
|outdent|0.157|0.255|0.142|
|paragraphs|4.067|5.360|3.584|
|spanGamut|1.524|2.136|1.321|
|strikethrough|0.005|0.093|0.000|
|stripLinkDefinitions|0.160|0.229|0.143|
|tables|0.002|0.038|0.000|
|unescapeSpecialChars|0.009|0.050|0.006|
|hashHTMLBlocks|2.616|8.181|1.899|
|anchors|0.515|4.691|0.264|
|autoLinks|0.093|0.188|0.073|
|blockQuotes|4.518|8.953|3.036|
|codeBlocks|0.223|0.348|0.188|
|codeSpans|0.318|1.095|0.177|
|detab|0.092|0.137|0.087|
|encodeAmpsAndAngles|0.044|0.089|0.038|
|encodeBackslashEscapes|0.108|0.265|0.078|
|encodeCode|1.535|9.896|0.865|
|escapeSpecialCharsWithinTagAttributes|0.294|0.523|0.253|
|githubCodeBlocks|0.208|0.790|0.142|
|hashBlock|0.042|0.123|0.036|
|hashElement|0.002|0.029|0.000|
|hashHTMLSpans|0.410|1.598|0.240|
|hashPreCodeTags|0.132|0.395|0.110|
|headers|1.015|1.502|0.806|
|horizontalRule|0.220|0.357|0.195|
|images|0.158|0.978|0.077|
|italicsAndBold|0.288|0.639|0.241|
|lists|5.151|6.331|4.629|
|outdent|0.180|0.363|0.143|
|paragraphs|4.548|6.309|4.002|
|spanGamut|1.519|1.864|1.372|
|strikethrough|0.003|0.065|0.000|
|stripLinkDefinitions|0.179|0.313|0.144|
|tables|0.004|0.063|0.000|
|unescapeSpecialChars|0.011|0.049|0.007|
## [version 1.6.2](https://github.com/showdownjs/showdown/tree/1.6.2)

View File

@ -31,7 +31,8 @@ yargs
.wrap(yargs.terminalWidth());
var argv = yargs.argv,
command = argv._[0];
command = argv._[0];
if (command === 'makehtml') {
require('./makehtml.cmd.js').run();
} else {

View File

@ -1,8 +1,8 @@
var yargs = require('yargs'),
fs = require('fs'),
Messenger = require('./messenger.js'),
showdown = require('../../dist/showdown'),
showdownOptions = showdown.getDefaultOptions(false);
fs = require('fs'),
Messenger = require('./messenger.js'),
showdown = require('../../dist/showdown'),
showdownOptions = showdown.getDefaultOptions(false);
yargs.reset()
.usage('Usage: showdown makehtml [options]')
@ -72,7 +72,7 @@ for (var opt in showdownOptions) {
}
}
function run() {
function run () {
'use strict';
var argv = yargs.argv,
readMode = (!argv.i || argv.i === '') ? 'stdin' : 'file',
@ -120,9 +120,9 @@ function run() {
write(html, append);
messenger.okExit();
function parseOptions(flavor) {
function parseOptions (flavor) {
var options = {},
flavorOpts = showdown.getFlavorOptions(flavor) || {};
flavorOpts = showdown.getFlavorOptions(flavor) || {};
// if flavor is not undefined, let's tell the user we're loading that preset
if (flavor) {
@ -156,7 +156,7 @@ function run() {
return options;
}
function readFromStdIn() {
function readFromStdIn () {
try {
var size = fs.fstatSync(process.stdin.fd).size;
return size > 0 ? fs.readSync(process.stdin.fd, size)[0] : '';
@ -166,7 +166,7 @@ function run() {
}
}
function readFromFile(encoding) {
function readFromFile (encoding) {
try {
return fs.readFileSync(argv.i, encoding);
} catch (err) {
@ -174,11 +174,11 @@ function run() {
}
}
function writeToStdOut(html) {
function writeToStdOut (html) {
return process.stdout.write(html);
}
function writeToFile(html, append) {
function writeToFile (html, append) {
// If a flag is passed, it means we should append instead of overwriting.
// Only works with files, obviously
var write = (append) ? fs.appendFileSync : fs.writeFileSync;

View File

@ -1,4 +1,4 @@
function Messenger(writeMode, supress, mute) {
function Messenger (writeMode, supress, mute) {
'use strict';
writeMode = writeMode || 'stderr';
supress = (!!supress || !!mute);

View File

@ -51,7 +51,7 @@ showdown.Converter = function (converterOptions) {
* Converter constructor
* @private
*/
function _constructor() {
function _constructor () {
converterOptions = converterOptions || {};
for (var gOpt in globalOptions) {
@ -83,7 +83,7 @@ showdown.Converter = function (converterOptions) {
* @param {string} [name='']
* @private
*/
function _parseExtension(ext, name) {
function _parseExtension (ext, name) {
name = name || null;
// If it's a string, the extension was previously loaded
@ -147,7 +147,7 @@ showdown.Converter = function (converterOptions) {
* @param {*} ext
* @param {string} name
*/
function legacyExtensionLoading(ext, name) {
function legacyExtensionLoading (ext, name) {
if (typeof ext === 'function') {
ext = ext(new showdown.Converter());
}
@ -179,7 +179,7 @@ showdown.Converter = function (converterOptions) {
* @param {string} name
* @param {function} callback
*/
function listen(name, callback) {
function listen (name, callback) {
if (!showdown.helper.isString(name)) {
throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given');
}
@ -194,7 +194,7 @@ showdown.Converter = function (converterOptions) {
listeners[name].push(callback);
}
function rTrimInputText(text) {
function rTrimInputText (text) {
var rsp = text.match(/^\s*/)[0].length,
rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
return text.replace(rgx, '');

View File

@ -101,7 +101,7 @@ showdown.helper.stdExtName = function (s) {
return s.replace(/[_?*+\/\\.^-]/g, '').replace(/\s/g, '').toLowerCase();
};
function escapeCharactersCallback(wholeMatch, m1) {
function escapeCharactersCallback (wholeMatch, m1) {
'use strict';
var charCodeToEscape = m1.charCodeAt(0);
return '¨E' + charCodeToEscape + 'E';
@ -143,11 +143,11 @@ showdown.helper.escapeCharacters = function (text, charsToEscape, afterBackslash
var rgxFindMatchPos = function (str, left, right, flags) {
'use strict';
var f = flags || '',
g = f.indexOf('g') > -1,
x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
l = new RegExp(left, f.replace(/g/g, '')),
pos = [],
t, s, m, start, end;
g = f.indexOf('g') > -1,
x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
l = new RegExp(left, f.replace(/g/g, '')),
pos = [],
t, s, m, start, end;
do {
t = 0;
@ -211,7 +211,7 @@ showdown.helper.matchRecursiveRegExp = function (str, left, right, flags) {
'use strict';
var matchPos = rgxFindMatchPos (str, left, right, flags),
results = [];
results = [];
for (var i = 0; i < matchPos.length; ++i) {
results.push([

View File

@ -2,7 +2,7 @@
* Created by Tivie on 13-07-2015.
*/
function getDefaultOpts(simple) {
function getDefaultOpts (simple) {
'use strict';
var defaultOptions = {
@ -129,7 +129,7 @@ function getDefaultOpts(simple) {
return ret;
}
function allOptionsOn() {
function allOptionsOn () {
'use strict';
var options = getDefaultOpts(true),
ret = {};

View File

@ -237,14 +237,14 @@ showdown.resetExtensions = function () {
* @param {string} name
* @returns {{valid: boolean, error: string}}
*/
function validate(extension, name) {
function validate (extension, name) {
'use strict';
var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension',
ret = {
valid: true,
error: ''
};
ret = {
valid: true,
error: ''
};
if (!showdown.helper.isArray(extension)) {
extension = [extension];
@ -324,7 +324,7 @@ function validate(extension, name) {
if (showdown.helper.isString(ext.regex)) {
ext.regex = new RegExp(ext.regex, 'g');
}
if (!ext.regex instanceof RegExp) {
if (!(ext.regex instanceof RegExp)) {
ret.valid = false;
ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' + typeof ext.regex + ' given';
return ret;

View File

@ -23,7 +23,7 @@ showdown.subParser('autoLinks', function (text, options, globals) {
text = text.replace(simpleMailRegex, replaceMail);
}
function replaceLink(wm, link, m2, m3, trailingPunctuation) {
function replaceLink (wm, link, m2, m3, trailingPunctuation) {
var lnkTxt = link,
append = '';
if (/^www\./i.test(link)) {
@ -35,7 +35,7 @@ showdown.subParser('autoLinks', function (text, options, globals) {
return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
}
function replaceMail(wholeMatch, b, mail) {
function replaceMail (wholeMatch, b, mail) {
var href = 'mailto:';
b = b || '';
mail = showdown.subParser('unescapeSpecialChars')(mail, options, globals);

View File

@ -3,50 +3,50 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
text = globals.converter._dispatch('hashHTMLBlocks.before', text, options, globals);
var blockTags = [
'pre',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'blockquote',
'table',
'dl',
'ol',
'ul',
'script',
'noscript',
'form',
'fieldset',
'iframe',
'math',
'style',
'section',
'header',
'footer',
'nav',
'article',
'aside',
'address',
'audio',
'canvas',
'figure',
'hgroup',
'output',
'video',
'p'
],
repFunc = function (wholeMatch, match, left, right) {
var txt = wholeMatch;
// check if this html element is marked as markdown
// if so, it's contents should be parsed as markdown
if (left.search(/\bmarkdown\b/) !== -1) {
txt = left + globals.converter.makeHtml(match) + right;
}
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
};
'pre',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'blockquote',
'table',
'dl',
'ol',
'ul',
'script',
'noscript',
'form',
'fieldset',
'iframe',
'math',
'style',
'section',
'header',
'footer',
'nav',
'article',
'aside',
'address',
'audio',
'canvas',
'figure',
'hgroup',
'output',
'video',
'p'
],
repFunc = function (wholeMatch, match, left, right) {
var txt = wholeMatch;
// check if this html element is marked as markdown
// if so, it's contents should be parsed as markdown
if (left.search(/\bmarkdown\b/) !== -1) {
txt = left + globals.converter.makeHtml(match) + right;
}
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
};
for (var i = 0; i < blockTags.length; ++i) {
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<' + blockTags[i] + '\\b[^>]*>', '</' + blockTags[i] + '>', 'gim');

View File

@ -30,7 +30,7 @@ showdown.subParser('headers', function (text, options, globals) {
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
hLevel = headerLevelStart + 1,
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
return showdown.subParser('hashBlock')(hashBlock, options, globals);
});
@ -52,7 +52,7 @@ showdown.subParser('headers', function (text, options, globals) {
return showdown.subParser('hashBlock')(header, options, globals);
});
function headerId(m) {
function headerId (m) {
var title, escapedId;
if (ghHeaderId) {

View File

@ -132,7 +132,7 @@ showdown.subParser('lists', function (text, options, globals) {
* @param {boolean} trimTrailing
* @returns {string}
*/
function parseConsecutiveLists(list, listType, trimTrailing) {
function parseConsecutiveLists (list, listType, trimTrailing) {
// check if we caught 2 or more consecutive lists by mistake
// we use the counterRgx, meaning if listType is UL we look for OL and vice versa
var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
@ -141,7 +141,7 @@ showdown.subParser('lists', function (text, options, globals) {
result = '';
if (list.search(counterRxg) !== -1) {
(function parseCL(txt) {
(function parseCL (txt) {
var pos = txt.search(counterRxg);
if (pos !== -1) {
// slice

View File

@ -10,7 +10,7 @@ showdown.subParser('runExtension', function (ext, text, options, globals) {
} else if (ext.regex) {
// TODO remove this when old extension loading mechanism is deprecated
var re = ext.regex;
if (!re instanceof RegExp) {
if (!(re instanceof RegExp)) {
re = new RegExp(re, 'g');
}
text = text.replace(re, ext.replace);

View File

@ -7,7 +7,7 @@ showdown.subParser('tables', function (text, options, globals) {
var tableRgx = /^ {0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|¨0)/gm;
function parseStyles(sLine) {
function parseStyles (sLine) {
if (/^:[ \t]*--*$/.test(sLine)) {
return ' style="text-align:left;"';
} else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) {
@ -19,7 +19,7 @@ showdown.subParser('tables', function (text, options, globals) {
}
}
function parseHeaders(header, style) {
function parseHeaders (header, style) {
var id = '';
header = header.trim();
if (options.tableHeaderId) {
@ -30,12 +30,12 @@ showdown.subParser('tables', function (text, options, globals) {
return '<th' + id + style + '>' + header + '</th>\n';
}
function parseCells(cell, style) {
function parseCells (cell, style) {
var subText = showdown.subParser('spanGamut')(cell, options, globals);
return '<td' + style + '>' + subText + '</td>\n';
}
function buildTable(headers, cells) {
function buildTable (headers, cells) {
var tb = '<table>\n<thead>\n<tr>\n',
tblLgn = headers.length;

18
test/bootstrap.js vendored
View File

@ -19,26 +19,26 @@
};
*/
function getTestSuite(dir) {
function getTestSuite (dir) {
return fs.readdirSync(dir)
.filter(filter())
.map(map(dir));
}
function filter() {
function filter () {
return function (file) {
var ext = file.slice(-3);
return (ext === '.md');
};
}
function map(dir) {
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');
htmlPath = dir + name + '.html',
html = fs.readFileSync(htmlPath, 'utf8'),
mdPath = dir + name + '.md',
md = fs.readFileSync(mdPath, 'utf8');
return {
name: name,
@ -48,7 +48,7 @@
};
}
function assertion(testCase, converter) {
function assertion (testCase, converter) {
return function () {
testCase.actual = converter.makeHtml(testCase.input);
testCase = normalize(testCase);
@ -59,7 +59,7 @@
}
//Normalize input/output
function normalize(testCase) {
function normalize (testCase) {
// Normalize line returns
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');

View File

@ -13,22 +13,22 @@ performance.setVersion(pkg.version);
performance.setGithubLink('https://github.com/showdownjs/showdown/tree/');
var globals = {
gHtmlBlocks: [],
gHtmlMdBlocks: [],
gHtmlSpans: [],
gUrls: {},
gTitles: {},
gDimensions: {},
gListLevel: 0,
hashLinkCounts: {},
langExtensions: [],
outputModifiers: [],
converter: converter,
ghCodeBlocks: []
},
options = showdown.getOptions();
gHtmlBlocks: [],
gHtmlMdBlocks: [],
gHtmlSpans: [],
gUrls: {},
gTitles: {},
gDimensions: {},
gListLevel: 0,
hashLinkCounts: {},
langExtensions: [],
outputModifiers: [],
converter: converter,
ghCodeBlocks: []
},
options = showdown.getOptions();
function runTests() {
function runTests () {
var testMDFile = fs.readFileSync('test/performance.testfile.md', 'utf8');
new performance.Suite('Basic')
.setOption('cycles', 50)

View File

@ -43,7 +43,7 @@ describe('showdown.Converter', function () {
check(opt, ghOpts[opt]);
}
}
function check(key, val) {
function check (key, val) {
it('should set ' + opt + ' to ' + val, function () {
converter.getOption(key).should.equal(val);
});
@ -112,22 +112,22 @@ describe('showdown.Converter', function () {
describe('events', function () {
var events = [
'anchors',
'autoLinks',
'blockGamut',
'blockQuotes',
'codeBlocks',
'codeSpans',
'githubCodeBlocks',
'headers',
'images',
'italicsAndBold',
'lists',
'paragraph',
'spanGamut'
//'strikeThrough',
//'tables'
];
'anchors',
'autoLinks',
'blockGamut',
'blockQuotes',
'codeBlocks',
'codeSpans',
'githubCodeBlocks',
'headers',
'images',
'italicsAndBold',
'lists',
'paragraph',
'spanGamut'
//'strikeThrough',
//'tables'
];
for (var i = 0; i < events.length; ++i) {
runListener(events[i] + '.before');

View File

@ -11,6 +11,7 @@ describe('showdown.Converter', function () {
var showdown = require('../bootstrap').showdown;
describe('Converter.options extensions', function () {
var runCount;
showdown.extensions.testext = function () {
return [{
type: 'output',
@ -20,8 +21,8 @@ describe('showdown.Converter', function () {
}
}];
};
var runCount,
converter = new showdown.Converter({extensions: ['testext']});
var converter = new showdown.Converter({extensions: ['testext']});
it('output extensions should run once', function () {
runCount = 0;
@ -32,8 +33,8 @@ describe('showdown.Converter', function () {
describe('makeHtml() with option omitExtraWLInCodeBlocks', function () {
var converter = new showdown.Converter({omitExtraWLInCodeBlocks: true}),
text = 'var foo = bar;',
html = converter.makeHtml(' ' + text);
text = 'var foo = bar;',
html = converter.makeHtml(' ' + text);
it('should omit extra line after code tag', function () {
var expectedHtml = '<pre><code>' + text + '</code></pre>';
html.should.equal(expectedHtml);
@ -42,19 +43,19 @@ describe('showdown.Converter', function () {
describe('makeHtml() with option prefixHeaderId', function () {
var converter = new showdown.Converter(),
text = 'foo header';
text = 'foo header';
it('should prefix header id with "section"', function () {
converter.setOption('prefixHeaderId', true);
var html = converter.makeHtml('# ' + text),
expectedHtml = '<h1 id="sectionfooheader">' + text + '</h1>';
expectedHtml = '<h1 id="sectionfooheader">' + text + '</h1>';
html.should.equal(expectedHtml);
});
it('should prefix header id with custom string', function () {
converter.setOption('prefixHeaderId', 'blabla');
var html = converter.makeHtml('# ' + text),
expectedHtml = '<h1 id="blablafooheader">' + text + '</h1>';
expectedHtml = '<h1 id="blablafooheader">' + text + '</h1>';
html.should.equal(expectedHtml);
});
});

View File

@ -6,7 +6,7 @@
/*jshint -W010 */
/*jshint -W009 */
var bootstrap = require('../bootstrap.js'),
showdown = bootstrap.showdown;
showdown = bootstrap.showdown;
describe('encodeEmailAddress()', function () {
'use strict';

View File

@ -100,9 +100,9 @@ describe('showdown.extension()', function () {
describe('showdown.getAllExtensions()', function () {
'use strict';
var extObjMock = {
type: 'lang',
filter: function () {}
};
type: 'lang',
filter: function () {}
};
it('should return all extensions', function () {
showdown.extension('bar', extObjMock);

View File

@ -2,16 +2,16 @@
* Created by Estevao on 14-07-2015.
*/
var bootstrap = require('../bootstrap.js'),
converter = new bootstrap.showdown.Converter({
strikethrough: true,
literalMidWordUnderscores: true,
simplifiedAutoLink: true,
tables: true,
parseImgDimensions: true, //extra
tasklists: true //extra
}),
assertion = bootstrap.assertion,
testsuite = bootstrap.getTestSuite('test/ghost/');
converter = new bootstrap.showdown.Converter({
strikethrough: true,
literalMidWordUnderscores: true,
simplifiedAutoLink: true,
tables: true,
parseImgDimensions: true, //extra
tasklists: true //extra
}),
assertion = bootstrap.assertion,
testsuite = bootstrap.getTestSuite('test/ghost/');
//MD-Testsuite (borrowed from karlcow/markdown-testsuite)
describe('makeHtml() ghost testsuite', function () {

View File

@ -39,8 +39,7 @@ performance.generateLog = function (filename, MDFilename, asTable) {
try {
jsonParsed = JSON.parse(json);
}
catch (err) {
} catch (err) {
jsonParsed = {};
}
@ -99,7 +98,7 @@ performance.generateLog = function (filename, MDFilename, asTable) {
generateMD(MDFilename, finalJsonObj, asTable);
};
function generateMD(filename, obj, asTable) {
function generateMD (filename, obj, asTable) {
fs.closeSync(fs.openSync(filename, 'w'));
asTable = !!asTable;
@ -137,11 +136,11 @@ function generateMD(filename, obj, asTable) {
performance.Suite = function (name) {
var suiteName = name || '',
tests = [],
hasRunFlag = false,
options = {
cycles: 20
};
tests = [],
hasRunFlag = false,
options = {
cycles: 20
};
this.setOption = function (key, val) {
options[key] = val;
@ -200,7 +199,7 @@ performance.Suite = function (name) {
console.log('running tests: ' + nn + ' cycles each.');
for (var i = 0; i < tests.length; ++i) {
var times = [],
passVar = tests[i].obj.prepare();
passVar = tests[i].obj.prepare();
for (var ii = 0; ii < nn; ++ii) {
var before = now();
tests[i].obj.test(passVar);