simplify eslint config
This commit is contained in:
parent
c458abdfd8
commit
bc835ae99e
@ -2,17 +2,23 @@
|
|||||||
"parserOptions": { "ecmaVersion": 5 },
|
"parserOptions": { "ecmaVersion": 5 },
|
||||||
"rules": {
|
"rules": {
|
||||||
"semi": ["error", "always"],
|
"semi": ["error", "always"],
|
||||||
"indent": ["warn", 2, {
|
"indent": ["error", 2, {
|
||||||
"VariableDeclarator": { "var": 2 },
|
|
||||||
"SwitchCase": 1,
|
"SwitchCase": 1,
|
||||||
"outerIIFEBody": 0
|
"VariableDeclarator": { "var": 2 },
|
||||||
|
"outerIIFEBody": 0,
|
||||||
|
"MemberExpression": 1,
|
||||||
|
"FunctionDeclaration": { "parameters": 1, "body": 1 },
|
||||||
|
"FunctionExpression": { "parameters": 1, "body": 1 },
|
||||||
|
"CallExpression": { "arguments": 1 },
|
||||||
|
"ArrayExpression": 1,
|
||||||
|
"ObjectExpression": 1,
|
||||||
|
"ImportDeclaration": 1,
|
||||||
|
"flatTernaryExpressions": false,
|
||||||
|
"ignoreComments": false
|
||||||
}],
|
}],
|
||||||
"space-before-function-paren": "off",
|
|
||||||
"object-curly-spacing": "off",
|
|
||||||
"operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }],
|
"operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }],
|
||||||
"no-cond-assign": "off",
|
"no-cond-assign": "off",
|
||||||
"no-useless-escape": "off",
|
"no-useless-escape": "off",
|
||||||
"no-return-assign": "off",
|
|
||||||
"one-var": "off",
|
"one-var": "off",
|
||||||
"no-control-regex": "off",
|
"no-control-regex": "off",
|
||||||
|
|
||||||
@ -100,6 +106,7 @@
|
|||||||
"no-proto": "error",
|
"no-proto": "error",
|
||||||
"no-redeclare": "error",
|
"no-redeclare": "error",
|
||||||
"no-regex-spaces": "error",
|
"no-regex-spaces": "error",
|
||||||
|
"no-return-assign": ["error", "except-parens"],
|
||||||
"no-return-await": "error",
|
"no-return-await": "error",
|
||||||
"no-self-assign": "error",
|
"no-self-assign": "error",
|
||||||
"no-self-compare": "error",
|
"no-self-compare": "error",
|
||||||
@ -129,6 +136,7 @@
|
|||||||
"no-useless-return": "error",
|
"no-useless-return": "error",
|
||||||
"no-whitespace-before-property": "error",
|
"no-whitespace-before-property": "error",
|
||||||
"no-with": "error",
|
"no-with": "error",
|
||||||
|
"object-curly-spacing": ["error", "always"],
|
||||||
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
|
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
|
||||||
"padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }],
|
"padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }],
|
||||||
"prefer-promise-reject-errors": "error",
|
"prefer-promise-reject-errors": "error",
|
||||||
@ -136,6 +144,7 @@
|
|||||||
"rest-spread-spacing": ["error", "never"],
|
"rest-spread-spacing": ["error", "never"],
|
||||||
"semi-spacing": ["error", { "before": false, "after": true }],
|
"semi-spacing": ["error", { "before": false, "after": true }],
|
||||||
"space-before-blocks": ["error", "always"],
|
"space-before-blocks": ["error", "always"],
|
||||||
|
"space-before-function-paren": ["error", "always"],
|
||||||
"space-in-parens": ["error", "never"],
|
"space-in-parens": ["error", "never"],
|
||||||
"space-infix-ops": "error",
|
"space-infix-ops": "error",
|
||||||
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
|
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
|
||||||
|
34
bin/marked
34
bin/marked
@ -13,7 +13,7 @@ var fs = require('fs'),
|
|||||||
* Man Page
|
* Man Page
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function help() {
|
function help () {
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
@ -24,15 +24,15 @@ function help() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
spawn('man', [path.resolve(__dirname, '/../man/marked.1')], options)
|
spawn('man', [path.resolve(__dirname, '/../man/marked.1')], options)
|
||||||
.on('error', function() {
|
.on('error', function () {
|
||||||
fs.readFile(path.resolve(__dirname, '/../man/marked.1.txt'), 'utf8', function(err, data) {
|
fs.readFile(path.resolve(__dirname, '/../man/marked.1.txt'), 'utf8', function (err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function version() {
|
function version () {
|
||||||
var pkg = require('../package.json');
|
var pkg = require('../package.json');
|
||||||
console.log(pkg.version);
|
console.log(pkg.version);
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ function version() {
|
|||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function main(argv, callback) {
|
function main (argv, callback) {
|
||||||
var files = [],
|
var files = [],
|
||||||
options = {},
|
options = {},
|
||||||
input,
|
input,
|
||||||
@ -51,7 +51,7 @@ function main(argv, callback) {
|
|||||||
tokens,
|
tokens,
|
||||||
opt;
|
opt;
|
||||||
|
|
||||||
function getarg() {
|
function getarg () {
|
||||||
var arg = argv.shift();
|
var arg = argv.shift();
|
||||||
|
|
||||||
if (arg.indexOf('--') === 0) {
|
if (arg.indexOf('--') === 0) {
|
||||||
@ -65,7 +65,7 @@ function main(argv, callback) {
|
|||||||
} else if (arg[0] === '-') {
|
} else if (arg[0] === '-') {
|
||||||
if (arg.length > 2) {
|
if (arg.length > 2) {
|
||||||
// e.g. -abc
|
// e.g. -abc
|
||||||
argv = arg.substring(1).split('').map(function(ch) {
|
argv = arg.substring(1).split('').map(function (ch) {
|
||||||
return '-' + ch;
|
return '-' + ch;
|
||||||
}).concat(argv);
|
}).concat(argv);
|
||||||
arg = argv.shift();
|
arg = argv.shift();
|
||||||
@ -128,7 +128,7 @@ function main(argv, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getData(callback) {
|
function getData (callback) {
|
||||||
if (!input) {
|
if (!input) {
|
||||||
if (files.length <= 2) {
|
if (files.length <= 2) {
|
||||||
if (string) {
|
if (string) {
|
||||||
@ -141,7 +141,7 @@ function main(argv, callback) {
|
|||||||
return fs.readFile(input, 'utf8', callback);
|
return fs.readFile(input, 'utf8', callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getData(function(err, data) {
|
return getData(function (err, data) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
|
||||||
data = tokens
|
data = tokens
|
||||||
@ -161,21 +161,21 @@ function main(argv, callback) {
|
|||||||
* Helpers
|
* Helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getStdin(callback) {
|
function getStdin (callback) {
|
||||||
var stdin = process.stdin,
|
var stdin = process.stdin,
|
||||||
buff = '';
|
buff = '';
|
||||||
|
|
||||||
stdin.setEncoding('utf8');
|
stdin.setEncoding('utf8');
|
||||||
|
|
||||||
stdin.on('data', function(data) {
|
stdin.on('data', function (data) {
|
||||||
buff += data;
|
buff += data;
|
||||||
});
|
});
|
||||||
|
|
||||||
stdin.on('error', function(err) {
|
stdin.on('error', function (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
stdin.on('end', function() {
|
stdin.on('end', function () {
|
||||||
return callback(null, buff);
|
return callback(null, buff);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -186,13 +186,13 @@ function getStdin(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function camelize(text) {
|
function camelize (text) {
|
||||||
return text.replace(/(\w)-(\w)/g, function(_, a, b) {
|
return text.replace(/(\w)-(\w)/g, function (_, a, b) {
|
||||||
return a + b.toUpperCase();
|
return a + b.toUpperCase();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleError(err) {
|
function handleError (err) {
|
||||||
if (err.code === 'ENOENT') {
|
if (err.code === 'ENOENT') {
|
||||||
console.error('marked: output to ' + err.path + ': No such directory');
|
console.error('marked: output to ' + err.path + ': No such directory');
|
||||||
return process.exit(1);
|
return process.exit(1);
|
||||||
@ -206,7 +206,7 @@ function handleError(err) {
|
|||||||
|
|
||||||
if (!module.parent) {
|
if (!module.parent) {
|
||||||
process.title = 'marked';
|
process.title = 'marked';
|
||||||
main(process.argv.slice(), function(err, code) {
|
main(process.argv.slice(), function (err, code) {
|
||||||
if (err) return handleError(err);
|
if (err) return handleError(err);
|
||||||
return process.exit(code || 0);
|
return process.exit(code || 0);
|
||||||
});
|
});
|
||||||
|
@ -79,7 +79,7 @@ Promise.all([
|
|||||||
$mainElem.style.display = 'block';
|
$mainElem.style.display = 'block';
|
||||||
});
|
});
|
||||||
|
|
||||||
function setInitialText() {
|
function setInitialText () {
|
||||||
if ('text' in search) {
|
if ('text' in search) {
|
||||||
$markdownElem.value = search.text;
|
$markdownElem.value = search.text;
|
||||||
} else {
|
} else {
|
||||||
@ -93,7 +93,7 @@ function setInitialText() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInitialQuickref() {
|
function setInitialQuickref () {
|
||||||
return fetch('./quickref.md')
|
return fetch('./quickref.md')
|
||||||
.then(function (res) { return res.text(); })
|
.then(function (res) { return res.text(); })
|
||||||
.then(function (text) {
|
.then(function (text) {
|
||||||
@ -101,7 +101,7 @@ function setInitialQuickref() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInitialVersion() {
|
function setInitialVersion () {
|
||||||
return fetch('https://data.jsdelivr.com/v1/package/npm/marked')
|
return fetch('https://data.jsdelivr.com/v1/package/npm/marked')
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
return res.json();
|
return res.json();
|
||||||
@ -162,7 +162,7 @@ function setInitialVersion() {
|
|||||||
.then(updateVersion);
|
.then(updateVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInitialOptions() {
|
function setInitialOptions () {
|
||||||
if ('options' in search) {
|
if ('options' in search) {
|
||||||
$optionsElem.value = search.options;
|
$optionsElem.value = search.options;
|
||||||
} else {
|
} else {
|
||||||
@ -170,22 +170,22 @@ function setInitialOptions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInitialOutputType() {
|
function setInitialOutputType () {
|
||||||
if (search.outputType) {
|
if (search.outputType) {
|
||||||
$outputTypeElem.value = search.outputType;
|
$outputTypeElem.value = search.outputType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleIframeLoad() {
|
function handleIframeLoad () {
|
||||||
lastInput = '';
|
lastInput = '';
|
||||||
inputDirty = true;
|
inputDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleInput() {
|
function handleInput () {
|
||||||
inputDirty = true;
|
inputDirty = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleVersionChange() {
|
function handleVersionChange () {
|
||||||
if ($markedVerElem.value === 'commit' || $markedVerElem.value === 'pr') {
|
if ($markedVerElem.value === 'commit' || $markedVerElem.value === 'pr') {
|
||||||
$commitVerElem.style.display = '';
|
$commitVerElem.style.display = '';
|
||||||
} else {
|
} else {
|
||||||
@ -194,14 +194,14 @@ function handleVersionChange() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleClearClick() {
|
function handleClearClick () {
|
||||||
$markdownElem.value = '';
|
$markdownElem.value = '';
|
||||||
$markedVerElem.value = 'master';
|
$markedVerElem.value = 'master';
|
||||||
$commitVerElem.style.display = 'none';
|
$commitVerElem.style.display = 'none';
|
||||||
updateVersion().then(setDefaultOptions);
|
updateVersion().then(setDefaultOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAddVersion(e) {
|
function handleAddVersion (e) {
|
||||||
if (e.which === 13) {
|
if (e.which === 13) {
|
||||||
switch ($markedVerElem.value) {
|
switch ($markedVerElem.value) {
|
||||||
case 'commit':
|
case 'commit':
|
||||||
@ -236,16 +236,16 @@ function handleAddVersion(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleInputChange() {
|
function handleInputChange () {
|
||||||
handleChange($inputPanes, $inputTypeElem.value);
|
handleChange($inputPanes, $inputTypeElem.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleOutputChange() {
|
function handleOutputChange () {
|
||||||
$activeOutputElem = handleChange($panes, $outputTypeElem.value);
|
$activeOutputElem = handleChange($panes, $outputTypeElem.value);
|
||||||
updateLink();
|
updateLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChange(panes, visiblePane) {
|
function handleChange (panes, visiblePane) {
|
||||||
var active = null;
|
var active = null;
|
||||||
for (var i = 0; i < panes.length; i++) {
|
for (var i = 0; i < panes.length; i++) {
|
||||||
if (panes[i].id === visiblePane) {
|
if (panes[i].id === visiblePane) {
|
||||||
@ -258,7 +258,7 @@ function handleChange(panes, visiblePane) {
|
|||||||
return active;
|
return active;
|
||||||
};
|
};
|
||||||
|
|
||||||
function addCommitVersion(value, text, commit) {
|
function addCommitVersion (value, text, commit) {
|
||||||
if (markedVersions[value]) {
|
if (markedVersions[value]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ function addCommitVersion(value, text, commit) {
|
|||||||
$markedVerElem.insertBefore(opt, $markedVerElem.firstChild);
|
$markedVerElem.insertBefore(opt, $markedVerElem.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPrCommit(pr) {
|
function getPrCommit (pr) {
|
||||||
return fetch('https://api.github.com/repos/markedjs/marked/pulls/' + pr + '/commits')
|
return fetch('https://api.github.com/repos/markedjs/marked/pulls/' + pr + '/commits')
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
return res.json();
|
return res.json();
|
||||||
@ -281,7 +281,7 @@ function getPrCommit(pr) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDefaultOptions() {
|
function setDefaultOptions () {
|
||||||
if (window.Worker) {
|
if (window.Worker) {
|
||||||
messageWorker({
|
messageWorker({
|
||||||
task: 'defaults',
|
task: 'defaults',
|
||||||
@ -293,7 +293,7 @@ function setDefaultOptions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setOptions(opts) {
|
function setOptions (opts) {
|
||||||
$optionsElem.value = JSON.stringify(
|
$optionsElem.value = JSON.stringify(
|
||||||
opts,
|
opts,
|
||||||
function (key, value) {
|
function (key, value) {
|
||||||
@ -304,7 +304,7 @@ function setOptions(opts) {
|
|||||||
}, ' ');
|
}, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchToObject() {
|
function searchToObject () {
|
||||||
// modified from https://stackoverflow.com/a/7090123/806777
|
// modified from https://stackoverflow.com/a/7090123/806777
|
||||||
var pairs = location.search.slice(1).split('&');
|
var pairs = location.search.slice(1).split('&');
|
||||||
var obj = {};
|
var obj = {};
|
||||||
@ -322,7 +322,7 @@ function searchToObject() {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsonString(input) {
|
function jsonString (input) {
|
||||||
var output = (input + '')
|
var output = (input + '')
|
||||||
.replace(/\n/g, '\\n')
|
.replace(/\n/g, '\\n')
|
||||||
.replace(/\r/g, '\\r')
|
.replace(/\r/g, '\\r')
|
||||||
@ -333,13 +333,13 @@ function jsonString(input) {
|
|||||||
return '"' + output + '"';
|
return '"' + output + '"';
|
||||||
};
|
};
|
||||||
|
|
||||||
function getScrollSize() {
|
function getScrollSize () {
|
||||||
var e = $activeOutputElem;
|
var e = $activeOutputElem;
|
||||||
|
|
||||||
return e.scrollHeight - e.clientHeight;
|
return e.scrollHeight - e.clientHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getScrollPercent() {
|
function getScrollPercent () {
|
||||||
var size = getScrollSize();
|
var size = getScrollSize();
|
||||||
|
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
@ -349,11 +349,11 @@ function getScrollPercent() {
|
|||||||
return $activeOutputElem.scrollTop / size;
|
return $activeOutputElem.scrollTop / size;
|
||||||
};
|
};
|
||||||
|
|
||||||
function setScrollPercent(percent) {
|
function setScrollPercent (percent) {
|
||||||
$activeOutputElem.scrollTop = percent * getScrollSize();
|
$activeOutputElem.scrollTop = percent * getScrollSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateLink() {
|
function updateLink () {
|
||||||
var outputType = '';
|
var outputType = '';
|
||||||
if ($outputTypeElem.value !== 'preview') {
|
if ($outputTypeElem.value !== 'preview') {
|
||||||
outputType = 'outputType=' + $outputTypeElem.value + '&';
|
outputType = 'outputType=' + $outputTypeElem.value + '&';
|
||||||
@ -365,7 +365,7 @@ function updateLink() {
|
|||||||
history.replaceState('', document.title, $permalinkElem.href);
|
history.replaceState('', document.title, $permalinkElem.href);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVersion() {
|
function updateVersion () {
|
||||||
if (window.Worker) {
|
if (window.Worker) {
|
||||||
handleInput();
|
handleInput();
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@ -390,7 +390,7 @@ function updateVersion() {
|
|||||||
}).then(handleInput);
|
}).then(handleInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForChanges() {
|
function checkForChanges () {
|
||||||
if (inputDirty && $markedVerElem.value !== 'commit' && $markedVerElem.value !== 'pr' && (typeof marked !== 'undefined' || window.Worker)) {
|
if (inputDirty && $markedVerElem.value !== 'commit' && $markedVerElem.value !== 'pr' && (typeof marked !== 'undefined' || window.Worker)) {
|
||||||
inputDirty = false;
|
inputDirty = false;
|
||||||
|
|
||||||
@ -448,7 +448,7 @@ function checkForChanges() {
|
|||||||
checkChangeTimeout = window.setTimeout(checkForChanges, delayTime);
|
checkChangeTimeout = window.setTimeout(checkForChanges, delayTime);
|
||||||
};
|
};
|
||||||
|
|
||||||
function setResponseTime(ms) {
|
function setResponseTime (ms) {
|
||||||
var amount = ms;
|
var amount = ms;
|
||||||
var suffix = 'ms';
|
var suffix = 'ms';
|
||||||
if (ms > 1000 * 60 * 60) {
|
if (ms > 1000 * 60 * 60) {
|
||||||
@ -464,7 +464,7 @@ function setResponseTime(ms) {
|
|||||||
$responseTimeElem.textContent = amount + suffix;
|
$responseTimeElem.textContent = amount + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setParsed(parsed, lexed) {
|
function setParsed (parsed, lexed) {
|
||||||
try {
|
try {
|
||||||
$previewIframe.contentDocument.body.innerHTML = parsed;
|
$previewIframe.contentDocument.body.innerHTML = parsed;
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
@ -472,7 +472,7 @@ function setParsed(parsed, lexed) {
|
|||||||
$lexerElem.value = lexed;
|
$lexerElem.value = lexed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function messageWorker(message) {
|
function messageWorker (message) {
|
||||||
if (!markedWorker || markedWorker.working) {
|
if (!markedWorker || markedWorker.working) {
|
||||||
if (markedWorker) {
|
if (markedWorker) {
|
||||||
clearTimeout(markedWorker.timeout);
|
clearTimeout(markedWorker.timeout);
|
||||||
@ -525,7 +525,7 @@ function messageWorker(message) {
|
|||||||
markedWorker.postMessage(message);
|
markedWorker.postMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function workerTimeout(seconds) {
|
function workerTimeout (seconds) {
|
||||||
markedWorker.timeout = setTimeout(function () {
|
markedWorker.timeout = setTimeout(function () {
|
||||||
seconds++;
|
seconds++;
|
||||||
markedWorker.onerror('Marked has taken longer than ' + seconds + ' second' + (seconds > 1 ? 's' : '') + ' to respond...');
|
markedWorker.onerror('Marked has taken longer than ' + seconds + ' second' + (seconds > 1 ? 's' : '') + ' to respond...');
|
||||||
|
@ -25,7 +25,7 @@ onmessage = function (e) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function parse(e) {
|
function parse (e) {
|
||||||
switch (e.data.task) {
|
switch (e.data.task) {
|
||||||
case 'defaults':
|
case 'defaults':
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ function parse(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsonString(input) {
|
function jsonString (input) {
|
||||||
var output = (input + '')
|
var output = (input + '')
|
||||||
.replace(/\n/g, '\\n')
|
.replace(/\n/g, '\\n')
|
||||||
.replace(/\r/g, '\\r')
|
.replace(/\r/g, '\\r')
|
||||||
@ -81,7 +81,7 @@ function jsonString(input) {
|
|||||||
return '"' + output + '"';
|
return '"' + output + '"';
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadVersion(ver) {
|
function loadVersion (ver) {
|
||||||
var promise;
|
var promise;
|
||||||
if (versionCache[ver]) {
|
if (versionCache[ver]) {
|
||||||
promise = Promise.resolve(versionCache[ver]);
|
promise = Promise.resolve(versionCache[ver]);
|
||||||
|
129
lib/marked.js
129
lib/marked.js
@ -4,7 +4,7 @@
|
|||||||
* https://github.com/markedjs/marked
|
* https://github.com/markedjs/marked
|
||||||
*/
|
*/
|
||||||
|
|
||||||
;(function(root) {
|
;(function (root) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,7 +133,7 @@ block.pedantic = merge({}, block.normal, {
|
|||||||
* Block Lexer
|
* Block Lexer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Lexer(options) {
|
function Lexer (options) {
|
||||||
this.tokens = [];
|
this.tokens = [];
|
||||||
this.tokens.links = Object.create(null);
|
this.tokens.links = Object.create(null);
|
||||||
this.options = options || marked.defaults;
|
this.options = options || marked.defaults;
|
||||||
@ -160,7 +160,7 @@ Lexer.rules = block;
|
|||||||
* Static Lex Method
|
* Static Lex Method
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Lexer.lex = function(src, options) {
|
Lexer.lex = function (src, options) {
|
||||||
var lexer = new Lexer(options);
|
var lexer = new Lexer(options);
|
||||||
return lexer.lex(src);
|
return lexer.lex(src);
|
||||||
};
|
};
|
||||||
@ -169,7 +169,7 @@ Lexer.lex = function(src, options) {
|
|||||||
* Preprocessing
|
* Preprocessing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Lexer.prototype.lex = function(src) {
|
Lexer.prototype.lex = function (src) {
|
||||||
src = src
|
src = src
|
||||||
.replace(/\r\n|\r/g, '\n')
|
.replace(/\r\n|\r/g, '\n')
|
||||||
.replace(/\t/g, ' ')
|
.replace(/\t/g, ' ')
|
||||||
@ -183,7 +183,7 @@ Lexer.prototype.lex = function(src) {
|
|||||||
* Lexing
|
* Lexing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Lexer.prototype.token = function(src, top) {
|
Lexer.prototype.token = function (src, top) {
|
||||||
src = src.replace(/^ +$/gm, '');
|
src = src.replace(/^ +$/gm, '');
|
||||||
var next,
|
var next,
|
||||||
loose,
|
loose,
|
||||||
@ -653,7 +653,7 @@ inline.breaks = merge({}, inline.gfm, {
|
|||||||
* Inline Lexer & Compiler
|
* Inline Lexer & Compiler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function InlineLexer(links, options) {
|
function InlineLexer (links, options) {
|
||||||
this.options = options || marked.defaults;
|
this.options = options || marked.defaults;
|
||||||
this.links = links;
|
this.links = links;
|
||||||
this.rules = inline.normal;
|
this.rules = inline.normal;
|
||||||
@ -685,7 +685,7 @@ InlineLexer.rules = inline;
|
|||||||
* Static Lexing/Compiling Method
|
* Static Lexing/Compiling Method
|
||||||
*/
|
*/
|
||||||
|
|
||||||
InlineLexer.output = function(src, links, options) {
|
InlineLexer.output = function (src, links, options) {
|
||||||
var inline = new InlineLexer(links, options);
|
var inline = new InlineLexer(links, options);
|
||||||
return inline.output(src);
|
return inline.output(src);
|
||||||
};
|
};
|
||||||
@ -694,7 +694,7 @@ InlineLexer.output = function(src, links, options) {
|
|||||||
* Lexing/Compiling
|
* Lexing/Compiling
|
||||||
*/
|
*/
|
||||||
|
|
||||||
InlineLexer.prototype.output = function(src) {
|
InlineLexer.prototype.output = function (src) {
|
||||||
var out = '',
|
var out = '',
|
||||||
link,
|
link,
|
||||||
text,
|
text,
|
||||||
@ -874,7 +874,7 @@ InlineLexer.prototype.output = function(src) {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
InlineLexer.escapes = function(text) {
|
InlineLexer.escapes = function (text) {
|
||||||
return text ? text.replace(InlineLexer.rules._escapes, '$1') : text;
|
return text ? text.replace(InlineLexer.rules._escapes, '$1') : text;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -882,7 +882,7 @@ InlineLexer.escapes = function(text) {
|
|||||||
* Compile Link
|
* Compile Link
|
||||||
*/
|
*/
|
||||||
|
|
||||||
InlineLexer.prototype.outputLink = function(cap, link) {
|
InlineLexer.prototype.outputLink = function (cap, link) {
|
||||||
var href = link.href,
|
var href = link.href,
|
||||||
title = link.title ? escape(link.title) : null;
|
title = link.title ? escape(link.title) : null;
|
||||||
|
|
||||||
@ -895,7 +895,7 @@ InlineLexer.prototype.outputLink = function(cap, link) {
|
|||||||
* Smartypants Transformations
|
* Smartypants Transformations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
InlineLexer.prototype.smartypants = function(text) {
|
InlineLexer.prototype.smartypants = function (text) {
|
||||||
if (!this.options.smartypants) return text;
|
if (!this.options.smartypants) return text;
|
||||||
return text
|
return text
|
||||||
// em-dashes
|
// em-dashes
|
||||||
@ -918,7 +918,7 @@ InlineLexer.prototype.smartypants = function(text) {
|
|||||||
* Mangle Links
|
* Mangle Links
|
||||||
*/
|
*/
|
||||||
|
|
||||||
InlineLexer.prototype.mangle = function(text) {
|
InlineLexer.prototype.mangle = function (text) {
|
||||||
if (!this.options.mangle) return text;
|
if (!this.options.mangle) return text;
|
||||||
var out = '',
|
var out = '',
|
||||||
l = text.length,
|
l = text.length,
|
||||||
@ -940,11 +940,11 @@ InlineLexer.prototype.mangle = function(text) {
|
|||||||
* Renderer
|
* Renderer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Renderer(options) {
|
function Renderer (options) {
|
||||||
this.options = options || marked.defaults;
|
this.options = options || marked.defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer.prototype.code = function(code, infostring, escaped) {
|
Renderer.prototype.code = function (code, infostring, escaped) {
|
||||||
var lang = (infostring || '').match(/\S*/)[0];
|
var lang = (infostring || '').match(/\S*/)[0];
|
||||||
if (this.options.highlight) {
|
if (this.options.highlight) {
|
||||||
var out = this.options.highlight(code, lang);
|
var out = this.options.highlight(code, lang);
|
||||||
@ -968,15 +968,15 @@ Renderer.prototype.code = function(code, infostring, escaped) {
|
|||||||
+ '</code></pre>\n';
|
+ '</code></pre>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.blockquote = function(quote) {
|
Renderer.prototype.blockquote = function (quote) {
|
||||||
return '<blockquote>\n' + quote + '</blockquote>\n';
|
return '<blockquote>\n' + quote + '</blockquote>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.html = function(html) {
|
Renderer.prototype.html = function (html) {
|
||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.heading = function(text, level, raw, slugger) {
|
Renderer.prototype.heading = function (text, level, raw, slugger) {
|
||||||
if (this.options.headerIds) {
|
if (this.options.headerIds) {
|
||||||
return '<h'
|
return '<h'
|
||||||
+ level
|
+ level
|
||||||
@ -993,21 +993,21 @@ Renderer.prototype.heading = function(text, level, raw, slugger) {
|
|||||||
return '<h' + level + '>' + text + '</h' + level + '>\n';
|
return '<h' + level + '>' + text + '</h' + level + '>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.hr = function() {
|
Renderer.prototype.hr = function () {
|
||||||
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.list = function(body, ordered, start) {
|
Renderer.prototype.list = function (body, ordered, start) {
|
||||||
var type = ordered ? 'ol' : 'ul',
|
var type = ordered ? 'ol' : 'ul',
|
||||||
startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
|
startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
|
||||||
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.listitem = function(text) {
|
Renderer.prototype.listitem = function (text) {
|
||||||
return '<li>' + text + '</li>\n';
|
return '<li>' + text + '</li>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.checkbox = function(checked) {
|
Renderer.prototype.checkbox = function (checked) {
|
||||||
return '<input '
|
return '<input '
|
||||||
+ (checked ? 'checked="" ' : '')
|
+ (checked ? 'checked="" ' : '')
|
||||||
+ 'disabled="" type="checkbox"'
|
+ 'disabled="" type="checkbox"'
|
||||||
@ -1015,11 +1015,11 @@ Renderer.prototype.checkbox = function(checked) {
|
|||||||
+ '> ';
|
+ '> ';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.paragraph = function(text) {
|
Renderer.prototype.paragraph = function (text) {
|
||||||
return '<p>' + text + '</p>\n';
|
return '<p>' + text + '</p>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.table = function(header, body) {
|
Renderer.prototype.table = function (header, body) {
|
||||||
if (body) body = '<tbody>' + body + '</tbody>';
|
if (body) body = '<tbody>' + body + '</tbody>';
|
||||||
|
|
||||||
return '<table>\n'
|
return '<table>\n'
|
||||||
@ -1030,11 +1030,11 @@ Renderer.prototype.table = function(header, body) {
|
|||||||
+ '</table>\n';
|
+ '</table>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.tablerow = function(content) {
|
Renderer.prototype.tablerow = function (content) {
|
||||||
return '<tr>\n' + content + '</tr>\n';
|
return '<tr>\n' + content + '</tr>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.tablecell = function(content, flags) {
|
Renderer.prototype.tablecell = function (content, flags) {
|
||||||
var type = flags.header ? 'th' : 'td';
|
var type = flags.header ? 'th' : 'td';
|
||||||
var tag = flags.align
|
var tag = flags.align
|
||||||
? '<' + type + ' align="' + flags.align + '">'
|
? '<' + type + ' align="' + flags.align + '">'
|
||||||
@ -1043,27 +1043,27 @@ Renderer.prototype.tablecell = function(content, flags) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// span level renderer
|
// span level renderer
|
||||||
Renderer.prototype.strong = function(text) {
|
Renderer.prototype.strong = function (text) {
|
||||||
return '<strong>' + text + '</strong>';
|
return '<strong>' + text + '</strong>';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.em = function(text) {
|
Renderer.prototype.em = function (text) {
|
||||||
return '<em>' + text + '</em>';
|
return '<em>' + text + '</em>';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.codespan = function(text) {
|
Renderer.prototype.codespan = function (text) {
|
||||||
return '<code>' + text + '</code>';
|
return '<code>' + text + '</code>';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.br = function() {
|
Renderer.prototype.br = function () {
|
||||||
return this.options.xhtml ? '<br/>' : '<br>';
|
return this.options.xhtml ? '<br/>' : '<br>';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.del = function(text) {
|
Renderer.prototype.del = function (text) {
|
||||||
return '<del>' + text + '</del>';
|
return '<del>' + text + '</del>';
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.link = function(href, title, text) {
|
Renderer.prototype.link = function (href, title, text) {
|
||||||
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
||||||
if (href === null) {
|
if (href === null) {
|
||||||
return text;
|
return text;
|
||||||
@ -1076,7 +1076,7 @@ Renderer.prototype.link = function(href, title, text) {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.image = function(href, title, text) {
|
Renderer.prototype.image = function (href, title, text) {
|
||||||
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
||||||
if (href === null) {
|
if (href === null) {
|
||||||
return text;
|
return text;
|
||||||
@ -1090,7 +1090,7 @@ Renderer.prototype.image = function(href, title, text) {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer.prototype.text = function(text) {
|
Renderer.prototype.text = function (text) {
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1099,7 +1099,7 @@ Renderer.prototype.text = function(text) {
|
|||||||
* returns only the textual part of the token
|
* returns only the textual part of the token
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function TextRenderer() {}
|
function TextRenderer () {}
|
||||||
|
|
||||||
// no need for block level renderers
|
// no need for block level renderers
|
||||||
|
|
||||||
@ -1112,11 +1112,11 @@ TextRenderer.prototype.text = function (text) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TextRenderer.prototype.link =
|
TextRenderer.prototype.link =
|
||||||
TextRenderer.prototype.image = function(href, title, text) {
|
TextRenderer.prototype.image = function (href, title, text) {
|
||||||
return '' + text;
|
return '' + text;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextRenderer.prototype.br = function() {
|
TextRenderer.prototype.br = function () {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1124,7 +1124,7 @@ TextRenderer.prototype.br = function() {
|
|||||||
* Parsing & Compiling
|
* Parsing & Compiling
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Parser(options) {
|
function Parser (options) {
|
||||||
this.tokens = [];
|
this.tokens = [];
|
||||||
this.token = null;
|
this.token = null;
|
||||||
this.options = options || marked.defaults;
|
this.options = options || marked.defaults;
|
||||||
@ -1138,7 +1138,7 @@ function Parser(options) {
|
|||||||
* Static Parse Method
|
* Static Parse Method
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Parser.parse = function(src, options) {
|
Parser.parse = function (src, options) {
|
||||||
var parser = new Parser(options);
|
var parser = new Parser(options);
|
||||||
return parser.parse(src);
|
return parser.parse(src);
|
||||||
};
|
};
|
||||||
@ -1147,12 +1147,12 @@ Parser.parse = function(src, options) {
|
|||||||
* Parse Loop
|
* Parse Loop
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Parser.prototype.parse = function(src) {
|
Parser.prototype.parse = function (src) {
|
||||||
this.inline = new InlineLexer(src.links, this.options);
|
this.inline = new InlineLexer(src.links, this.options);
|
||||||
// use an InlineLexer with a TextRenderer to extract pure text
|
// use an InlineLexer with a TextRenderer to extract pure text
|
||||||
this.inlineText = new InlineLexer(
|
this.inlineText = new InlineLexer(
|
||||||
src.links,
|
src.links,
|
||||||
merge({}, this.options, {renderer: new TextRenderer()})
|
merge({}, this.options, { renderer: new TextRenderer() })
|
||||||
);
|
);
|
||||||
this.tokens = src.reverse();
|
this.tokens = src.reverse();
|
||||||
|
|
||||||
@ -1168,15 +1168,16 @@ Parser.prototype.parse = function(src) {
|
|||||||
* Next Token
|
* Next Token
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Parser.prototype.next = function() {
|
Parser.prototype.next = function () {
|
||||||
return this.token = this.tokens.pop();
|
this.token = this.tokens.pop();
|
||||||
|
return this.token;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preview Next Token
|
* Preview Next Token
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Parser.prototype.peek = function() {
|
Parser.prototype.peek = function () {
|
||||||
return this.tokens[this.tokens.length - 1] || 0;
|
return this.tokens[this.tokens.length - 1] || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1184,7 +1185,7 @@ Parser.prototype.peek = function() {
|
|||||||
* Parse Text Tokens
|
* Parse Text Tokens
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Parser.prototype.parseText = function() {
|
Parser.prototype.parseText = function () {
|
||||||
var body = this.token.text;
|
var body = this.token.text;
|
||||||
|
|
||||||
while (this.peek().type === 'text') {
|
while (this.peek().type === 'text') {
|
||||||
@ -1198,7 +1199,7 @@ Parser.prototype.parseText = function() {
|
|||||||
* Parse Current Token
|
* Parse Current Token
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Parser.prototype.tok = function() {
|
Parser.prototype.tok = function () {
|
||||||
switch (this.token.type) {
|
switch (this.token.type) {
|
||||||
case 'space': {
|
case 'space': {
|
||||||
return '';
|
return '';
|
||||||
@ -1358,7 +1359,7 @@ Slugger.prototype.slug = function (value) {
|
|||||||
* Helpers
|
* Helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function escape(html, encode) {
|
function escape (html, encode) {
|
||||||
if (encode) {
|
if (encode) {
|
||||||
if (escape.escapeTest.test(html)) {
|
if (escape.escapeTest.test(html)) {
|
||||||
return html.replace(escape.escapeReplace, function (ch) { return escape.replacements[ch]; });
|
return html.replace(escape.escapeReplace, function (ch) { return escape.replacements[ch]; });
|
||||||
@ -1385,9 +1386,9 @@ escape.replacements = {
|
|||||||
escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
|
escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
|
||||||
escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
|
escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
|
||||||
|
|
||||||
function unescape(html) {
|
function unescape (html) {
|
||||||
// explicitly match decimal, hex, and named HTML entities
|
// explicitly match decimal, hex, and named HTML entities
|
||||||
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) {
|
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function (_, n) {
|
||||||
n = n.toLowerCase();
|
n = n.toLowerCase();
|
||||||
if (n === 'colon') return ':';
|
if (n === 'colon') return ':';
|
||||||
if (n.charAt(0) === '#') {
|
if (n.charAt(0) === '#') {
|
||||||
@ -1399,23 +1400,23 @@ function unescape(html) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function edit(regex, opt) {
|
function edit (regex, opt) {
|
||||||
regex = regex.source || regex;
|
regex = regex.source || regex;
|
||||||
opt = opt || '';
|
opt = opt || '';
|
||||||
return {
|
return {
|
||||||
replace: function(name, val) {
|
replace: function (name, val) {
|
||||||
val = val.source || val;
|
val = val.source || val;
|
||||||
val = val.replace(/(^|[^\[])\^/g, '$1');
|
val = val.replace(/(^|[^\[])\^/g, '$1');
|
||||||
regex = regex.replace(name, val);
|
regex = regex.replace(name, val);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
getRegex: function() {
|
getRegex: function () {
|
||||||
return new RegExp(regex, opt);
|
return new RegExp(regex, opt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanUrl(sanitize, base, href) {
|
function cleanUrl (sanitize, base, href) {
|
||||||
if (sanitize) {
|
if (sanitize) {
|
||||||
try {
|
try {
|
||||||
var prot = decodeURIComponent(unescape(href))
|
var prot = decodeURIComponent(unescape(href))
|
||||||
@ -1439,7 +1440,7 @@ function cleanUrl(sanitize, base, href) {
|
|||||||
return href;
|
return href;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveUrl(base, href) {
|
function resolveUrl (base, href) {
|
||||||
if (!baseUrls[' ' + base]) {
|
if (!baseUrls[' ' + base]) {
|
||||||
// we can ignore everything in base after the last slash of its path component,
|
// we can ignore everything in base after the last slash of its path component,
|
||||||
// but we might need to add _that_
|
// but we might need to add _that_
|
||||||
@ -1463,10 +1464,10 @@ function resolveUrl(base, href) {
|
|||||||
var baseUrls = {};
|
var baseUrls = {};
|
||||||
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
||||||
|
|
||||||
function noop() {}
|
function noop () {}
|
||||||
noop.exec = noop;
|
noop.exec = noop;
|
||||||
|
|
||||||
function merge(obj) {
|
function merge (obj) {
|
||||||
var i = 1,
|
var i = 1,
|
||||||
target,
|
target,
|
||||||
key;
|
key;
|
||||||
@ -1483,7 +1484,7 @@ function merge(obj) {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
function splitCells(tableRow, count) {
|
function splitCells (tableRow, count) {
|
||||||
// ensure that every cell-delimiting pipe has a space
|
// ensure that every cell-delimiting pipe has a space
|
||||||
// before it to distinguish it from an escaped pipe
|
// before it to distinguish it from an escaped pipe
|
||||||
var row = tableRow.replace(/\|/g, function (match, offset, str) {
|
var row = tableRow.replace(/\|/g, function (match, offset, str) {
|
||||||
@ -1518,7 +1519,7 @@ function splitCells(tableRow, count) {
|
|||||||
// Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
|
// Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
|
||||||
// /c*$/ is vulnerable to REDOS.
|
// /c*$/ is vulnerable to REDOS.
|
||||||
// invert: Remove suffix of non-c chars instead. Default falsey.
|
// invert: Remove suffix of non-c chars instead. Default falsey.
|
||||||
function rtrim(str, c, invert) {
|
function rtrim (str, c, invert) {
|
||||||
if (str.length === 0) {
|
if (str.length === 0) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -1541,7 +1542,7 @@ function rtrim(str, c, invert) {
|
|||||||
return str.substr(0, str.length - suffLen);
|
return str.substr(0, str.length - suffLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
function findClosingBracket(str, b) {
|
function findClosingBracket (str, b) {
|
||||||
if (str.indexOf(b[1]) === -1) {
|
if (str.indexOf(b[1]) === -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1565,7 +1566,7 @@ function findClosingBracket(str, b) {
|
|||||||
* Marked
|
* Marked
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function marked(src, opt, callback) {
|
function marked (src, opt, callback) {
|
||||||
// throw error in case of non string input
|
// throw error in case of non string input
|
||||||
if (typeof src === 'undefined' || src === null) {
|
if (typeof src === 'undefined' || src === null) {
|
||||||
throw new Error('marked(): input parameter is undefined or null');
|
throw new Error('marked(): input parameter is undefined or null');
|
||||||
@ -1596,7 +1597,7 @@ function marked(src, opt, callback) {
|
|||||||
|
|
||||||
pending = tokens.length;
|
pending = tokens.length;
|
||||||
|
|
||||||
var done = function(err) {
|
var done = function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
opt.highlight = highlight;
|
opt.highlight = highlight;
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@ -1626,11 +1627,11 @@ function marked(src, opt, callback) {
|
|||||||
if (!pending) return done();
|
if (!pending) return done();
|
||||||
|
|
||||||
for (; i < tokens.length; i++) {
|
for (; i < tokens.length; i++) {
|
||||||
(function(token) {
|
(function (token) {
|
||||||
if (token.type !== 'code') {
|
if (token.type !== 'code') {
|
||||||
return --pending || done();
|
return --pending || done();
|
||||||
}
|
}
|
||||||
return highlight(token.text, token.lang, function(err, code) {
|
return highlight(token.text, token.lang, function (err, code) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
if (code == null || code === token.text) {
|
if (code == null || code === token.text) {
|
||||||
return --pending || done();
|
return --pending || done();
|
||||||
@ -1663,7 +1664,7 @@ function marked(src, opt, callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
marked.options =
|
marked.options =
|
||||||
marked.setOptions = function(opt) {
|
marked.setOptions = function (opt) {
|
||||||
merge(marked.defaults, opt);
|
merge(marked.defaults, opt);
|
||||||
return marked;
|
return marked;
|
||||||
};
|
};
|
||||||
@ -1715,7 +1716,7 @@ marked.parse = marked;
|
|||||||
if (typeof module !== 'undefined' && typeof exports === 'object') {
|
if (typeof module !== 'undefined' && typeof exports === 'object') {
|
||||||
module.exports = marked;
|
module.exports = marked;
|
||||||
} else if (typeof define === 'function' && define.amd) {
|
} else if (typeof define === 'function' && define.amd) {
|
||||||
define(function() { return marked; });
|
define(function () { return marked; });
|
||||||
} else {
|
} else {
|
||||||
root.marked = marked;
|
root.marked = marked;
|
||||||
}
|
}
|
||||||
|
13
test/.eslintrc.json
vendored
13
test/.eslintrc.json
vendored
@ -3,21 +3,8 @@
|
|||||||
"plugins": [
|
"plugins": [
|
||||||
"standard"
|
"standard"
|
||||||
],
|
],
|
||||||
"parserOptions": { "ecmaVersion": 2018 },
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"semi": ["error", "always"],
|
"semi": ["error", "always"],
|
||||||
"indent": ["warn", 2, {
|
|
||||||
"SwitchCase": 1,
|
|
||||||
"outerIIFEBody": 0
|
|
||||||
}],
|
|
||||||
"space-before-function-paren": "off",
|
|
||||||
"object-curly-spacing": "off",
|
|
||||||
"operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }],
|
|
||||||
"no-cond-assign": "off",
|
|
||||||
"no-useless-escape": "off",
|
|
||||||
"no-return-assign": "off",
|
|
||||||
"one-var": "off",
|
|
||||||
"no-control-regex": "off",
|
|
||||||
"prefer-const": "error",
|
"prefer-const": "error",
|
||||||
"no-var": "error"
|
"no-var": "error"
|
||||||
},
|
},
|
||||||
|
20
test/bench.js
vendored
20
test/bench.js
vendored
@ -1,13 +1,13 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const htmlDiffer = require('./helpers/html-differ.js');
|
const htmlDiffer = require('./helpers/html-differ.js');
|
||||||
const {loadFiles} = require('./helpers/load.js');
|
const { loadFiles } = require('./helpers/load.js');
|
||||||
|
|
||||||
let marked = require('../');
|
let marked = require('../');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load specs
|
* Load specs
|
||||||
*/
|
*/
|
||||||
function load() {
|
function load () {
|
||||||
const dir = path.resolve(__dirname, './specs/commonmark');
|
const dir = path.resolve(__dirname, './specs/commonmark');
|
||||||
const sections = loadFiles(dir);
|
const sections = loadFiles(dir);
|
||||||
let specs = [];
|
let specs = [];
|
||||||
@ -22,7 +22,7 @@ function load() {
|
|||||||
/**
|
/**
|
||||||
* Run all benchmarks
|
* Run all benchmarks
|
||||||
*/
|
*/
|
||||||
function runBench(options) {
|
function runBench (options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
const specs = load();
|
const specs = load();
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ function runBench(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function bench(name, specs, engine) {
|
function bench (name, specs, engine) {
|
||||||
const before = process.hrtime();
|
const before = process.hrtime();
|
||||||
for (let i = 0; i < 1e3; i++) {
|
for (let i = 0; i < 1e3; i++) {
|
||||||
for (const spec of specs) {
|
for (const spec of specs) {
|
||||||
@ -127,7 +127,7 @@ function bench(name, specs, engine) {
|
|||||||
/**
|
/**
|
||||||
* A simple one-time benchmark
|
* A simple one-time benchmark
|
||||||
*/
|
*/
|
||||||
function time(options) {
|
function time (options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
const specs = load();
|
const specs = load();
|
||||||
if (options.marked) {
|
if (options.marked) {
|
||||||
@ -139,13 +139,13 @@ function time(options) {
|
|||||||
/**
|
/**
|
||||||
* Argument Parsing
|
* Argument Parsing
|
||||||
*/
|
*/
|
||||||
function parseArg(argv) {
|
function parseArg (argv) {
|
||||||
argv = argv.slice(2);
|
argv = argv.slice(2);
|
||||||
|
|
||||||
const options = {};
|
const options = {};
|
||||||
const orphans = [];
|
const orphans = [];
|
||||||
|
|
||||||
function getarg() {
|
function getarg () {
|
||||||
let arg = argv.shift();
|
let arg = argv.shift();
|
||||||
|
|
||||||
if (arg.indexOf('--') === 0) {
|
if (arg.indexOf('--') === 0) {
|
||||||
@ -222,14 +222,14 @@ function parseArg(argv) {
|
|||||||
/**
|
/**
|
||||||
* Helpers
|
* Helpers
|
||||||
*/
|
*/
|
||||||
function camelize(text) {
|
function camelize (text) {
|
||||||
return text.replace(/(\w)-(\w)/g, (_, a, b) => a + b.toUpperCase());
|
return text.replace(/(\w)-(\w)/g, (_, a, b) => a + b.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
function main(argv) {
|
function main (argv) {
|
||||||
const opt = parseArg(argv);
|
const opt = parseArg(argv);
|
||||||
|
|
||||||
if (opt.minified) {
|
if (opt.minified) {
|
||||||
@ -246,7 +246,7 @@ function main(argv) {
|
|||||||
/**
|
/**
|
||||||
* returns time to millisecond granularity
|
* returns time to millisecond granularity
|
||||||
*/
|
*/
|
||||||
function prettyElapsedTime(hrtimeElapsed) {
|
function prettyElapsedTime (hrtimeElapsed) {
|
||||||
const seconds = hrtimeElapsed[0];
|
const seconds = hrtimeElapsed[0];
|
||||||
const frac = Math.round(hrtimeElapsed[1] / 1e3) / 1e3;
|
const frac = Math.round(hrtimeElapsed[1] / 1e3) / 1e3;
|
||||||
return seconds * 1e3 + frac;
|
return seconds * 1e3 + frac;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer;
|
const HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer;
|
||||||
const htmlDiffer = new HtmlDiffer({ignoreSelfClosingSlash: true});
|
const htmlDiffer = new HtmlDiffer({ ignoreSelfClosingSlash: true });
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isEqual: htmlDiffer.isEqual.bind(htmlDiffer),
|
isEqual: htmlDiffer.isEqual.bind(htmlDiffer),
|
||||||
|
@ -4,12 +4,12 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fm = require('front-matter');
|
const fm = require('front-matter');
|
||||||
|
|
||||||
function node4Polyfills() {
|
function node4Polyfills () {
|
||||||
// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
|
// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
|
||||||
if (!String.prototype.padEnd) {
|
if (!String.prototype.padEnd) {
|
||||||
// eslint-disable-next-line no-extend-native
|
// eslint-disable-next-line no-extend-native
|
||||||
String.prototype.padEnd = function padEnd(targetLength, padString) {
|
String.prototype.padEnd = function padEnd (targetLength, padString) {
|
||||||
targetLength = targetLength >> 0; // floor if number or convert non-number to 0;
|
targetLength = targetLength >> 0; // floor if number or convert non-number to 0;
|
||||||
padString = String((typeof padString !== 'undefined' ? padString : ' '));
|
padString = String((typeof padString !== 'undefined' ? padString : ' '));
|
||||||
if (this.length > targetLength) {
|
if (this.length > targetLength) {
|
||||||
@ -28,7 +28,7 @@ function node4Polyfills() {
|
|||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
|
||||||
if (!String.prototype.padStart) {
|
if (!String.prototype.padStart) {
|
||||||
// eslint-disable-next-line no-extend-native
|
// eslint-disable-next-line no-extend-native
|
||||||
String.prototype.padStart = function padStart(targetLength, padString) {
|
String.prototype.padStart = function padStart (targetLength, padString) {
|
||||||
targetLength = targetLength >> 0; // truncate if number, or convert non-number to 0;
|
targetLength = targetLength >> 0; // truncate if number, or convert non-number to 0;
|
||||||
padString = String(typeof padString !== 'undefined' ? padString : ' ');
|
padString = String(typeof padString !== 'undefined' ? padString : ' ');
|
||||||
if (this.length >= targetLength) {
|
if (this.length >= targetLength) {
|
||||||
@ -45,7 +45,7 @@ function node4Polyfills() {
|
|||||||
}
|
}
|
||||||
node4Polyfills();
|
node4Polyfills();
|
||||||
|
|
||||||
function outputCompletionTable(title, specs) {
|
function outputCompletionTable (title, specs) {
|
||||||
let longestName = 0;
|
let longestName = 0;
|
||||||
let maxSpecs = 0;
|
let maxSpecs = 0;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ function outputCompletionTable(title, specs) {
|
|||||||
console.log();
|
console.log();
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFiles(dir) {
|
function loadFiles (dir) {
|
||||||
const files = fs.readdirSync(dir);
|
const files = fs.readdirSync(dir);
|
||||||
|
|
||||||
return files.reduce((obj, file) => {
|
return files.reduce((obj, file) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const load = require('../helpers/load.js');
|
const load = require('../helpers/load.js');
|
||||||
|
|
||||||
function runSpecs(title, dir, showCompletionTable, options) {
|
function runSpecs (title, dir, showCompletionTable, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
const specs = load.loadFiles(path.resolve(__dirname, dir));
|
const specs = load.loadFiles(path.resolve(__dirname, dir));
|
||||||
|
|
||||||
@ -33,8 +33,8 @@ function runSpecs(title, dir, showCompletionTable, options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
runSpecs('GFM', './gfm', true, {gfm: true});
|
runSpecs('GFM', './gfm', true, { gfm: true });
|
||||||
runSpecs('CommonMark', './commonmark', true, {headerIds: false});
|
runSpecs('CommonMark', './commonmark', true, { headerIds: false });
|
||||||
runSpecs('Original', './original', false, {gfm: false});
|
runSpecs('Original', './original', false, { gfm: false });
|
||||||
runSpecs('New', './new');
|
runSpecs('New', './new');
|
||||||
runSpecs('Redos', './redos');
|
runSpecs('Redos', './redos');
|
||||||
|
10
test/update-specs.js
vendored
10
test/update-specs.js
vendored
@ -5,13 +5,13 @@ const htmlDiffer = require('./helpers/html-differ.js');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
function removeFiles(dir) {
|
function removeFiles (dir) {
|
||||||
fs.readdirSync(dir).forEach(file => {
|
fs.readdirSync(dir).forEach(file => {
|
||||||
fs.unlinkSync(path.join(dir, file));
|
fs.unlinkSync(path.join(dir, file));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCommonmark(dir) {
|
function updateCommonmark (dir) {
|
||||||
return fetch('https://raw.githubusercontent.com/commonmark/commonmark.js/master/package.json')
|
return fetch('https://raw.githubusercontent.com/commonmark/commonmark.js/master/package.json')
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(pkg => pkg.version.replace(/^(\d+\.\d+).*$/, '$1'))
|
.then(pkg => pkg.version.replace(/^(\d+\.\d+).*$/, '$1'))
|
||||||
@ -20,7 +20,7 @@ function updateCommonmark(dir) {
|
|||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(specs => {
|
.then(specs => {
|
||||||
specs.forEach(spec => {
|
specs.forEach(spec => {
|
||||||
const html = marked(spec.markdown, {headerIds: false});
|
const html = marked(spec.markdown, { headerIds: false });
|
||||||
if (!htmlDiffer.isEqual(html, spec.html)) {
|
if (!htmlDiffer.isEqual(html, spec.html)) {
|
||||||
spec.shouldFail = true;
|
spec.shouldFail = true;
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ function updateCommonmark(dir) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateGfm(dir) {
|
function updateGfm (dir) {
|
||||||
return fetch('https://github.github.com/gfm/')
|
return fetch('https://github.github.com/gfm/')
|
||||||
.then(res => res.text())
|
.then(res => res.text())
|
||||||
.then(html => cheerio.load(html))
|
.then(html => cheerio.load(html))
|
||||||
@ -64,7 +64,7 @@ function updateGfm(dir) {
|
|||||||
})
|
})
|
||||||
.then(([version, specs]) => {
|
.then(([version, specs]) => {
|
||||||
specs.forEach(spec => {
|
specs.forEach(spec => {
|
||||||
const html = marked(spec.markdown, {gfm: true});
|
const html = marked(spec.markdown, { gfm: true });
|
||||||
if (!htmlDiffer.isEqual(html, spec.html)) {
|
if (!htmlDiffer.isEqual(html, spec.html)) {
|
||||||
spec.shouldFail = true;
|
spec.shouldFail = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user