Browse Source

standard: spaces in comments

pull/979/head
Vitaly Puzrin 5 months ago
parent
commit
94177fca70
  1. 5
      .eslintrc.yml
  2. 2
      benchmark/benchmark.mjs
  3. 2
      benchmark/profile.mjs
  4. 5
      bin/markdown-it.mjs
  5. 18
      lib/common/utils.mjs
  6. 4
      lib/index.mjs
  7. 2
      lib/parser_inline.mjs
  8. 1
      lib/renderer.mjs
  9. 2
      lib/ruler.mjs
  10. 2
      lib/rules_block/code.mjs
  11. 2
      lib/rules_block/lheading.mjs
  12. 6
      lib/rules_block/reference.mjs
  13. 4
      lib/rules_core/smartquotes.mjs
  14. 2
      lib/rules_inline/autolink.mjs
  15. 2
      lib/rules_inline/html_inline.mjs
  16. 2
      lib/rules_inline/text.mjs
  17. 2
      support/build_demo.mjs
  18. 9
      support/demo_template/index.mjs
  19. 6
      support/specsplit.mjs
  20. 4
      test/misc.mjs
  21. 4
      test/utils.mjs

5
.eslintrc.yml

@ -153,7 +153,10 @@ rules:
space-infix-ops: 2
space-unary-ops: 2
# Postponed
#spaced-comment: [ 1, always, { exceptions: [ '/', '=' ] } ]
spaced-comment: [ 2, 'always', {
line: { markers: ['*package', '!', '/', ',', '='] },
block: { balanced: true, markers: ['*package', '!', ',', ':', '::', 'flow-include'], exceptions: ['*'] }
}]
strict: [ 2, global ]
quotes: [ 2, single, avoid-escape ]
quote-props: [ 1, 'as-needed' ]

2
benchmark/benchmark.mjs

@ -1,5 +1,5 @@
#!/usr/bin/env node
/*eslint no-console:0*/
/* eslint no-console:0 */
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)

2
benchmark/profile.mjs

@ -1,5 +1,5 @@
#!/usr/bin/env node
/*eslint no-console:0*/
/* eslint no-console:0 */
import { readFileSync } from 'fs'
import markdownit from '../index.mjs'

5
bin/markdown-it.mjs

@ -1,11 +1,10 @@
#!/usr/bin/env node
/*eslint no-console:0*/
/* eslint no-console:0 */
import fs from 'node:fs'
import argparse from 'argparse'
import markdownit from '../index.mjs'
////////////////////////////////////////////////////////////////////////////////
const cli = new argparse.ArgumentParser({
prog: 'markdown-it',
@ -67,8 +66,6 @@ function readFile (filename, encoding, callback) {
}
////////////////////////////////////////////////////////////////////////////////
readFile(options.file, 'utf8', function (err, input) {
let output

18
lib/common/utils.mjs

@ -18,7 +18,7 @@ function has (object, key) {
// Merge objects
//
function assign (obj /*from1, from2, from3, ...*/) {
function assign (obj /* from1, from2, from3, ... */) {
const sources = Array.prototype.slice.call(arguments, 1)
sources.forEach(function (source) {
@ -42,10 +42,9 @@ function arrayReplaceAt (src, pos, newElements) {
return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1))
}
////////////////////////////////////////////////////////////////////////////////
function isValidEntityCode (c) {
/*eslint no-bitwise:0*/
/* eslint no-bitwise:0 */
// broken sequence
if (c >= 0xD800 && c <= 0xDFFF) { return false }
// never used
@ -62,7 +61,7 @@ function isValidEntityCode (c) {
}
function fromCodePoint (c) {
/*eslint no-bitwise:0*/
/* eslint no-bitwise:0 */
if (c > 0xffff) {
c -= 0x10000
const surrogate1 = 0xd800 + (c >> 10)
@ -101,11 +100,11 @@ function replaceEntityPattern (match, name) {
return match
}
/*function replaceEntities(str) {
/* function replaceEntities(str) {
if (str.indexOf('&') < 0) { return str; }
return str.replace(ENTITY_RE, replaceEntityPattern);
}*/
} */
function unescapeMd (str) {
if (str.indexOf('\\') < 0) { return str }
@ -121,7 +120,6 @@ function unescapeAll (str) {
})
}
////////////////////////////////////////////////////////////////////////////////
const HTML_ESCAPE_TEST_RE = /[&<>"]/
const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g
@ -143,7 +141,6 @@ function escapeHtml (str) {
return str
}
////////////////////////////////////////////////////////////////////////////////
const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g
@ -151,7 +148,6 @@ function escapeRE (str) {
return str.replace(REGEXP_ESCAPE_RE, '\\$&')
}
////////////////////////////////////////////////////////////////////////////////
function isSpace (code) {
switch (code) {
@ -182,9 +178,8 @@ function isWhiteSpace (code) {
return false
}
////////////////////////////////////////////////////////////////////////////////
/*eslint-disable max-len*/
/* eslint-disable max-len */
// Currently without astral characters support.
function isPunctChar (ch) {
@ -291,7 +286,6 @@ function normalizeReference (str) {
return str.toLowerCase().toUpperCase()
}
////////////////////////////////////////////////////////////////////////////////
// Re-export libraries commonly used in both markdown-it and its plugins,
// so plugins won't have to depend on them explicitly, which reduces their

4
lib/index.mjs

@ -20,7 +20,7 @@ const config = {
commonmark: cfg_commonmark
}
////////////////////////////////////////////////////////////////////////////////
//
// This validator can prohibit more than really needed to prevent XSS. It's a
// tradeoff to keep code simple and to be secure by default.
@ -39,8 +39,6 @@ function validateLink (url) {
return BAD_PROTO_RE.test(str) ? (GOOD_DATA_RE.test(str) ? true : false) : true
}
////////////////////////////////////////////////////////////////////////////////
const RECODE_HOSTNAME_FOR = ['http:', 'https:', 'mailto:']

2
lib/parser_inline.mjs

@ -24,8 +24,6 @@ import r_balance_pairs from './rules_inline/balance_pairs.mjs'
import r_fragments_join from './rules_inline/fragments_join.mjs'
////////////////////////////////////////////////////////////////////////////////
// Parser rules
const _rules = [

1
lib/renderer.mjs

@ -8,7 +8,6 @@
import { assign, unescapeAll, escapeHtml } from './common/utils.mjs'
////////////////////////////////////////////////////////////////////////////////
const default_rules = {}

2
lib/ruler.mjs

@ -40,7 +40,7 @@ function Ruler () {
this.__cache__ = null
}
////////////////////////////////////////////////////////////////////////////////
// Helper methods, should not be used directly

2
lib/rules_block/code.mjs

@ -1,6 +1,6 @@
// Code block (4 spaces padded)
export default function code (state, startLine, endLine/*, silent*/) {
export default function code (state, startLine, endLine/*, silent */) {
if (state.sCount[startLine] - state.blkIndent < 4) { return false }
let nextLine = startLine + 1

2
lib/rules_block/lheading.mjs

@ -1,6 +1,6 @@
// lheading (---, ===)
export default function lheading (state, startLine, endLine/*, silent*/) {
export default function lheading (state, startLine, endLine/*, silent */) {
const terminatorRules = state.md.block.ruler.getRules('paragraph')
// if it's indented more than 3 spaces, it should be a code block

6
lib/rules_block/reference.mjs

@ -80,7 +80,7 @@ export default function reference (state, startLine, _endLine, silent) {
if (ch === 0x0A) {
lines++
} else if (isSpace(ch)) {
/*eslint no-empty:0*/
/* eslint no-empty:0 */
} else {
break
}
@ -109,7 +109,7 @@ export default function reference (state, startLine, _endLine, silent) {
if (ch === 0x0A) {
lines++
} else if (isSpace(ch)) {
/*eslint no-empty:0*/
/* eslint no-empty:0 */
} else {
break
}
@ -164,7 +164,7 @@ export default function reference (state, startLine, _endLine, silent) {
}
// Reference can not terminate anything. This check is for safety only.
/*istanbul ignore if*/
/* istanbul ignore if */
if (silent) { return true }
if (typeof state.env.references === 'undefined') {

4
lib/rules_core/smartquotes.mjs

@ -33,7 +33,7 @@ function process_inlines (tokens, state) {
let pos = 0
let max = text.length
/*eslint no-labels:0,block-scoped-var:0*/
/* eslint no-labels:0,block-scoped-var:0 */
OUTER:
while (pos < max) {
QUOTE_RE.lastIndex = pos
@ -181,7 +181,7 @@ function process_inlines (tokens, state) {
export default function smartquotes (state) {
/*eslint max-depth:0*/
/* eslint max-depth:0 */
if (!state.md.options.typographer) { return }
for (let blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) {

2
lib/rules_inline/autolink.mjs

@ -1,6 +1,6 @@
// Process autolinks '<protocol:...>'
/*eslint max-len:0*/
/* eslint max-len:0 */
const EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/
const AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)$/

2
lib/rules_inline/html_inline.mjs

@ -12,7 +12,7 @@ function isLinkClose (str) {
function isLetter (ch) {
/*eslint no-bitwise:0*/
/* eslint no-bitwise:0 */
const lc = ch | 0x20 // to lower case
return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */)
}

2
lib/rules_inline/text.mjs

@ -83,4 +83,4 @@ module.exports = function text(state, silent) {
state.pos += idx;
return true;
};*/
}; */

2
support/build_demo.mjs

@ -9,7 +9,7 @@ function escape (input) {
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
//.replaceAll("'", '&#039;');
// .replaceAll("'", '&#039;');
}
shell.rm('-rf', 'demo')

9
support/demo_template/index.mjs

@ -1,5 +1,5 @@
/*eslint-env browser*/
/*global $, _*/
/* eslint-env browser */
/* global $, _ */
import mdurl from 'mdurl'
import hljs from 'highlight.js'
@ -50,7 +50,7 @@ defaults.highlight = function (str, lang) {
const result = hljs.highlightAuto(str)
/*eslint-disable no-console*/
/* eslint-disable no-console */
console.log('highlight language: ' + result.language + ', relevance: ' + result.relevance)
return '<pre class="hljs language-' + esc(result.language) + '"><code>' +
@ -156,7 +156,7 @@ function updateResult () {
'json'
)
} else { /*defaults._view === 'html'*/
} else { /* defaults._view === 'html' */
$('.result-html').html(mdHtml.render(source))
}
@ -349,7 +349,6 @@ function loadPermalink () {
}
//////////////////////////////////////////////////////////////////////////////
// Init on page load
//
$(function () {

6
support/specsplit.mjs

@ -1,5 +1,5 @@
#!/usr/bin/env node
/*eslint no-console:0*/
/* eslint no-console:0 */
// Fixtures generator from commonmark specs. Split spec to working / not working
// examples, or show total stat.
@ -31,13 +31,11 @@ cli.add_argument('-o', '--output', {
const options = cli.parse_args()
////////////////////////////////////////////////////////////////////////////////
function normalize (text) {
return text.replace(/<blockquote>\n<\/blockquote>/g, '<blockquote></blockquote>')
}
////////////////////////////////////////////////////////////////////////////////
function readFile (filename, encoding, callback) {
if (options.file === '-') {
@ -58,8 +56,6 @@ function readFile (filename, encoding, callback) {
}
////////////////////////////////////////////////////////////////////////////////
readFile(options.spec, 'utf8', function (error, input) {
const good = []
const bad = []

4
test/misc.mjs

@ -182,7 +182,7 @@ describe('Plugins', function () {
it('should not loop infinitely if inline rule doesn\'t increment pos', function () {
const md = markdownit()
md.inline.ruler.after('text', 'custom', function (state/*, silent*/) {
md.inline.ruler.after('text', 'custom', function (state/*, silent */) {
if (state.src.charCodeAt(state.pos) !== 0x40/* @ */) return false
return true
})
@ -194,7 +194,7 @@ describe('Plugins', function () {
it('should not loop infinitely if block rule doesn\'t increment pos', function () {
const md = markdownit()
md.block.ruler.before('paragraph', 'custom', function (state, startLine/*, endLine, silent*/) {
md.block.ruler.before('paragraph', 'custom', function (state, startLine/*, endLine, silent */) {
const pos = state.bMarks[startLine] + state.tShift[startLine]
if (state.src.charCodeAt(pos) !== 0x40/* @ */) return false
return true

4
test/utils.mjs

@ -25,7 +25,7 @@ describe('Utils', function () {
assert.strictEqual(isValidEntityCode(0x7F), false)
})
/*it('replaceEntities', function () {
/* it('replaceEntities', function () {
var replaceEntities = utils.replaceEntities;
assert.strictEqual(replaceEntities('&amp;'), '&');
@ -35,7 +35,7 @@ describe('Utils', function () {
assert.strictEqual(replaceEntities('&am;'), '&am;');
assert.strictEqual(replaceEntities('&#00;'), '&#00;');
});*/
}); */
it('assign', function () {
const assign = utils.assign

Loading…
Cancel
Save