Skip to content

Commit

Permalink
Merge pull request markedjs#1482 from UziTech/branch-json
Browse files Browse the repository at this point in the history
Clean up tests
  • Loading branch information
joshbruce committed May 6, 2019
2 parents 8049334 + 7f777b7 commit 29d4c0e
Show file tree
Hide file tree
Showing 187 changed files with 602 additions and 4,155 deletions.
16 changes: 8 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
"plugins": [
"standard"
],
"parserOptions": { "ecmaVersion": 5 },
"parserOptions": {
"ecmaVersion": 5,
"sourceType": "script"
},
"rules": {
"semi": ["error", "always"],
"indent": ["warn", 2, {
"VariableDeclarator": { "var": 2 },
"indent": ["error", 2, {
"SwitchCase": 1,
"VariableDeclarator": { "var": 2 },
"outerIIFEBody": 0
}],
"space-before-function-paren": "off",
"object-curly-spacing": "off",
"operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }],
"space-before-function-paren": ["error", "never"],
"no-cond-assign": "off",
"no-useless-escape": "off",
"no-return-assign": "off",
"one-var": "off",
"no-control-regex": "off"
},
"env": {
"node": true,
"browser": true,
"amd": true,
"jasmine": true
"amd": true
}
}
2 changes: 1 addition & 1 deletion bin/marked
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function camelize(text) {

function handleError(err) {
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);
}
throw err;
Expand Down
54 changes: 27 additions & 27 deletions docs/demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals marked, unfetch, ES6Promise */
/* globals marked, unfetch, ES6Promise, Promise */

if (!window.Promise) {
window.Promise = ES6Promise;
Expand All @@ -7,7 +7,7 @@ if (!window.fetch) {
window.fetch = unfetch;
}

onunhandledrejection = function (e) {
onunhandledrejection = function(e) {
throw e.reason;
};

Expand Down Expand Up @@ -70,7 +70,7 @@ Promise.all([
setInitialText(),
setInitialVersion()
.then(setInitialOptions)
]).then(function () {
]).then(function() {
handleInputChange();
handleOutputChange();
checkForChanges();
Expand All @@ -84,8 +84,8 @@ function setInitialText() {
$markdownElem.value = search.text;
} else {
return fetch('./initial.md')
.then(function (res) { return res.text(); })
.then(function (text) {
.then(function(res) { return res.text(); })
.then(function(text) {
if ($markdownElem.value === '') {
$markdownElem.value = text;
}
Expand All @@ -95,18 +95,18 @@ function setInitialText() {

function setInitialQuickref() {
return fetch('./quickref.md')
.then(function (res) { return res.text(); })
.then(function (text) {
.then(function(res) { return res.text(); })
.then(function(text) {
document.querySelector('#quickref').value = text;
});
}

function setInitialVersion() {
return fetch('https://data.jsdelivr.com/v1/package/npm/marked')
.then(function (res) {
.then(function(res) {
return res.json();
})
.then(function (json) {
.then(function(json) {
for (var i = 0; i < json.versions.length; i++) {
var ver = json.versions[i];
markedVersions[ver] = 'https://cdn.jsdelivr.net/npm/marked@' + ver + '/lib/marked.js';
Expand All @@ -116,20 +116,20 @@ function setInitialVersion() {
$markedVerElem.appendChild(opt);
}
})
.then(function () {
.then(function() {
return fetch('https://api.github.com/repos/markedjs/marked/commits')
.then(function (res) {
.then(function(res) {
return res.json();
})
.then(function (json) {
.then(function(json) {
markedVersions['master'] = 'https://cdn.jsdelivr.net/gh/markedjs/marked@' + json[0].sha + '/lib/marked.js';
})
.catch(function () {
.catch(function() {
// do nothing
// uses url without commit
});
})
.then(function () {
.then(function() {
if (search.version) {
if (markedVersions[search.version]) {
return search.version;
Expand All @@ -142,7 +142,7 @@ function setInitialVersion() {
return search.version;
case 'pr':
return getPrCommit(match[2])
.then(function (commit) {
.then(function(commit) {
if (!commit) {
return 'master';
}
Expand All @@ -156,7 +156,7 @@ function setInitialVersion() {

return 'master';
})
.then(function (version) {
.then(function(version) {
$markedVerElem.value = version;
})
.then(updateVersion);
Expand Down Expand Up @@ -220,7 +220,7 @@ function handleAddVersion(e) {
$commitVerElem.disabled = true;
var pr = $commitVerElem.value.replace(/\D/g, '');
getPrCommit(pr)
.then(function (commit) {
.then(function(commit) {
$commitVerElem.disabled = false;
if (!commit) {
alert('That is not a valid PR');
Expand Down Expand Up @@ -271,12 +271,12 @@ function addCommitVersion(value, text, commit) {

function getPrCommit(pr) {
return fetch('https://api.github.com/repos/markedjs/marked/pulls/' + pr + '/commits')
.then(function (res) {
.then(function(res) {
return res.json();
})
.then(function (json) {
.then(function(json) {
return json[json.length - 1].sha;
}).catch(function () {
}).catch(function() {
// return undefined
});
}
Expand All @@ -296,7 +296,7 @@ function setDefaultOptions() {
function setOptions(opts) {
$optionsElem.value = JSON.stringify(
opts,
function (key, value) {
function(key, value) {
if (value && typeof value === 'object' && Object.getPrototypeOf(value) !== Object.prototype) {
return undefined;
}
Expand Down Expand Up @@ -375,13 +375,13 @@ function updateVersion() {
promise = Promise.resolve(markedVersionCache[$markedVerElem.value]);
} else {
promise = fetch(markedVersions[$markedVerElem.value])
.then(function (res) { return res.text(); })
.then(function (text) {
.then(function(res) { return res.text(); })
.then(function(text) {
markedVersionCache[$markedVerElem.value] = text;
return text;
});
}
return promise.then(function (text) {
return promise.then(function(text) {
var script = document.createElement('script');
script.textContent = text;

Expand Down Expand Up @@ -479,7 +479,7 @@ function messageWorker(message) {
markedWorker.terminate();
}
markedWorker = new Worker('worker.js');
markedWorker.onmessage = function (e) {
markedWorker.onmessage = function(e) {
clearTimeout(markedWorker.timeout);
markedWorker.working = false;
switch (e.data.task) {
Expand All @@ -500,7 +500,7 @@ function messageWorker(message) {
delayTime = 10;
checkForChanges();
};
markedWorker.onerror = markedWorker.onmessageerror = function (err) {
markedWorker.onerror = markedWorker.onmessageerror = function(err) {
clearTimeout(markedWorker.timeout);
var error = 'There was an error in the Worker';
if (err) {
Expand All @@ -526,7 +526,7 @@ function messageWorker(message) {
}

function workerTimeout(seconds) {
markedWorker.timeout = setTimeout(function () {
markedWorker.timeout = setTimeout(function() {
seconds++;
markedWorker.onerror('Marked has taken longer than ' + seconds + ' second' + (seconds > 1 ? 's' : '') + ' to respond...');
workerTimeout(seconds);
Expand Down
14 changes: 7 additions & 7 deletions docs/demo/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals marked, unfetch, ES6Promise */
/* globals marked, unfetch, ES6Promise, Promise */
if (!self.Promise) {
self.importScripts('https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.js');
self.Promise = ES6Promise;
Expand All @@ -11,15 +11,15 @@ if (!self.fetch) {
var versionCache = {};
var currentVersion;

onunhandledrejection = function (e) {
onunhandledrejection = function(e) {
throw e.reason;
};

onmessage = function (e) {
onmessage = function(e) {
if (e.data.version === currentVersion) {
parse(e);
} else {
loadVersion(e.data.version).then(function () {
loadVersion(e.data.version).then(function() {
parse(e);
});
}
Expand Down Expand Up @@ -87,13 +87,13 @@ function loadVersion(ver) {
promise = Promise.resolve(versionCache[ver]);
} else {
promise = fetch(ver)
.then(function (res) { return res.text(); })
.then(function (text) {
.then(function(res) { return res.text(); })
.then(function(text) {
versionCache[ver] = text;
return text;
});
}
return promise.then(function (text) {
return promise.then(function(text) {
try {
// eslint-disable-next-line no-new-func
Function(text)();
Expand Down
23 changes: 12 additions & 11 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ Lexer.prototype.token = function(src, top) {

// code
if (cap = this.rules.code.exec(src)) {
const lastToken = this.tokens[this.tokens.length - 1];
var lastToken = this.tokens[this.tokens.length - 1];
src = src.substring(cap[0].length);
// An indented code block cannot interrupt a paragraph.
if (lastToken && lastToken.type === 'paragraph') {
lastToken.text += `\n${cap[0].trimRight()}`;
lastToken.text += '\n' + cap[0].trimRight();
} else {
cap = cap[0].replace(/^ {4}/gm, '');
this.tokens.push({
Expand Down Expand Up @@ -1107,7 +1107,7 @@ TextRenderer.prototype.strong =
TextRenderer.prototype.em =
TextRenderer.prototype.codespan =
TextRenderer.prototype.del =
TextRenderer.prototype.text = function (text) {
TextRenderer.prototype.text = function(text) {
return text;
};

Expand Down Expand Up @@ -1152,7 +1152,7 @@ Parser.prototype.parse = function(src) {
// use an InlineLexer with a TextRenderer to extract pure text
this.inlineText = new InlineLexer(
src.links,
merge({}, this.options, {renderer: new TextRenderer()})
merge({}, this.options, { renderer: new TextRenderer() })
);
this.tokens = src.reverse();

Expand All @@ -1169,7 +1169,8 @@ Parser.prototype.parse = function(src) {
*/

Parser.prototype.next = function() {
return this.token = this.tokens.pop();
this.token = this.tokens.pop();
return this.token;
};

/**
Expand Down Expand Up @@ -1327,15 +1328,15 @@ Parser.prototype.tok = function() {
* Slugger generates header id
*/

function Slugger () {
function Slugger() {
this.seen = {};
}

/**
* Convert string to unique id
*/

Slugger.prototype.slug = function (value) {
Slugger.prototype.slug = function(value) {
var slug = value
.toLowerCase()
.trim()
Expand All @@ -1361,11 +1362,11 @@ Slugger.prototype.slug = function (value) {
function escape(html, encode) {
if (encode) {
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]; });
}
} else {
if (escape.escapeTestNoEncode.test(html)) {
return html.replace(escape.escapeReplaceNoEncode, function (ch) { return escape.replacements[ch]; });
return html.replace(escape.escapeReplaceNoEncode, function(ch) { return escape.replacements[ch]; });
}
}

Expand Down Expand Up @@ -1486,7 +1487,7 @@ function merge(obj) {
function splitCells(tableRow, count) {
// ensure that every cell-delimiting pipe has a space
// 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) {
var escaped = false,
curr = offset;
while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
Expand Down Expand Up @@ -1668,7 +1669,7 @@ marked.setOptions = function(opt) {
return marked;
};

marked.getDefaults = function () {
marked.getDefaults = function() {
return {
baseUrl: null,
breaks: false,
Expand Down
12 changes: 3 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 29d4c0e

Please sign in to comment.