diff --git a/.eslintrc.yml b/.eslintrc.yml index 1ee633c..4031bb2 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -28,7 +28,7 @@ rules: guard-for-in: 2 handle-callback-err: 2 - indent: [ 2, 2, { VariableDeclarator: { var: 2, let: 2, const: 3 }, SwitchCase: 1 } ] + indent: [ 2, 2, { VariableDeclarator: { var: 2, let: 2, const: 3 }, SwitchCase: 1, ignoreComments: true } ] # key-spacing: [ 2, { "align": "value" } ] keyword-spacing: 2 diff --git a/lib/common/utils.js b/lib/common/utils.js index 17dd817..33bfcc4 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -88,9 +88,8 @@ function replaceEntityPattern(match, name) { if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { code = name[1].toLowerCase() === 'x' ? - parseInt(name.slice(2), 16) - : - parseInt(name.slice(1), 10); + parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10); + if (isValidEntityCode(code)) { return fromCodePoint(code); } diff --git a/lib/rules_core/replacements.js b/lib/rules_core/replacements.js index de604ed..5b5a157 100644 --- a/lib/rules_core/replacements.js +++ b/lib/rules_core/replacements.js @@ -62,16 +62,16 @@ function replace_rare(inlineTokens) { if (token.type === 'text' && !inside_autolink) { if (RARE_RE.test(token.content)) { token.content = token.content - .replace(/\+-/g, '±') - // .., ..., ....... -> … - // but ?..... & !..... -> ?.. & !.. - .replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..') - .replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',') - // em-dash - .replace(/(^|[^-])---([^-]|$)/mg, '$1\u2014$2') - // en-dash - .replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2') - .replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2'); + .replace(/\+-/g, '±') + // .., ..., ....... -> … + // but ?..... & !..... -> ?.. & !.. + .replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..') + .replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',') + // em-dash + .replace(/(^|[^-])---([^-]|$)/mg, '$1\u2014$2') + // en-dash + .replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2') + .replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2'); } } diff --git a/lib/rules_inline/backticks.js b/lib/rules_inline/backticks.js index b585c6f..3a172f1 100644 --- a/lib/rules_inline/backticks.js +++ b/lib/rules_inline/backticks.js @@ -29,8 +29,8 @@ module.exports = function backtick(state, silent) { token = state.push('code_inline', 'code', 0); token.markup = marker; token.content = state.src.slice(pos, matchStart) - .replace(/\n/g, ' ') - .replace(/^ (.+) $/, '$1'); + .replace(/\n/g, ' ') + .replace(/^ (.+) $/, '$1'); } state.pos = matchEnd; return true; diff --git a/package.json b/package.json index 05fc25b..2644af3 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "browserify": "^16.3.0", "chai": "^4.2.0", "coveralls": "^3.0.4", - "eslint": "^3.5.0", + "eslint": "^6.0.1", "express": "^4.14.0", "highlight.js": "^9.2.0", "istanbul": "^0.4.5", diff --git a/support/demo_template/index.js b/support/demo_template/index.js index 0565a5a..7c848e7 100644 --- a/support/demo_template/index.js +++ b/support/demo_template/index.js @@ -130,25 +130,25 @@ function mdInit() { mdSrc = window.markdownit('commonmark'); } else { mdHtml = window.markdownit(defaults) - .use(require('markdown-it-abbr')) - .use(require('markdown-it-container'), 'warning') - .use(require('markdown-it-deflist')) - .use(require('markdown-it-emoji')) - .use(require('markdown-it-footnote')) - .use(require('markdown-it-ins')) - .use(require('markdown-it-mark')) - .use(require('markdown-it-sub')) - .use(require('markdown-it-sup')); + .use(require('markdown-it-abbr')) + .use(require('markdown-it-container'), 'warning') + .use(require('markdown-it-deflist')) + .use(require('markdown-it-emoji')) + .use(require('markdown-it-footnote')) + .use(require('markdown-it-ins')) + .use(require('markdown-it-mark')) + .use(require('markdown-it-sub')) + .use(require('markdown-it-sup')); mdSrc = window.markdownit(defaults) - .use(require('markdown-it-abbr')) - .use(require('markdown-it-container'), 'warning') - .use(require('markdown-it-deflist')) - .use(require('markdown-it-emoji')) - .use(require('markdown-it-footnote')) - .use(require('markdown-it-ins')) - .use(require('markdown-it-mark')) - .use(require('markdown-it-sub')) - .use(require('markdown-it-sup')); + .use(require('markdown-it-abbr')) + .use(require('markdown-it-container'), 'warning') + .use(require('markdown-it-deflist')) + .use(require('markdown-it-emoji')) + .use(require('markdown-it-footnote')) + .use(require('markdown-it-ins')) + .use(require('markdown-it-mark')) + .use(require('markdown-it-sub')) + .use(require('markdown-it-sup')); } // Beautify output of parser for html content diff --git a/support/specsplit.js b/support/specsplit.js index 038664b..c87f0b5 100755 --- a/support/specsplit.js +++ b/support/specsplit.js @@ -76,34 +76,34 @@ readFile(options.spec, 'utf8', function (error, input) { input = input.replace(/→/g, '\t'); markdown.parse(input, {}) - .filter(function (token) { - return token.tag === 'code' && - token.info.trim() === 'example'; - }) - .forEach(function (token) { - var arr = token.content.split(/^\.\s*?$/m, 2); - var md = arr[0]; - var html = arr[1].replace(/^\n/, ''); - - var result = { - md: md, - html: html, - line: token.map[0], - err: '' - }; - - try { - if (markdown.render(md) === normalize(html)) { - good.push(result); - } else { - result.err = markdown.render(md); - bad.push(result); - } - } catch (___) { - // bad.push(result); - throw ___; - } - }); + .filter(function (token) { + return token.tag === 'code' && + token.info.trim() === 'example'; + }) + .forEach(function (token) { + var arr = token.content.split(/^\.\s*?$/m, 2); + var md = arr[0]; + var html = arr[1].replace(/^\n/, ''); + + var result = { + md: md, + html: html, + line: token.map[0], + err: '' + }; + + try { + if (markdown.render(md) === normalize(html)) { + good.push(result); + } else { + result.err = markdown.render(md); + bad.push(result); + } + } catch (___) { + // bad.push(result); + throw ___; + } + }); if (!options.type) { console.log(util.format('passed samples - %s, failed samples - %s', good.length, bad.length)); diff --git a/test/misc.js b/test/misc.js index 8cf3bf5..c933afa 100644 --- a/test/misc.js +++ b/test/misc.js @@ -215,9 +215,9 @@ describe('Misc', function () { it('Should render link target attr', function () { var md = markdownit() - .use(require('markdown-it-for-inline'), 'target', 'link_open', function (tokens, idx) { - tokens[idx].attrs.push([ 'target', '_blank' ]); - }); + .use(require('markdown-it-for-inline'), 'target', 'link_open', function (tokens, idx) { + tokens[idx].attrs.push([ 'target', '_blank' ]); + }); assert.strictEqual(md.render('[foo](bar)'), '
\n'); });