Browse Source

Bump eslint & update CS

pull/570/head
Vitaly Puzrin 6 years ago
parent
commit
c36309ef1c
  1. 2
      .eslintrc.yml
  2. 5
      lib/common/utils.js
  3. 20
      lib/rules_core/replacements.js
  4. 4
      lib/rules_inline/backticks.js
  5. 2
      package.json
  6. 36
      support/demo_template/index.js
  7. 56
      support/specsplit.js
  8. 6
      test/misc.js

2
.eslintrc.yml

@ -28,7 +28,7 @@ rules:
guard-for-in: 2 guard-for-in: 2
handle-callback-err: 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" } ] # key-spacing: [ 2, { "align": "value" } ]
keyword-spacing: 2 keyword-spacing: 2

5
lib/common/utils.js

@ -88,9 +88,8 @@ function replaceEntityPattern(match, name) {
if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) {
code = name[1].toLowerCase() === 'x' ? code = name[1].toLowerCase() === 'x' ?
parseInt(name.slice(2), 16) parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10);
:
parseInt(name.slice(1), 10);
if (isValidEntityCode(code)) { if (isValidEntityCode(code)) {
return fromCodePoint(code); return fromCodePoint(code);
} }

20
lib/rules_core/replacements.js

@ -62,16 +62,16 @@ function replace_rare(inlineTokens) {
if (token.type === 'text' && !inside_autolink) { if (token.type === 'text' && !inside_autolink) {
if (RARE_RE.test(token.content)) { if (RARE_RE.test(token.content)) {
token.content = token.content token.content = token.content
.replace(/\+-/g, '±') .replace(/\+-/g, '±')
// .., ..., ....... -> … // .., ..., ....... -> …
// but ?..... & !..... -> ?.. & !.. // but ?..... & !..... -> ?.. & !..
.replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..') .replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..')
.replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',') .replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',')
// em-dash // em-dash
.replace(/(^|[^-])---([^-]|$)/mg, '$1\u2014$2') .replace(/(^|[^-])---([^-]|$)/mg, '$1\u2014$2')
// en-dash // en-dash
.replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2') .replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2')
.replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2'); .replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2');
} }
} }

4
lib/rules_inline/backticks.js

@ -29,8 +29,8 @@ module.exports = function backtick(state, silent) {
token = state.push('code_inline', 'code', 0); token = state.push('code_inline', 'code', 0);
token.markup = marker; token.markup = marker;
token.content = state.src.slice(pos, matchStart) token.content = state.src.slice(pos, matchStart)
.replace(/\n/g, ' ') .replace(/\n/g, ' ')
.replace(/^ (.+) $/, '$1'); .replace(/^ (.+) $/, '$1');
} }
state.pos = matchEnd; state.pos = matchEnd;
return true; return true;

2
package.json

@ -38,7 +38,7 @@
"browserify": "^16.3.0", "browserify": "^16.3.0",
"chai": "^4.2.0", "chai": "^4.2.0",
"coveralls": "^3.0.4", "coveralls": "^3.0.4",
"eslint": "^3.5.0", "eslint": "^6.0.1",
"express": "^4.14.0", "express": "^4.14.0",
"highlight.js": "^9.2.0", "highlight.js": "^9.2.0",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",

36
support/demo_template/index.js

@ -130,25 +130,25 @@ function mdInit() {
mdSrc = window.markdownit('commonmark'); mdSrc = window.markdownit('commonmark');
} else { } else {
mdHtml = window.markdownit(defaults) mdHtml = window.markdownit(defaults)
.use(require('markdown-it-abbr')) .use(require('markdown-it-abbr'))
.use(require('markdown-it-container'), 'warning') .use(require('markdown-it-container'), 'warning')
.use(require('markdown-it-deflist')) .use(require('markdown-it-deflist'))
.use(require('markdown-it-emoji')) .use(require('markdown-it-emoji'))
.use(require('markdown-it-footnote')) .use(require('markdown-it-footnote'))
.use(require('markdown-it-ins')) .use(require('markdown-it-ins'))
.use(require('markdown-it-mark')) .use(require('markdown-it-mark'))
.use(require('markdown-it-sub')) .use(require('markdown-it-sub'))
.use(require('markdown-it-sup')); .use(require('markdown-it-sup'));
mdSrc = window.markdownit(defaults) mdSrc = window.markdownit(defaults)
.use(require('markdown-it-abbr')) .use(require('markdown-it-abbr'))
.use(require('markdown-it-container'), 'warning') .use(require('markdown-it-container'), 'warning')
.use(require('markdown-it-deflist')) .use(require('markdown-it-deflist'))
.use(require('markdown-it-emoji')) .use(require('markdown-it-emoji'))
.use(require('markdown-it-footnote')) .use(require('markdown-it-footnote'))
.use(require('markdown-it-ins')) .use(require('markdown-it-ins'))
.use(require('markdown-it-mark')) .use(require('markdown-it-mark'))
.use(require('markdown-it-sub')) .use(require('markdown-it-sub'))
.use(require('markdown-it-sup')); .use(require('markdown-it-sup'));
} }
// Beautify output of parser for html content // Beautify output of parser for html content

56
support/specsplit.js

@ -76,34 +76,34 @@ readFile(options.spec, 'utf8', function (error, input) {
input = input.replace(/→/g, '\t'); input = input.replace(/→/g, '\t');
markdown.parse(input, {}) markdown.parse(input, {})
.filter(function (token) { .filter(function (token) {
return token.tag === 'code' && return token.tag === 'code' &&
token.info.trim() === 'example'; token.info.trim() === 'example';
}) })
.forEach(function (token) { .forEach(function (token) {
var arr = token.content.split(/^\.\s*?$/m, 2); var arr = token.content.split(/^\.\s*?$/m, 2);
var md = arr[0]; var md = arr[0];
var html = arr[1].replace(/^\n/, ''); var html = arr[1].replace(/^\n/, '');
var result = { var result = {
md: md, md: md,
html: html, html: html,
line: token.map[0], line: token.map[0],
err: '' err: ''
}; };
try { try {
if (markdown.render(md) === normalize(html)) { if (markdown.render(md) === normalize(html)) {
good.push(result); good.push(result);
} else { } else {
result.err = markdown.render(md); result.err = markdown.render(md);
bad.push(result); bad.push(result);
} }
} catch (___) { } catch (___) {
// bad.push(result); // bad.push(result);
throw ___; throw ___;
} }
}); });
if (!options.type) { if (!options.type) {
console.log(util.format('passed samples - %s, failed samples - %s', good.length, bad.length)); console.log(util.format('passed samples - %s, failed samples - %s', good.length, bad.length));

6
test/misc.js

@ -215,9 +215,9 @@ describe('Misc', function () {
it('Should render link target attr', function () { it('Should render link target attr', function () {
var md = markdownit() var md = markdownit()
.use(require('markdown-it-for-inline'), 'target', 'link_open', function (tokens, idx) { .use(require('markdown-it-for-inline'), 'target', 'link_open', function (tokens, idx) {
tokens[idx].attrs.push([ 'target', '_blank' ]); tokens[idx].attrs.push([ 'target', '_blank' ]);
}); });
assert.strictEqual(md.render('[foo](bar)'), '<p><a href="bar" target="_blank">foo</a></p>\n'); assert.strictEqual(md.render('[foo](bar)'), '<p><a href="bar" target="_blank">foo</a></p>\n');
}); });

Loading…
Cancel
Save