diff --git a/.eslintrc.yml b/.eslintrc.yml index 05b2918..d4d359b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -21,5 +21,3 @@ rules: camelcase: 0 key-spacing: 0 no-multi-spaces: 0 - no-multiple-empty-lines: 0 - padded-blocks: 0 diff --git a/benchmark/benchmark.mjs b/benchmark/benchmark.mjs index 982cf68..c08e83e 100755 --- a/benchmark/benchmark.mjs +++ b/benchmark/benchmark.mjs @@ -55,7 +55,6 @@ fs.readdirSync(new URL('./samples', import.meta.url)).sort().forEach(sample => { SAMPLES.push({ name: sample.split('.')[0], title, content, suite }) }) - function select (patterns) { const result = [] @@ -78,7 +77,6 @@ function select (patterns) { return result } - function run (files) { const selected = select(files) diff --git a/bin/markdown-it.mjs b/bin/markdown-it.mjs index c3c497e..0a8e4f0 100755 --- a/bin/markdown-it.mjs +++ b/bin/markdown-it.mjs @@ -5,7 +5,6 @@ import fs from 'node:fs' import argparse from 'argparse' import markdownit from '../index.mjs' - const cli = new argparse.ArgumentParser({ prog: 'markdown-it', add_help: true @@ -49,7 +48,6 @@ cli.add_argument('-o', '--output', { const options = cli.parse_args() - function readFile (filename, encoding, callback) { if (options.file === '-') { // read from stdin @@ -65,7 +63,6 @@ function readFile (filename, encoding, callback) { } } - readFile(options.file, 'utf8', function (err, input) { let output @@ -92,7 +89,6 @@ readFile(options.file, 'utf8', function (err, input) { try { output = md.render(input) - } catch (e) { console.error( (options.trace && e.stack) || diff --git a/lib/common/utils.mjs b/lib/common/utils.mjs index dc1b87b..0fbc183 100644 --- a/lib/common/utils.mjs +++ b/lib/common/utils.mjs @@ -41,7 +41,6 @@ function arrayReplaceAt (src, pos, newElements) { return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1)) } - function isValidEntityCode (c) { /* eslint no-bitwise:0 */ // broken sequence @@ -71,14 +70,12 @@ function fromCodePoint (c) { return String.fromCharCode(c) } - const UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g const ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi const UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.source, 'gi') const DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i - function replaceEntityPattern (match, name) { if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { const code = name[1].toLowerCase() === 'x' @@ -120,7 +117,6 @@ function unescapeAll (str) { }) } - const HTML_ESCAPE_TEST_RE = /[&<>"]/ const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g const HTML_REPLACEMENTS = { @@ -141,14 +137,12 @@ function escapeHtml (str) { return str } - const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g function escapeRE (str) { return str.replace(REGEXP_ESCAPE_RE, '\\$&') } - function isSpace (code) { switch (code) { case 0x09: @@ -178,7 +172,6 @@ function isWhiteSpace (code) { return false } - /* eslint-disable max-len */ // Currently without astral characters support. @@ -186,7 +179,6 @@ function isPunctChar (ch) { return ucmicro.P.test(ch) } - // Markdown ASCII punctuation characters. // // !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~ @@ -286,7 +278,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 // bundled size (e.g. a browser build). diff --git a/lib/helpers/parse_link_title.mjs b/lib/helpers/parse_link_title.mjs index f2eb53b..637997f 100644 --- a/lib/helpers/parse_link_title.mjs +++ b/lib/helpers/parse_link_title.mjs @@ -3,7 +3,6 @@ import { unescapeAll } from '../common/utils.mjs' - export default function parseLinkTitle (str, start, max) { let code, marker let lines = 0 diff --git a/lib/index.mjs b/lib/index.mjs index 47823db..7a23f82 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -20,7 +20,6 @@ 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,7 +38,6 @@ function validateLink (url) { return BAD_PROTO_RE.test(str) ? GOOD_DATA_RE.test(str) : true } - const RECODE_HOSTNAME_FOR = ['http:', 'https:', 'mailto:'] function normalizeLink (url) { @@ -83,7 +81,6 @@ function normalizeLinkText (url) { return mdurl.decode(mdurl.format(parsed), mdurl.decode.defaultChars + '%') } - /** * class MarkdownIt * @@ -320,7 +317,6 @@ function MarkdownIt (presetName, options) { **/ this.normalizeLinkText = normalizeLinkText - // Expose utils & helpers for easy acces from plugins /** @@ -339,14 +335,12 @@ function MarkdownIt (presetName, options) { **/ this.helpers = utils.assign({}, helpers) - this.options = {} this.configure(presetName) if (options) { this.set(options) } } - /** chainable * MarkdownIt.set(options) * @@ -371,7 +365,6 @@ MarkdownIt.prototype.set = function (options) { return this } - /** chainable, internal * MarkdownIt.configure(presets) * @@ -408,7 +401,6 @@ MarkdownIt.prototype.configure = function (presets) { return this } - /** chainable * MarkdownIt.enable(list, ignoreInvalid) * - list (String|Array): rule name or list of rule names to enable @@ -446,7 +438,6 @@ MarkdownIt.prototype.enable = function (list, ignoreInvalid) { return this } - /** chainable * MarkdownIt.disable(list, ignoreInvalid) * - list (String|Array): rule name or list of rule names to disable. @@ -473,7 +464,6 @@ MarkdownIt.prototype.disable = function (list, ignoreInvalid) { return this } - /** chainable * MarkdownIt.use(plugin, params) * @@ -496,7 +486,6 @@ MarkdownIt.prototype.use = function (plugin /*, params, ... */) { return this } - /** internal * MarkdownIt.parse(src, env) -> Array * - src (String): source string @@ -524,7 +513,6 @@ MarkdownIt.prototype.parse = function (src, env) { return state.tokens } - /** * MarkdownIt.render(src [, env]) -> String * - src (String): source string @@ -542,7 +530,6 @@ MarkdownIt.prototype.render = function (src, env) { return this.renderer.render(this.parse(src, env), this.options, env) } - /** internal * MarkdownIt.parseInline(src, env) -> Array * - src (String): source string @@ -561,7 +548,6 @@ MarkdownIt.prototype.parseInline = function (src, env) { return state.tokens } - /** * MarkdownIt.renderInline(src [, env]) -> String * - src (String): source string @@ -576,5 +562,4 @@ MarkdownIt.prototype.renderInline = function (src, env) { return this.renderer.render(this.parseInline(src, env), this.options, env) } - export default MarkdownIt diff --git a/lib/parser_block.mjs b/lib/parser_block.mjs index 27be2f7..486d68f 100644 --- a/lib/parser_block.mjs +++ b/lib/parser_block.mjs @@ -35,7 +35,6 @@ const _rules = [ ['paragraph', r_paragraph] ] - /** * new ParserBlock() **/ @@ -52,7 +51,6 @@ function ParserBlock () { } } - // Generate tokens for input range // ParserBlock.prototype.tokenize = function (state, startLine, endLine) { @@ -118,7 +116,6 @@ ParserBlock.prototype.tokenize = function (state, startLine, endLine) { } } - /** * ParserBlock.parse(str, md, env, outTokens) * @@ -132,8 +129,6 @@ ParserBlock.prototype.parse = function (src, md, env, outTokens) { this.tokenize(state, state.line, state.lineMax) } - ParserBlock.prototype.State = StateBlock - export default ParserBlock diff --git a/lib/parser_core.mjs b/lib/parser_core.mjs index 62878d9..df61d67 100644 --- a/lib/parser_core.mjs +++ b/lib/parser_core.mjs @@ -16,7 +16,6 @@ import r_replacements from './rules_core/replacements.mjs' import r_smartquotes from './rules_core/smartquotes.mjs' import r_text_join from './rules_core/text_join.mjs' - const _rules = [ ['normalize', r_normalize], ['block', r_block], @@ -29,7 +28,6 @@ const _rules = [ ['text_join', r_text_join] ] - /** * new Core() **/ @@ -46,7 +44,6 @@ function Core () { } } - /** * Core.process(state) * @@ -62,5 +59,4 @@ Core.prototype.process = function (state) { Core.prototype.State = StateCore - export default Core diff --git a/lib/parser_inline.mjs b/lib/parser_inline.mjs index cc3c337..c2cc6a1 100644 --- a/lib/parser_inline.mjs +++ b/lib/parser_inline.mjs @@ -23,7 +23,6 @@ import r_entity from './rules_inline/entity.mjs' import r_balance_pairs from './rules_inline/balance_pairs.mjs' import r_fragments_join from './rules_inline/fragments_join.mjs' - // Parser rules const _rules = [ @@ -55,7 +54,6 @@ const _rules2 = [ ['fragments_join', r_fragments_join] ] - /** * new ParserInline() **/ @@ -84,7 +82,6 @@ function ParserInline () { } } - // Skip single token by running all rules in validation mode; // returns `true` if any rule reported success // @@ -95,7 +92,6 @@ ParserInline.prototype.skipToken = function (state) { const maxNesting = state.md.options.maxNesting const cache = state.cache - if (typeof cache[pos] !== 'undefined') { state.pos = cache[pos] return @@ -137,7 +133,6 @@ ParserInline.prototype.skipToken = function (state) { cache[pos] = state.pos } - // Generate tokens for input range // ParserInline.prototype.tokenize = function (state) { @@ -179,7 +174,6 @@ ParserInline.prototype.tokenize = function (state) { } } - /** * ParserInline.parse(str, md, env, outTokens) * @@ -198,8 +192,6 @@ ParserInline.prototype.parse = function (str, md, env, outTokens) { } } - ParserInline.prototype.State = StateInline - export default ParserInline diff --git a/lib/renderer.mjs b/lib/renderer.mjs index bcd93ac..da4bc87 100644 --- a/lib/renderer.mjs +++ b/lib/renderer.mjs @@ -8,10 +8,8 @@ import { assign, unescapeAll, escapeHtml } from './common/utils.mjs' - const default_rules = {} - default_rules.code_inline = function (tokens, idx, options, env, slf) { const token = tokens[idx] @@ -20,7 +18,6 @@ default_rules.code_inline = function (tokens, idx, options, env, slf) { '' } - default_rules.code_block = function (tokens, idx, options, env, slf) { const token = tokens[idx] @@ -29,7 +26,6 @@ default_rules.code_block = function (tokens, idx, options, env, slf) { '\n' } - default_rules.fence = function (tokens, idx, options, env, slf) { const token = tokens[idx] const info = token.info ? unescapeAll(token.info).trim() : '' @@ -78,7 +74,6 @@ default_rules.fence = function (tokens, idx, options, env, slf) { return `
${highlighted}
\n`
}
-
default_rules.image = function (tokens, idx, options, env, slf) {
const token = tokens[idx]
@@ -93,7 +88,6 @@ default_rules.image = function (tokens, idx, options, env, slf) {
return slf.renderToken(tokens, idx, options)
}
-
default_rules.hardbreak = function (tokens, idx, options /*, env */) {
return options.xhtmlOut ? '' +
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
'
'
-
} else if (lang === 'auto') {
-
const result = hljs.highlightAuto(str)
/* eslint-disable no-console */
@@ -114,7 +110,6 @@ function mdInit () {
return window.twemoji.parse(token[idx].content)
}
-
//
// Inject line numbers for sync scroll. Notes:
//
@@ -148,14 +143,12 @@ function updateResult () {
// (debug & src view with highlighting are a bit slow)
if (defaults._view === 'src') {
setHighlightedlContent('.result-src-content', mdSrc.render(source), 'html')
-
} else if (defaults._view === 'debug') {
setHighlightedlContent(
'.result-debug-content',
JSON.stringify(mdSrc.parse(source, { references: {} }), null, 2),
'json'
)
-
} else { /* defaults._view === 'html' */
$('.result-html').html(mdHtml.render(source))
}
@@ -294,24 +287,18 @@ const syncSrcScroll = _.debounce(function () {
}, 100, 'linear')
}, 50, { maxWait: 50 })
-
function loadPermalink () {
-
if (!location.hash) { return }
let cfg
try {
-
if (/^#md3=/.test(location.hash)) {
cfg = JSON.parse(mdurl.decode(location.hash.slice(5), mdurl.decode.componentChars))
-
} else if (/^#md64=/.test(location.hash)) {
cfg = JSON.parse(window.atob(location.hash.slice(6)))
-
} else if (/^#md=/.test(location.hash)) {
cfg = JSON.parse(decodeURIComponent(location.hash.slice(4)))
-
} else {
return
}
@@ -348,7 +335,6 @@ function loadPermalink () {
}
}
-
// Init on page load
//
$(function () {
@@ -384,7 +370,6 @@ $(function () {
updateResult()
})
setOptionClass(key, val)
-
} else {
$(el).val(val)
$el.on('change update keyup', function () {
diff --git a/support/specsplit.mjs b/support/specsplit.mjs
index a2e8a51..3e2dbe6 100755
--- a/support/specsplit.mjs
+++ b/support/specsplit.mjs
@@ -8,7 +8,6 @@ import fs from 'node:fs'
import argparse from 'argparse'
import markdownit from '../index.mjs'
-
const cli = new argparse.ArgumentParser({
add_help: true
})
@@ -31,12 +30,10 @@ cli.add_argument('-o', '--output', {
const options = cli.parse_args()
-
function normalize (text) {
return text.replace(/\n<\/blockquote>/g, '') } - function readFile (filename, encoding, callback) { if (options.file === '-') { // read from stdin @@ -55,7 +52,6 @@ function readFile (filename, encoding, callback) { } } - readFile(options.spec, 'utf8', function (error, input) { const good = [] const bad = [] diff --git a/test/babelmark-responder.mjs b/test/babelmark-responder.mjs index 4677dd2..47411e2 100644 --- a/test/babelmark-responder.mjs +++ b/test/babelmark-responder.mjs @@ -3,7 +3,6 @@ import { execFile } from 'child_process' import { readFileSync } from 'fs' import { setTimeout as sleep } from 'node:timers/promises' - describe('babelmark responder app', function () { let app @@ -30,7 +29,6 @@ describe('babelmark responder app', function () { } }) - it('ping root', () => { return request .get('/') @@ -38,7 +36,6 @@ describe('babelmark responder app', function () { .expect(//i) }) - it('do request', () => { const version = JSON.parse(readFileSync(new URL('../package.json', import.meta.url))).version @@ -52,7 +49,6 @@ describe('babelmark responder app', function () { }) }) - after(() => { if (app) app.kill() }) diff --git a/test/commonmark.mjs b/test/commonmark.mjs index e45c6e3..af2caed 100644 --- a/test/commonmark.mjs +++ b/test/commonmark.mjs @@ -4,12 +4,10 @@ import { load } from 'markdown-it-testgen' import markdownit from '../index.mjs' import { assert } from 'chai' - function normalize (text) { return text.replace(/\n<\/blockquote>/g, '') } - function generate (path, md) { load(path, function (data) { data.meta = data.meta || {} @@ -26,7 +24,6 @@ function generate (path, md) { }) } - describe('CommonMark', function () { const md = markdownit('commonmark') diff --git a/test/markdown-it.mjs b/test/markdown-it.mjs index 301d246..66b34b4 100644 --- a/test/markdown-it.mjs +++ b/test/markdown-it.mjs @@ -2,7 +2,6 @@ import { fileURLToPath } from 'node:url' import generate from 'markdown-it-testgen' import markdownit from '../index.mjs' - describe('markdown-it', function () { const md = markdownit({ html: true, diff --git a/test/misc.mjs b/test/misc.mjs index 67aef87..9c297e9 100644 --- a/test/misc.mjs +++ b/test/misc.mjs @@ -2,9 +2,7 @@ import { assert } from 'chai' import markdownit from '../index.mjs' import forInline from 'markdown-it-for-inline' - describe('API', function () { - it('constructor', function () { assert.throws(function () { markdownit('bad preset') @@ -163,12 +161,9 @@ describe('API', function () { /Input data should be a String/ ) }) - }) - describe('Plugins', function () { - it('should not loop infinitely if all rules are disabled', function () { const md = markdownit() @@ -205,9 +200,7 @@ describe('Plugins', function () { }) }) - describe('Misc', function () { - it('Should replace NULL characters', function () { const md = markdownit() @@ -301,9 +294,7 @@ describe('Misc', function () { }) }) - describe('Url normalization', function () { - it('Should be overridable', function () { const md = markdownit({ linkify: true }) @@ -323,12 +314,9 @@ describe('Url normalization', function () { assert.strictEqual(md.render('[test](http://example.com)'), '\n') assert.strictEqual(md.render('![test](http://example.com)'), '\n') }) - }) - describe('Links validation', function () { - it('Override validator, disable everything', function () { const md = markdownit({ linkify: true }) @@ -341,12 +329,9 @@ describe('Links validation', function () { assert.strictEqual(md.render('[test](http://example.com)'), '[test](http://example.com)
\n') assert.strictEqual(md.render('![test](http://example.com)'), '![test](http://example.com)
\n') }) - }) - describe('maxNesting', function () { - it('Block parser should not nest above limit', function () { const md = markdownit({ maxNesting: 2 }) assert.strictEqual( @@ -370,10 +355,8 @@ describe('maxNesting', function () { '[[[[[[[[[[[[[[[[[[foo]()
\n' ) }) - }) - describe('smartquotes', function () { const md = markdownit({ typographer: true, @@ -403,10 +386,8 @@ describe('smartquotes', function () { '[[[a b (((((c d e)))) f g]]
\n' ) }) - }) - describe('Ordered list info', function () { const md = markdownit() @@ -441,7 +422,6 @@ describe('Ordered list info', function () { }) }) - describe('Token attributes', function () { it('.attrJoin', function () { const md = markdownit() diff --git a/test/pathological.mjs b/test/pathological.mjs index 8c1731c..d9f8591 100644 --- a/test/pathological.mjs +++ b/test/pathological.mjs @@ -4,7 +4,6 @@ import crypto from 'node:crypto' import { Worker as JestWorker } from 'jest-worker' import { readFileSync } from 'fs' - async function test_pattern (str) { const worker = new JestWorker( new URL('./pathological_worker.js', import.meta.url), @@ -32,9 +31,7 @@ async function test_pattern (str) { return result } - describe('Pathological sequences speed', () => { - it('Integrity check', async () => { assert.strictEqual( await test_pattern('foo'), @@ -44,7 +41,6 @@ describe('Pathological sequences speed', () => { // Ported from cmark, https://github.com/commonmark/cmark/blob/master/test/pathological_tests.py describe('Cmark', () => { - it('verify original source crc', async () => { /* eslint-disable max-len */ const src = await needle('get', 'https://raw.githubusercontent.com/commonmark/cmark/master/test/pathological_tests.py') diff --git a/test/ruler.mjs b/test/ruler.mjs index a261307..e47d001 100644 --- a/test/ruler.mjs +++ b/test/ruler.mjs @@ -2,7 +2,6 @@ import { assert } from 'chai' import Ruler from '../lib/ruler.mjs' describe('Ruler', function () { - it('should replace rule (.at)', function () { const ruler = new Ruler() let res = 0 @@ -17,7 +16,6 @@ describe('Ruler', function () { assert.strictEqual(res, 2) }) - it('should inject before/after rule', function () { const ruler = new Ruler() let res = 0 @@ -37,7 +35,6 @@ describe('Ruler', function () { assert.strictEqual(res, 10) }) - it('should enable/disable rule', function () { const ruler = new Ruler() let rules @@ -63,7 +60,6 @@ describe('Ruler', function () { assert.strictEqual(rules.length, 2) }) - it('should enable/disable multiple rule', function () { const ruler = new Ruler() let rules @@ -79,7 +75,6 @@ describe('Ruler', function () { assert.strictEqual(rules.length, 2) }) - it('should enable rules by whitelist', function () { const ruler = new Ruler() @@ -91,7 +86,6 @@ describe('Ruler', function () { assert.strictEqual(rules.length, 1) }) - it('should support multiple chains', function () { const ruler = new Ruler() let rules @@ -108,7 +102,6 @@ describe('Ruler', function () { assert.strictEqual(rules.length, 1) }) - it('should fail on invalid rule name', function () { const ruler = new Ruler() @@ -131,7 +124,6 @@ describe('Ruler', function () { }) }) - it('should not fail on invalid rule name in silent mode', function () { const ruler = new Ruler() @@ -147,5 +139,4 @@ describe('Ruler', function () { ruler.disable('invalid name', true) }) }) - }) diff --git a/test/token.mjs b/test/token.mjs index 87c4896..47dd951 100644 --- a/test/token.mjs +++ b/test/token.mjs @@ -1,9 +1,7 @@ import { assert } from 'chai' import Token from '../lib/token.mjs' - describe('Token', function () { - it('attr', function () { const t = new Token('test_token', 'tok', 1) @@ -17,5 +15,4 @@ describe('Token', function () { assert.equal(t.attrIndex('baz'), 1) assert.equal(t.attrIndex('none'), -1) }) - }) diff --git a/test/utils.mjs b/test/utils.mjs index 38e7c6f..ba78d2f 100644 --- a/test/utils.mjs +++ b/test/utils.mjs @@ -1,9 +1,7 @@ import { assert } from 'chai' import * as utils from '../lib/common/utils.mjs' - describe('Utils', function () { - it('fromCodePoint', function () { const fromCodePoint = utils.fromCodePoint @@ -81,5 +79,4 @@ describe('Utils', function () { assert.strictEqual(unescapeMd('\\' + ch), ch) }) }) - })