diff --git a/docs/.eslintrc.json b/docs/.eslintrc.json index 1014c317..cf5a3610 100644 --- a/docs/.eslintrc.json +++ b/docs/.eslintrc.json @@ -1,7 +1,7 @@ { "extends": "standard", "parserOptions": { - "ecmaVersion": 5, + "ecmaVersion": 2015, "sourceType": "script" }, "rules": { @@ -19,8 +19,8 @@ "no-control-regex": "off", "no-prototype-builtins": "off", - "prefer-const": "off", - "no-var": "off" + "prefer-const": "error", + "no-var": "error" }, "env": { "node": true, diff --git a/docs/demo/demo.js b/docs/demo/demo.js index 129a67fa..536e4202 100644 --- a/docs/demo/demo.js +++ b/docs/demo/demo.js @@ -11,35 +11,35 @@ onunhandledrejection = function(e) { throw e.reason; }; -var $loadingElem = document.querySelector('#loading'); -var $mainElem = document.querySelector('#main'); -var $markdownElem = document.querySelector('#markdown'); -var $markedVerElem = document.querySelector('#markedVersion'); -var $commitVerElem = document.querySelector('#commitVersion'); -var $markedVer = document.querySelector('#markedCdn'); -var $optionsElem = document.querySelector('#options'); -var $outputTypeElem = document.querySelector('#outputType'); -var $inputTypeElem = document.querySelector('#inputType'); -var $responseTimeElem = document.querySelector('#responseTime'); -var $previewElem = document.querySelector('#preview'); -var $previewIframe = document.querySelector('#preview iframe'); -var $permalinkElem = document.querySelector('#permalink'); -var $clearElem = document.querySelector('#clear'); -var $htmlElem = document.querySelector('#html'); -var $lexerElem = document.querySelector('#lexer'); -var $panes = document.querySelectorAll('.pane'); -var $inputPanes = document.querySelectorAll('.inputPane'); -var lastInput = ''; -var inputDirty = true; -var $activeOutputElem = null; -var search = searchToObject(); -var markedVersions = { +const $loadingElem = document.querySelector('#loading'); +const $mainElem = document.querySelector('#main'); +const $markdownElem = document.querySelector('#markdown'); +const $markedVerElem = document.querySelector('#markedVersion'); +const $commitVerElem = document.querySelector('#commitVersion'); +let $markedVer = document.querySelector('#markedCdn'); +const $optionsElem = document.querySelector('#options'); +const $outputTypeElem = document.querySelector('#outputType'); +const $inputTypeElem = document.querySelector('#inputType'); +const $responseTimeElem = document.querySelector('#responseTime'); +const $previewElem = document.querySelector('#preview'); +const $previewIframe = document.querySelector('#preview iframe'); +const $permalinkElem = document.querySelector('#permalink'); +const $clearElem = document.querySelector('#clear'); +const $htmlElem = document.querySelector('#html'); +const $lexerElem = document.querySelector('#lexer'); +const $panes = document.querySelectorAll('.pane'); +const $inputPanes = document.querySelectorAll('.inputPane'); +let lastInput = ''; +let inputDirty = true; +let $activeOutputElem = null; +const search = searchToObject(); +const markedVersions = { master: 'https://cdn.jsdelivr.net/gh/markedjs/marked/marked.min.js' }; -var markedVersionCache = {}; -var delayTime = 1; -var checkChangeTimeout = null; -var markedWorker; +const markedVersionCache = {}; +let delayTime = 1; +let checkChangeTimeout = null; +let markedWorker; $previewIframe.addEventListener('load', handleIframeLoad); @@ -107,10 +107,10 @@ function setInitialVersion() { return res.json(); }) .then(function(json) { - for (var i = 0; i < json.versions.length; i++) { - var ver = json.versions[i]; + for (let i = 0; i < json.versions.length; i++) { + const ver = json.versions[i]; markedVersions[ver] = 'https://cdn.jsdelivr.net/npm/marked@' + ver + '/marked.min.js'; - var opt = document.createElement('option'); + const opt = document.createElement('option'); opt.textContent = ver; opt.value = ver; $markedVerElem.appendChild(opt); @@ -134,7 +134,7 @@ function setInitialVersion() { if (markedVersions[search.version]) { return search.version; } else { - var match = search.version.match(/^(\w+):(.+)$/); + const match = search.version.match(/^(\w+):(.+)$/); if (match) { switch (match[1]) { case 'commit': @@ -204,8 +204,8 @@ function handleClearClick() { function handleAddVersion(e) { if (e.which === 13) { switch ($markedVerElem.value) { - case 'commit': - var commit = $commitVerElem.value.toLowerCase(); + case 'commit': { + const commit = $commitVerElem.value.toLowerCase(); if (!commit.match(/^[0-9a-f]{40}$/)) { alert('That is not a valid commit'); return; @@ -216,9 +216,10 @@ function handleAddVersion(e) { $commitVerElem.value = ''; updateVersion(); break; - case 'pr': + } + case 'pr': { $commitVerElem.disabled = true; - var pr = $commitVerElem.value.replace(/\D/g, ''); + const pr = $commitVerElem.value.replace(/\D/g, ''); getPrCommit(pr) .then(function(commit) { $commitVerElem.disabled = false; @@ -232,6 +233,8 @@ function handleAddVersion(e) { $commitVerElem.value = ''; updateVersion(); }); + break; + } } } } @@ -246,8 +249,8 @@ function handleOutputChange() { } function handleChange(panes, visiblePane) { - var active = null; - for (var i = 0; i < panes.length; i++) { + let active = null; + for (let i = 0; i < panes.length; i++) { if (panes[i].id === visiblePane) { panes[i].style.display = ''; active = panes[i]; @@ -263,7 +266,7 @@ function addCommitVersion(value, text, commit) { return; } markedVersions[value] = 'https://cdn.jsdelivr.net/gh/markedjs/marked@' + commit + '/marked.min.js'; - var opt = document.createElement('option'); + const opt = document.createElement('option'); opt.textContent = text; opt.value = value; $markedVerElem.insertBefore(opt, $markedVerElem.firstChild); @@ -288,7 +291,7 @@ function setDefaultOptions() { version: markedVersions[$markedVerElem.value] }); } else { - var defaults = marked.getDefaults(); + const defaults = marked.getDefaults(); setOptions(defaults); } } @@ -306,15 +309,15 @@ function setOptions(opts) { function searchToObject() { // modified from https://stackoverflow.com/a/7090123/806777 - var pairs = location.search.slice(1).split('&'); - var obj = {}; + const pairs = location.search.slice(1).split('&'); + const obj = {}; - for (var i = 0; i < pairs.length; i++) { + for (let i = 0; i < pairs.length; i++) { if (pairs[i] === '') { continue; } - var pair = pairs[i].split('='); + const pair = pairs[i].split('='); obj[decodeURIComponent(pair.shift())] = decodeURIComponent(pair.join('=')); } @@ -332,8 +335,8 @@ function jsonString(input, level) { if (input.length === 0) { return '[]'; } - var items = [], - i; + const items = []; + let i; if (!isArray(input[0]) && typeof input[0] === 'object' && input[0] !== null) { for (i = 0; i < input.length; i++) { items.push(' '.repeat(2 * level) + jsonString(input[i], level + 1)); @@ -345,8 +348,8 @@ function jsonString(input, level) { } return '[' + items.join(', ') + ']'; } else if (typeof input === 'object' && input !== null) { - var props = []; - for (var prop in input) { + const props = []; + for (const prop in input) { props.push(prop + ':' + jsonString(input[prop], level)); } return '{' + props.join(', ') + '}'; @@ -356,13 +359,13 @@ function jsonString(input, level) { } function getScrollSize() { - var e = $activeOutputElem; + const e = $activeOutputElem; return e.scrollHeight - e.clientHeight; } function getScrollPercent() { - var size = getScrollSize(); + const size = getScrollSize(); if (size <= 0) { return 1; @@ -376,7 +379,7 @@ function setScrollPercent(percent) { } function updateLink() { - var outputType = ''; + let outputType = ''; if ($outputTypeElem.value !== 'preview') { outputType = 'outputType=' + $outputTypeElem.value + '&'; } @@ -392,7 +395,7 @@ function updateVersion() { handleInput(); return Promise.resolve(); } - var promise; + let promise; if (markedVersionCache[$markedVerElem.value]) { promise = Promise.resolve(markedVersionCache[$markedVerElem.value]); } else { @@ -404,7 +407,7 @@ function updateVersion() { }); } return promise.then(function(text) { - var script = document.createElement('script'); + const script = document.createElement('script'); script.textContent = text; $markedVer.parentNode.replaceChild(script, $markedVer); @@ -418,40 +421,40 @@ function checkForChanges() { updateLink(); - var options = {}; - var optionsString = $optionsElem.value || '{}'; + let options = {}; + const optionsString = $optionsElem.value || '{}'; try { - var newOptions = JSON.parse(optionsString); + const newOptions = JSON.parse(optionsString); options = newOptions; $optionsElem.classList.remove('error'); } catch (err) { $optionsElem.classList.add('error'); } - var version = markedVersions[$markedVerElem.value]; - var markdown = $markdownElem.value; - var hash = version + markdown + optionsString; + const version = markedVersions[$markedVerElem.value]; + const markdown = $markdownElem.value; + const hash = version + markdown + optionsString; if (lastInput !== hash) { lastInput = hash; if (window.Worker) { delayTime = 100; messageWorker({ task: 'parse', - version: version, - markdown: markdown, - options: options + version, + markdown, + options }); } else { - var startTime = new Date(); - var lexed = marked.lexer(markdown, options); - var lexedList = jsonString(lexed); - var parsed = marked.parser(lexed, options); - var endTime = new Date(); + const startTime = new Date(); + const lexed = marked.lexer(markdown, options); + const lexedList = jsonString(lexed); + const parsed = marked.parser(lexed, options); + const endTime = new Date(); $previewElem.classList.remove('error'); $htmlElem.classList.remove('error'); $lexerElem.classList.remove('error'); - var scrollPercent = getScrollPercent(); + const scrollPercent = getScrollPercent(); setParsed(parsed, lexedList); setScrollPercent(scrollPercent); delayTime = endTime - startTime; @@ -468,8 +471,8 @@ function checkForChanges() { } function setResponseTime(ms) { - var amount = ms; - var suffix = 'ms'; + let amount = ms; + let suffix = 'ms'; if (ms > 1000 * 60 * 60) { amount = 'Too Long'; suffix = ''; @@ -491,7 +494,7 @@ function setParsed(parsed, lexed) { $lexerElem.value = lexed; } -var workerPromises = {}; +const workerPromises = {}; function messageWorker(message) { if (!markedWorker || markedWorker.working) { if (markedWorker) { @@ -503,18 +506,20 @@ function messageWorker(message) { clearTimeout(markedWorker.timeout); markedWorker.working = false; switch (e.data.task) { - case 'defaults': + case 'defaults': { setOptions(e.data.defaults); break; - case 'parse': + } + case 'parse': { $previewElem.classList.remove('error'); $htmlElem.classList.remove('error'); $lexerElem.classList.remove('error'); - var scrollPercent = getScrollPercent(); + const scrollPercent = getScrollPercent(); setParsed(e.data.parsed, e.data.lexed); setScrollPercent(scrollPercent); setResponseTime(e.data.time); break; + } } clearTimeout(checkChangeTimeout); delayTime = 10; @@ -524,7 +529,7 @@ function messageWorker(message) { }; markedWorker.onerror = markedWorker.onmessageerror = function(err) { clearTimeout(markedWorker.timeout); - var error = 'There was an error in the Worker'; + let error = 'There was an error in the Worker'; if (err) { if (err.message) { error = err.message; @@ -552,7 +557,7 @@ function messageWorker(message) { } function uniqueWorkerMessageId() { - var id; + let id; do { id = Math.random().toString(36); } while (id in workerPromises); diff --git a/docs/demo/worker.js b/docs/demo/worker.js index 5c292859..b8cf1c4a 100644 --- a/docs/demo/worker.js +++ b/docs/demo/worker.js @@ -9,8 +9,8 @@ if (!self.fetch) { self.fetch = unfetch; } -var versionCache = {}; -var currentVersion; +const versionCache = {}; +let currentVersion; onunhandledrejection = function(e) { throw e.reason; @@ -27,12 +27,12 @@ onmessage = function(e) { }; function getDefaults() { - var defaults = {}; + let defaults = {}; if (typeof marked.getDefaults === 'function') { defaults = marked.getDefaults(); delete defaults.renderer; } else if ('defaults' in marked) { - for (var prop in marked.defaults) { + for (const prop in marked.defaults) { if (prop !== 'renderer') { defaults[prop] = marked.defaults[prop]; } @@ -42,9 +42,9 @@ function getDefaults() { } function mergeOptions(options) { - var defaults = getDefaults(); - var opts = {}; - var invalidOptions = [ + const defaults = getDefaults(); + const opts = {}; + const invalidOptions = [ 'renderer', 'tokenizer', 'walkTokens', @@ -52,7 +52,7 @@ function mergeOptions(options) { 'highlight', 'sanitizer' ]; - for (var prop in defaults) { + for (const prop in defaults) { opts[prop] = invalidOptions.includes(prop) || !(prop in options) ? defaults[prop] : options[prop]; @@ -62,28 +62,30 @@ function mergeOptions(options) { function parse(e) { switch (e.data.task) { - case 'defaults': + case 'defaults': { postMessage({ id: e.data.id, task: e.data.task, defaults: getDefaults() }); break; - case 'parse': - var options = mergeOptions(e.data.options); - var startTime = new Date(); - var lexed = marked.lexer(e.data.markdown, options); - var lexedList = jsonString(lexed); - var parsed = marked.parser(lexed, options); - var endTime = new Date(); + } + case 'parse': { + const options = mergeOptions(e.data.options); + const startTime = new Date(); + const lexed = marked.lexer(e.data.markdown, options); + const lexedList = jsonString(lexed); + const parsed = marked.parser(lexed, options); + const endTime = new Date(); postMessage({ id: e.data.id, task: e.data.task, lexed: lexedList, - parsed: parsed, + parsed, time: endTime - startTime }); break; + } } } @@ -93,8 +95,8 @@ function jsonString(input, level) { if (input.length === 0) { return '[]'; } - var items = [], - i; + const items = []; + let i; if (!Array.isArray(input[0]) && typeof input[0] === 'object' && input[0] !== null) { for (i = 0; i < input.length; i++) { items.push(' '.repeat(2 * level) + jsonString(input[i], level + 1)); @@ -106,8 +108,8 @@ function jsonString(input, level) { } return '[' + items.join(', ') + ']'; } else if (typeof input === 'object' && input !== null) { - var props = []; - for (var prop in input) { + const props = []; + for (const prop in input) { props.push(prop + ':' + jsonString(input[prop], level)); } return '{' + props.join(', ') + '}'; @@ -117,7 +119,7 @@ function jsonString(input, level) { } function loadVersion(ver) { - var promise; + let promise; if (versionCache[ver]) { promise = Promise.resolve(versionCache[ver]); } else { diff --git a/docs/js/index.js b/docs/js/index.js index 8e46ca2c..2f896564 100644 --- a/docs/js/index.js +++ b/docs/js/index.js @@ -1,18 +1,17 @@ - -var match = /#\/(.+)\\.md(.*)/g.exec(window.location.hash); +const match = /#\/(.+)\\.md(.*)/g.exec(window.location.hash); if (match && match[1]) { // Redirect from URL format to new URL, for example: // Old: https://marked.js.org/#/USING_PRO.md#renderer // New: https://marked.js.org/using_pro#renderer - var pageName = match[1].toLowerCase(); - var sectionName = match[2]; + const pageName = match[1].toLowerCase(); + const sectionName = match[2]; window.location.href = '/' + pageName + sectionName; } -var navLinks = document.querySelectorAll('nav a'); +const navLinks = document.querySelectorAll('nav a'); function hashChange() { - var fullUrl = window.location.href; + const fullUrl = window.location.href; navLinks.forEach(function(link) { link.className = link.href === fullUrl ? 'selected' : ''; }); @@ -26,14 +25,14 @@ window.addEventListener('hashchange', function(e) { hashChange(); document.addEventListener('DOMContentLoaded', function() { - var div = document.createElement('div'); + const div = document.createElement('div'); div.innerHTML = '
'; div.className = 'div-copy'; - var allPres = document.querySelectorAll('pre'); + const allPres = document.querySelectorAll('pre'); allPres.forEach(function(pre) { - var timeout = null; - var copy = div.cloneNode(true); + let timeout = null; + const copy = div.cloneNode(true); pre.appendChild(copy); pre.onmouseover = function() { copy.classList.add('active'); diff --git a/package-lock.json b/package-lock.json index 144b8f34..d8fe4e85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "cheerio": "^1.0.0-rc.12", "commonmark": "0.30.0", "eslint": "^8.42.0", - "eslint-config-standard": "^17.0.0", + "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.27.5", "eslint-plugin-n": "^15.7.0", "eslint-plugin-promise": "^6.1.1", @@ -4407,9 +4407,9 @@ } }, "node_modules/eslint-config-standard": { - "version": "17.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.0.0.tgz", - "integrity": "sha512-/2ks1GKyqSOkH7JFvXJicu0iMpoojkwB+f5Du/1SC0PtBL+s8v30k9njRZ21pm2drKYm2342jFnGWzttxPmZVg==", + "version": "17.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.1.0.tgz", + "integrity": "sha512-IwHwmaBNtDK4zDHQukFDW5u/aTb8+meQWZvNFWkiGmbWjD6bqyuSSBxxXKkCftCUzc1zwCH2m/baCNDLGmuO5Q==", "dev": true, "funding": [ { @@ -4425,10 +4425,13 @@ "url": "https://feross.org/support" } ], + "engines": { + "node": ">=12.0.0" + }, "peerDependencies": { "eslint": "^8.0.1", "eslint-plugin-import": "^2.25.2", - "eslint-plugin-n": "^15.0.0", + "eslint-plugin-n": "^15.0.0 || ^16.0.0 ", "eslint-plugin-promise": "^6.0.0" } }, @@ -15610,9 +15613,9 @@ } }, "eslint-config-standard": { - "version": "17.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.0.0.tgz", - "integrity": "sha512-/2ks1GKyqSOkH7JFvXJicu0iMpoojkwB+f5Du/1SC0PtBL+s8v30k9njRZ21pm2drKYm2342jFnGWzttxPmZVg==", + "version": "17.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.1.0.tgz", + "integrity": "sha512-IwHwmaBNtDK4zDHQukFDW5u/aTb8+meQWZvNFWkiGmbWjD6bqyuSSBxxXKkCftCUzc1zwCH2m/baCNDLGmuO5Q==", "dev": true, "requires": {} }, diff --git a/package.json b/package.json index ea13d166..b2106a98 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "cheerio": "^1.0.0-rc.12", "commonmark": "0.30.0", "eslint": "^8.42.0", - "eslint-config-standard": "^17.0.0", + "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.27.5", "eslint-plugin-n": "^15.7.0", "eslint-plugin-promise": "^6.1.1",