diff --git a/.eslintrc.json b/.eslintrc.json index 220dfc0ac7..142e68f6a9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,6 +23,7 @@ "ignoreComments": false }], "operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }], + "space-before-function-paren": ["error", "never"], "no-cond-assign": "off", "no-useless-escape": "off", "one-var": "off", @@ -150,7 +151,6 @@ "rest-spread-spacing": ["error", "never"], "semi-spacing": ["error", { "before": false, "after": true }], "space-before-blocks": ["error", "always"], - "space-before-function-paren": ["error", "always"], "space-in-parens": ["error", "never"], "space-infix-ops": "error", "space-unary-ops": ["error", { "words": true, "nonwords": false }], diff --git a/bin/marked b/bin/marked index c7676d7d2d..307db173b0 100755 --- a/bin/marked +++ b/bin/marked @@ -13,7 +13,7 @@ var fs = require('fs'), * Man Page */ -function help () { +function help() { var spawn = require('child_process').spawn; var options = { @@ -24,15 +24,15 @@ function help () { }; spawn('man', [path.resolve(__dirname, '/../man/marked.1')], options) - .on('error', function () { - fs.readFile(path.resolve(__dirname, '/../man/marked.1.txt'), 'utf8', function (err, data) { + .on('error', function() { + fs.readFile(path.resolve(__dirname, '/../man/marked.1.txt'), 'utf8', function(err, data) { if (err) throw err; console.log(data); }); }); } -function version () { +function version() { var pkg = require('../package.json'); console.log(pkg.version); } @@ -41,7 +41,7 @@ function version () { * Main */ -function main (argv, callback) { +function main(argv, callback) { var files = [], options = {}, input, @@ -51,7 +51,7 @@ function main (argv, callback) { tokens, opt; - function getarg () { + function getarg() { var arg = argv.shift(); if (arg.indexOf('--') === 0) { @@ -65,7 +65,7 @@ function main (argv, callback) { } else if (arg[0] === '-') { if (arg.length > 2) { // e.g. -abc - argv = arg.substring(1).split('').map(function (ch) { + argv = arg.substring(1).split('').map(function(ch) { return '-' + ch; }).concat(argv); arg = argv.shift(); @@ -128,7 +128,7 @@ function main (argv, callback) { } } - function getData (callback) { + function getData(callback) { if (!input) { if (files.length <= 2) { if (string) { @@ -141,7 +141,7 @@ function main (argv, callback) { return fs.readFile(input, 'utf8', callback); } - return getData(function (err, data) { + return getData(function(err, data) { if (err) return callback(err); data = tokens @@ -161,21 +161,21 @@ function main (argv, callback) { * Helpers */ -function getStdin (callback) { +function getStdin(callback) { var stdin = process.stdin, buff = ''; stdin.setEncoding('utf8'); - stdin.on('data', function (data) { + stdin.on('data', function(data) { buff += data; }); - stdin.on('error', function (err) { + stdin.on('error', function(err) { return callback(err); }); - stdin.on('end', function () { + stdin.on('end', function() { return callback(null, buff); }); @@ -186,13 +186,13 @@ function getStdin (callback) { } } -function camelize (text) { - return text.replace(/(\w)-(\w)/g, function (_, a, b) { +function camelize(text) { + return text.replace(/(\w)-(\w)/g, function(_, a, b) { return a + b.toUpperCase(); }); } -function handleError (err) { +function handleError(err) { if (err.code === 'ENOENT') { console.error('marked: output to ' + err.path + ': No such directory'); return process.exit(1); @@ -206,7 +206,7 @@ function handleError (err) { if (!module.parent) { process.title = 'marked'; - main(process.argv.slice(), function (err, code) { + main(process.argv.slice(), function(err, code) { if (err) return handleError(err); return process.exit(code || 0); }); diff --git a/docs/demo/demo.js b/docs/demo/demo.js index eb452d0a41..c54a3a244a 100644 --- a/docs/demo/demo.js +++ b/docs/demo/demo.js @@ -7,7 +7,7 @@ if (!window.fetch) { window.fetch = unfetch; } -onunhandledrejection = function (e) { +onunhandledrejection = function(e) { throw e.reason; }; @@ -70,7 +70,7 @@ Promise.all([ setInitialText(), setInitialVersion() .then(setInitialOptions) -]).then(function () { +]).then(function() { handleInputChange(); handleOutputChange(); checkForChanges(); @@ -79,13 +79,13 @@ Promise.all([ $mainElem.style.display = 'block'; }); -function setInitialText () { +function setInitialText() { if ('text' in search) { $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; } @@ -93,20 +93,20 @@ function setInitialText () { } } -function setInitialQuickref () { +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 () { +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'; @@ -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; @@ -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'; } @@ -156,13 +156,13 @@ function setInitialVersion () { return 'master'; }) - .then(function (version) { + .then(function(version) { $markedVerElem.value = version; }) .then(updateVersion); } -function setInitialOptions () { +function setInitialOptions() { if ('options' in search) { $optionsElem.value = search.options; } else { @@ -170,22 +170,22 @@ function setInitialOptions () { } } -function setInitialOutputType () { +function setInitialOutputType() { if (search.outputType) { $outputTypeElem.value = search.outputType; } } -function handleIframeLoad () { +function handleIframeLoad() { lastInput = ''; inputDirty = true; } -function handleInput () { +function handleInput() { inputDirty = true; }; -function handleVersionChange () { +function handleVersionChange() { if ($markedVerElem.value === 'commit' || $markedVerElem.value === 'pr') { $commitVerElem.style.display = ''; } else { @@ -194,14 +194,14 @@ function handleVersionChange () { } } -function handleClearClick () { +function handleClearClick() { $markdownElem.value = ''; $markedVerElem.value = 'master'; $commitVerElem.style.display = 'none'; updateVersion().then(setDefaultOptions); } -function handleAddVersion (e) { +function handleAddVersion(e) { if (e.which === 13) { switch ($markedVerElem.value) { case 'commit': @@ -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'); @@ -236,16 +236,16 @@ function handleAddVersion (e) { } } -function handleInputChange () { +function handleInputChange() { handleChange($inputPanes, $inputTypeElem.value); } -function handleOutputChange () { +function handleOutputChange() { $activeOutputElem = handleChange($panes, $outputTypeElem.value); updateLink(); } -function handleChange (panes, visiblePane) { +function handleChange(panes, visiblePane) { var active = null; for (var i = 0; i < panes.length; i++) { if (panes[i].id === visiblePane) { @@ -258,7 +258,7 @@ function handleChange (panes, visiblePane) { return active; }; -function addCommitVersion (value, text, commit) { +function addCommitVersion(value, text, commit) { if (markedVersions[value]) { return; } @@ -269,19 +269,19 @@ function addCommitVersion (value, text, commit) { $markedVerElem.insertBefore(opt, $markedVerElem.firstChild); } -function getPrCommit (pr) { +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 }); } -function setDefaultOptions () { +function setDefaultOptions() { if (window.Worker) { messageWorker({ task: 'defaults', @@ -293,10 +293,10 @@ function setDefaultOptions () { } } -function setOptions (opts) { +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; } @@ -304,7 +304,7 @@ function setOptions (opts) { }, ' '); } -function searchToObject () { +function searchToObject() { // modified from https://stackoverflow.com/a/7090123/806777 var pairs = location.search.slice(1).split('&'); var obj = {}; @@ -322,7 +322,7 @@ function searchToObject () { return obj; } -function jsonString (input) { +function jsonString(input) { var output = (input + '') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') @@ -333,13 +333,13 @@ function jsonString (input) { return '"' + output + '"'; }; -function getScrollSize () { +function getScrollSize() { var e = $activeOutputElem; return e.scrollHeight - e.clientHeight; }; -function getScrollPercent () { +function getScrollPercent() { var size = getScrollSize(); if (size <= 0) { @@ -349,11 +349,11 @@ function getScrollPercent () { return $activeOutputElem.scrollTop / size; }; -function setScrollPercent (percent) { +function setScrollPercent(percent) { $activeOutputElem.scrollTop = percent * getScrollSize(); }; -function updateLink () { +function updateLink() { var outputType = ''; if ($outputTypeElem.value !== 'preview') { outputType = 'outputType=' + $outputTypeElem.value + '&'; @@ -365,7 +365,7 @@ function updateLink () { history.replaceState('', document.title, $permalinkElem.href); } -function updateVersion () { +function updateVersion() { if (window.Worker) { handleInput(); return Promise.resolve(); @@ -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; @@ -390,7 +390,7 @@ function updateVersion () { }).then(handleInput); } -function checkForChanges () { +function checkForChanges() { if (inputDirty && $markedVerElem.value !== 'commit' && $markedVerElem.value !== 'pr' && (typeof marked !== 'undefined' || window.Worker)) { inputDirty = false; @@ -448,7 +448,7 @@ function checkForChanges () { checkChangeTimeout = window.setTimeout(checkForChanges, delayTime); }; -function setResponseTime (ms) { +function setResponseTime(ms) { var amount = ms; var suffix = 'ms'; if (ms > 1000 * 60 * 60) { @@ -464,7 +464,7 @@ function setResponseTime (ms) { $responseTimeElem.textContent = amount + suffix; } -function setParsed (parsed, lexed) { +function setParsed(parsed, lexed) { try { $previewIframe.contentDocument.body.innerHTML = parsed; } catch (ex) {} @@ -472,14 +472,14 @@ function setParsed (parsed, lexed) { $lexerElem.value = lexed; } -function messageWorker (message) { +function messageWorker(message) { if (!markedWorker || markedWorker.working) { if (markedWorker) { clearTimeout(markedWorker.timeout); 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) { @@ -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) { @@ -525,8 +525,8 @@ function messageWorker (message) { markedWorker.postMessage(message); } -function workerTimeout (seconds) { - markedWorker.timeout = setTimeout(function () { +function workerTimeout(seconds) { + markedWorker.timeout = setTimeout(function() { seconds++; markedWorker.onerror('Marked has taken longer than ' + seconds + ' second' + (seconds > 1 ? 's' : '') + ' to respond...'); workerTimeout(seconds); diff --git a/docs/demo/worker.js b/docs/demo/worker.js index 34020ae875..01b6b7530c 100644 --- a/docs/demo/worker.js +++ b/docs/demo/worker.js @@ -11,21 +11,21 @@ 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); }); } }; -function parse (e) { +function parse(e) { switch (e.data.task) { case 'defaults': @@ -70,7 +70,7 @@ function parse (e) { } } -function jsonString (input) { +function jsonString(input) { var output = (input + '') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') @@ -81,19 +81,19 @@ function jsonString (input) { return '"' + output + '"'; }; -function loadVersion (ver) { +function loadVersion(ver) { var promise; if (versionCache[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)(); diff --git a/lib/marked.js b/lib/marked.js index a643f060d4..d9e3bafeb1 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -4,7 +4,7 @@ * https://github.com/markedjs/marked */ -;(function (root) { +;(function(root) { 'use strict'; /** @@ -133,7 +133,7 @@ block.pedantic = merge({}, block.normal, { * Block Lexer */ -function Lexer (options) { +function Lexer(options) { this.tokens = []; this.tokens.links = Object.create(null); this.options = options || marked.defaults; @@ -160,7 +160,7 @@ Lexer.rules = block; * Static Lex Method */ -Lexer.lex = function (src, options) { +Lexer.lex = function(src, options) { var lexer = new Lexer(options); return lexer.lex(src); }; @@ -169,7 +169,7 @@ Lexer.lex = function (src, options) { * Preprocessing */ -Lexer.prototype.lex = function (src) { +Lexer.prototype.lex = function(src) { src = src .replace(/\r\n|\r/g, '\n') .replace(/\t/g, ' ') @@ -183,7 +183,7 @@ Lexer.prototype.lex = function (src) { * Lexing */ -Lexer.prototype.token = function (src, top) { +Lexer.prototype.token = function(src, top) { src = src.replace(/^ +$/gm, ''); var next, loose, @@ -653,7 +653,7 @@ inline.breaks = merge({}, inline.gfm, { * Inline Lexer & Compiler */ -function InlineLexer (links, options) { +function InlineLexer(links, options) { this.options = options || marked.defaults; this.links = links; this.rules = inline.normal; @@ -685,7 +685,7 @@ InlineLexer.rules = inline; * Static Lexing/Compiling Method */ -InlineLexer.output = function (src, links, options) { +InlineLexer.output = function(src, links, options) { var inline = new InlineLexer(links, options); return inline.output(src); }; @@ -694,7 +694,7 @@ InlineLexer.output = function (src, links, options) { * Lexing/Compiling */ -InlineLexer.prototype.output = function (src) { +InlineLexer.prototype.output = function(src) { var out = '', link, text, @@ -874,7 +874,7 @@ InlineLexer.prototype.output = function (src) { return out; }; -InlineLexer.escapes = function (text) { +InlineLexer.escapes = function(text) { return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; }; @@ -882,7 +882,7 @@ InlineLexer.escapes = function (text) { * Compile Link */ -InlineLexer.prototype.outputLink = function (cap, link) { +InlineLexer.prototype.outputLink = function(cap, link) { var href = link.href, title = link.title ? escape(link.title) : null; @@ -895,7 +895,7 @@ InlineLexer.prototype.outputLink = function (cap, link) { * Smartypants Transformations */ -InlineLexer.prototype.smartypants = function (text) { +InlineLexer.prototype.smartypants = function(text) { if (!this.options.smartypants) return text; return text // em-dashes @@ -918,7 +918,7 @@ InlineLexer.prototype.smartypants = function (text) { * Mangle Links */ -InlineLexer.prototype.mangle = function (text) { +InlineLexer.prototype.mangle = function(text) { if (!this.options.mangle) return text; var out = '', l = text.length, @@ -940,11 +940,11 @@ InlineLexer.prototype.mangle = function (text) { * Renderer */ -function Renderer (options) { +function Renderer(options) { 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]; if (this.options.highlight) { var out = this.options.highlight(code, lang); @@ -968,15 +968,15 @@ Renderer.prototype.code = function (code, infostring, escaped) { + '\n'; }; -Renderer.prototype.blockquote = function (quote) { +Renderer.prototype.blockquote = function(quote) { return '
\n' + quote + '
\n'; }; -Renderer.prototype.html = function (html) { +Renderer.prototype.html = function(html) { return html; }; -Renderer.prototype.heading = function (text, level, raw, slugger) { +Renderer.prototype.heading = function(text, level, raw, slugger) { if (this.options.headerIds) { return '' + text + '\n'; }; -Renderer.prototype.hr = function () { +Renderer.prototype.hr = function() { return this.options.xhtml ? '
\n' : '
\n'; }; -Renderer.prototype.list = function (body, ordered, start) { +Renderer.prototype.list = function(body, ordered, start) { var type = ordered ? 'ol' : 'ul', startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; return '<' + type + startatt + '>\n' + body + '\n'; }; -Renderer.prototype.listitem = function (text) { +Renderer.prototype.listitem = function(text) { return '
  • ' + text + '
  • \n'; }; -Renderer.prototype.checkbox = function (checked) { +Renderer.prototype.checkbox = function(checked) { return ' '; }; -Renderer.prototype.paragraph = function (text) { +Renderer.prototype.paragraph = function(text) { return '

    ' + text + '

    \n'; }; -Renderer.prototype.table = function (header, body) { +Renderer.prototype.table = function(header, body) { if (body) body = '' + body + ''; return '\n' @@ -1030,11 +1030,11 @@ Renderer.prototype.table = function (header, body) { + '
    \n'; }; -Renderer.prototype.tablerow = function (content) { +Renderer.prototype.tablerow = function(content) { return '\n' + content + '\n'; }; -Renderer.prototype.tablecell = function (content, flags) { +Renderer.prototype.tablecell = function(content, flags) { var type = flags.header ? 'th' : 'td'; var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' @@ -1043,27 +1043,27 @@ Renderer.prototype.tablecell = function (content, flags) { }; // span level renderer -Renderer.prototype.strong = function (text) { +Renderer.prototype.strong = function(text) { return '' + text + ''; }; -Renderer.prototype.em = function (text) { +Renderer.prototype.em = function(text) { return '' + text + ''; }; -Renderer.prototype.codespan = function (text) { +Renderer.prototype.codespan = function(text) { return '' + text + ''; }; -Renderer.prototype.br = function () { +Renderer.prototype.br = function() { return this.options.xhtml ? '
    ' : '
    '; }; -Renderer.prototype.del = function (text) { +Renderer.prototype.del = function(text) { return '' + text + ''; }; -Renderer.prototype.link = function (href, title, text) { +Renderer.prototype.link = function(href, title, text) { href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); if (href === null) { return text; @@ -1076,7 +1076,7 @@ Renderer.prototype.link = function (href, title, text) { 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); if (href === null) { return text; @@ -1090,7 +1090,7 @@ Renderer.prototype.image = function (href, title, text) { return out; }; -Renderer.prototype.text = function (text) { +Renderer.prototype.text = function(text) { return text; }; @@ -1099,7 +1099,7 @@ Renderer.prototype.text = function (text) { * returns only the textual part of the token */ -function TextRenderer () {} +function TextRenderer() {} // no need for block level renderers @@ -1107,16 +1107,16 @@ TextRenderer.prototype.strong = TextRenderer.prototype.em = TextRenderer.prototype.codespan = TextRenderer.prototype.del = -TextRenderer.prototype.text = function (text) { +TextRenderer.prototype.text = function(text) { return text; }; TextRenderer.prototype.link = -TextRenderer.prototype.image = function (href, title, text) { +TextRenderer.prototype.image = function(href, title, text) { return '' + text; }; -TextRenderer.prototype.br = function () { +TextRenderer.prototype.br = function() { return ''; }; @@ -1124,7 +1124,7 @@ TextRenderer.prototype.br = function () { * Parsing & Compiling */ -function Parser (options) { +function Parser(options) { this.tokens = []; this.token = null; this.options = options || marked.defaults; @@ -1138,7 +1138,7 @@ function Parser (options) { * Static Parse Method */ -Parser.parse = function (src, options) { +Parser.parse = function(src, options) { var parser = new Parser(options); return parser.parse(src); }; @@ -1147,7 +1147,7 @@ Parser.parse = function (src, options) { * Parse Loop */ -Parser.prototype.parse = function (src) { +Parser.prototype.parse = function(src) { this.inline = new InlineLexer(src.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text this.inlineText = new InlineLexer( @@ -1168,7 +1168,7 @@ Parser.prototype.parse = function (src) { * Next Token */ -Parser.prototype.next = function () { +Parser.prototype.next = function() { this.token = this.tokens.pop(); return this.token; }; @@ -1177,7 +1177,7 @@ Parser.prototype.next = function () { * Preview Next Token */ -Parser.prototype.peek = function () { +Parser.prototype.peek = function() { return this.tokens[this.tokens.length - 1] || 0; }; @@ -1185,7 +1185,7 @@ Parser.prototype.peek = function () { * Parse Text Tokens */ -Parser.prototype.parseText = function () { +Parser.prototype.parseText = function() { var body = this.token.text; while (this.peek().type === 'text') { @@ -1199,7 +1199,7 @@ Parser.prototype.parseText = function () { * Parse Current Token */ -Parser.prototype.tok = function () { +Parser.prototype.tok = function() { switch (this.token.type) { case 'space': { return ''; @@ -1328,7 +1328,7 @@ Parser.prototype.tok = function () { * Slugger generates header id */ -function Slugger () { +function Slugger() { this.seen = {}; } @@ -1336,7 +1336,7 @@ function Slugger () { * Convert string to unique id */ -Slugger.prototype.slug = function (value) { +Slugger.prototype.slug = function(value) { var slug = value .toLowerCase() .trim() @@ -1359,14 +1359,14 @@ Slugger.prototype.slug = function (value) { * Helpers */ -function escape (html, encode) { +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]; }); } } @@ -1386,9 +1386,9 @@ escape.replacements = { escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; -function unescape (html) { +function unescape(html) { // 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(); if (n === 'colon') return ':'; if (n.charAt(0) === '#') { @@ -1400,23 +1400,23 @@ function unescape (html) { }); } -function edit (regex, opt) { +function edit(regex, opt) { regex = regex.source || regex; opt = opt || ''; return { - replace: function (name, val) { + replace: function(name, val) { val = val.source || val; val = val.replace(/(^|[^\[])\^/g, '$1'); regex = regex.replace(name, val); return this; }, - getRegex: function () { + getRegex: function() { return new RegExp(regex, opt); } }; } -function cleanUrl (sanitize, base, href) { +function cleanUrl(sanitize, base, href) { if (sanitize) { try { var prot = decodeURIComponent(unescape(href)) @@ -1440,7 +1440,7 @@ function cleanUrl (sanitize, base, href) { return href; } -function resolveUrl (base, href) { +function resolveUrl(base, href) { if (!baseUrls[' ' + base]) { // we can ignore everything in base after the last slash of its path component, // but we might need to add _that_ @@ -1464,10 +1464,10 @@ function resolveUrl (base, href) { var baseUrls = {}; var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; -function noop () {} +function noop() {} noop.exec = noop; -function merge (obj) { +function merge(obj) { var i = 1, target, key; @@ -1484,10 +1484,10 @@ function merge (obj) { return obj; } -function splitCells (tableRow, count) { +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; @@ -1519,7 +1519,7 @@ function splitCells (tableRow, count) { // Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). // /c*$/ is vulnerable to REDOS. // invert: Remove suffix of non-c chars instead. Default falsey. -function rtrim (str, c, invert) { +function rtrim(str, c, invert) { if (str.length === 0) { return ''; } @@ -1542,7 +1542,7 @@ function rtrim (str, c, invert) { return str.substr(0, str.length - suffLen); } -function findClosingBracket (str, b) { +function findClosingBracket(str, b) { if (str.indexOf(b[1]) === -1) { return -1; } @@ -1566,7 +1566,7 @@ function findClosingBracket (str, b) { * Marked */ -function marked (src, opt, callback) { +function marked(src, opt, callback) { // throw error in case of non string input if (typeof src === 'undefined' || src === null) { throw new Error('marked(): input parameter is undefined or null'); @@ -1597,7 +1597,7 @@ function marked (src, opt, callback) { pending = tokens.length; - var done = function (err) { + var done = function(err) { if (err) { opt.highlight = highlight; return callback(err); @@ -1627,11 +1627,11 @@ function marked (src, opt, callback) { if (!pending) return done(); for (; i < tokens.length; i++) { - (function (token) { + (function(token) { if (token.type !== 'code') { 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 (code == null || code === token.text) { return --pending || done(); @@ -1664,12 +1664,12 @@ function marked (src, opt, callback) { */ marked.options = -marked.setOptions = function (opt) { +marked.setOptions = function(opt) { merge(marked.defaults, opt); return marked; }; -marked.getDefaults = function () { +marked.getDefaults = function() { return { baseUrl: null, breaks: false, @@ -1716,7 +1716,7 @@ marked.parse = marked; if (typeof module !== 'undefined' && typeof exports === 'object') { module.exports = marked; } else if (typeof define === 'function' && define.amd) { - define(function () { return marked; }); + define(function() { return marked; }); } else { root.marked = marked; }