Browse Source

standard: spaces in comments

pull/979/head
Vitaly Puzrin 6 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-infix-ops: 2
space-unary-ops: 2 space-unary-ops: 2
# Postponed # Postponed
#spaced-comment: [ 1, always, { exceptions: [ '/', '=' ] } ] spaced-comment: [ 2, 'always', {
line: { markers: ['*package', '!', '/', ',', '='] },
block: { balanced: true, markers: ['*package', '!', ',', ':', '::', 'flow-include'], exceptions: ['*'] }
}]
strict: [ 2, global ] strict: [ 2, global ]
quotes: [ 2, single, avoid-escape ] quotes: [ 2, single, avoid-escape ]
quote-props: [ 1, 'as-needed' ] quote-props: [ 1, 'as-needed' ]

2
benchmark/benchmark.mjs

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

2
benchmark/profile.mjs

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

5
bin/markdown-it.mjs

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

18
lib/common/utils.mjs

@ -18,7 +18,7 @@ function has (object, key) {
// Merge objects // Merge objects
// //
function assign (obj /*from1, from2, from3, ...*/) { function assign (obj /* from1, from2, from3, ... */) {
const sources = Array.prototype.slice.call(arguments, 1) const sources = Array.prototype.slice.call(arguments, 1)
sources.forEach(function (source) { sources.forEach(function (source) {
@ -42,10 +42,9 @@ function arrayReplaceAt (src, pos, newElements) {
return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1)) return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1))
} }
////////////////////////////////////////////////////////////////////////////////
function isValidEntityCode (c) { function isValidEntityCode (c) {
/*eslint no-bitwise:0*/ /* eslint no-bitwise:0 */
// broken sequence // broken sequence
if (c >= 0xD800 && c <= 0xDFFF) { return false } if (c >= 0xD800 && c <= 0xDFFF) { return false }
// never used // never used
@ -62,7 +61,7 @@ function isValidEntityCode (c) {
} }
function fromCodePoint (c) { function fromCodePoint (c) {
/*eslint no-bitwise:0*/ /* eslint no-bitwise:0 */
if (c > 0xffff) { if (c > 0xffff) {
c -= 0x10000 c -= 0x10000
const surrogate1 = 0xd800 + (c >> 10) const surrogate1 = 0xd800 + (c >> 10)
@ -101,11 +100,11 @@ function replaceEntityPattern (match, name) {
return match return match
} }
/*function replaceEntities(str) { /* function replaceEntities(str) {
if (str.indexOf('&') < 0) { return str; } if (str.indexOf('&') < 0) { return str; }
return str.replace(ENTITY_RE, replaceEntityPattern); return str.replace(ENTITY_RE, replaceEntityPattern);
}*/ } */
function unescapeMd (str) { function unescapeMd (str) {
if (str.indexOf('\\') < 0) { return str } if (str.indexOf('\\') < 0) { return str }
@ -121,7 +120,6 @@ function unescapeAll (str) {
}) })
} }
////////////////////////////////////////////////////////////////////////////////
const HTML_ESCAPE_TEST_RE = /[&<>"]/ const HTML_ESCAPE_TEST_RE = /[&<>"]/
const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g
@ -143,7 +141,6 @@ function escapeHtml (str) {
return str return str
} }
////////////////////////////////////////////////////////////////////////////////
const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g
@ -151,7 +148,6 @@ function escapeRE (str) {
return str.replace(REGEXP_ESCAPE_RE, '\\$&') return str.replace(REGEXP_ESCAPE_RE, '\\$&')
} }
////////////////////////////////////////////////////////////////////////////////
function isSpace (code) { function isSpace (code) {
switch (code) { switch (code) {
@ -182,9 +178,8 @@ function isWhiteSpace (code) {
return false return false
} }
////////////////////////////////////////////////////////////////////////////////
/*eslint-disable max-len*/ /* eslint-disable max-len */
// Currently without astral characters support. // Currently without astral characters support.
function isPunctChar (ch) { function isPunctChar (ch) {
@ -291,7 +286,6 @@ function normalizeReference (str) {
return str.toLowerCase().toUpperCase() return str.toLowerCase().toUpperCase()
} }
////////////////////////////////////////////////////////////////////////////////
// Re-export libraries commonly used in both markdown-it and its plugins, // 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 // 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 commonmark: cfg_commonmark
} }
////////////////////////////////////////////////////////////////////////////////
// //
// This validator can prohibit more than really needed to prevent XSS. It's a // 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. // 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 return BAD_PROTO_RE.test(str) ? (GOOD_DATA_RE.test(str) ? true : false) : true
} }
////////////////////////////////////////////////////////////////////////////////
const RECODE_HOSTNAME_FOR = ['http:', 'https:', 'mailto:'] 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' import r_fragments_join from './rules_inline/fragments_join.mjs'
////////////////////////////////////////////////////////////////////////////////
// Parser rules // Parser rules
const _rules = [ const _rules = [

1
lib/renderer.mjs

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

2
lib/ruler.mjs

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

2
lib/rules_block/code.mjs

@ -1,6 +1,6 @@
// Code block (4 spaces padded) // 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 } if (state.sCount[startLine] - state.blkIndent < 4) { return false }
let nextLine = startLine + 1 let nextLine = startLine + 1

2
lib/rules_block/lheading.mjs

@ -1,6 +1,6 @@
// lheading (---, ===) // 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') const terminatorRules = state.md.block.ruler.getRules('paragraph')
// if it's indented more than 3 spaces, it should be a code block // 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) { if (ch === 0x0A) {
lines++ lines++
} else if (isSpace(ch)) { } else if (isSpace(ch)) {
/*eslint no-empty:0*/ /* eslint no-empty:0 */
} else { } else {
break break
} }
@ -109,7 +109,7 @@ export default function reference (state, startLine, _endLine, silent) {
if (ch === 0x0A) { if (ch === 0x0A) {
lines++ lines++
} else if (isSpace(ch)) { } else if (isSpace(ch)) {
/*eslint no-empty:0*/ /* eslint no-empty:0 */
} else { } else {
break break
} }
@ -164,7 +164,7 @@ export default function reference (state, startLine, _endLine, silent) {
} }
// Reference can not terminate anything. This check is for safety only. // Reference can not terminate anything. This check is for safety only.
/*istanbul ignore if*/ /* istanbul ignore if */
if (silent) { return true } if (silent) { return true }
if (typeof state.env.references === 'undefined') { 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 pos = 0
let max = text.length let max = text.length
/*eslint no-labels:0,block-scoped-var:0*/ /* eslint no-labels:0,block-scoped-var:0 */
OUTER: OUTER:
while (pos < max) { while (pos < max) {
QUOTE_RE.lastIndex = pos QUOTE_RE.lastIndex = pos
@ -181,7 +181,7 @@ function process_inlines (tokens, state) {
export default function smartquotes (state) { export default function smartquotes (state) {
/*eslint max-depth:0*/ /* eslint max-depth:0 */
if (!state.md.options.typographer) { return } if (!state.md.options.typographer) { return }
for (let blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { for (let blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) {

2
lib/rules_inline/autolink.mjs

@ -1,6 +1,6 @@
// Process autolinks '<protocol:...>' // 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 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]*)$/ 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) { function isLetter (ch) {
/*eslint no-bitwise:0*/ /* eslint no-bitwise:0 */
const lc = ch | 0x20 // to lower case const lc = ch | 0x20 // to lower case
return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */) 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; state.pos += idx;
return true; return true;
};*/ }; */

2
support/build_demo.mjs

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

9
support/demo_template/index.mjs

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

6
support/specsplit.mjs

@ -1,5 +1,5 @@
#!/usr/bin/env node #!/usr/bin/env node
/*eslint no-console:0*/ /* eslint no-console:0 */
// Fixtures generator from commonmark specs. Split spec to working / not working // Fixtures generator from commonmark specs. Split spec to working / not working
// examples, or show total stat. // examples, or show total stat.
@ -31,13 +31,11 @@ cli.add_argument('-o', '--output', {
const options = cli.parse_args() const options = cli.parse_args()
////////////////////////////////////////////////////////////////////////////////
function normalize (text) { function normalize (text) {
return text.replace(/<blockquote>\n<\/blockquote>/g, '<blockquote></blockquote>') return text.replace(/<blockquote>\n<\/blockquote>/g, '<blockquote></blockquote>')
} }
////////////////////////////////////////////////////////////////////////////////
function readFile (filename, encoding, callback) { function readFile (filename, encoding, callback) {
if (options.file === '-') { if (options.file === '-') {
@ -58,8 +56,6 @@ function readFile (filename, encoding, callback) {
} }
////////////////////////////////////////////////////////////////////////////////
readFile(options.spec, 'utf8', function (error, input) { readFile(options.spec, 'utf8', function (error, input) {
const good = [] const good = []
const bad = [] 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 () { it('should not loop infinitely if inline rule doesn\'t increment pos', function () {
const md = markdownit() 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 if (state.src.charCodeAt(state.pos) !== 0x40/* @ */) return false
return true return true
}) })
@ -194,7 +194,7 @@ describe('Plugins', function () {
it('should not loop infinitely if block rule doesn\'t increment pos', function () { it('should not loop infinitely if block rule doesn\'t increment pos', function () {
const md = markdownit() 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] const pos = state.bMarks[startLine] + state.tShift[startLine]
if (state.src.charCodeAt(pos) !== 0x40/* @ */) return false if (state.src.charCodeAt(pos) !== 0x40/* @ */) return false
return true return true

4
test/utils.mjs

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

Loading…
Cancel
Save