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 ? '
\n' : '
\n' } @@ -101,12 +95,10 @@ default_rules.softbreak = function (tokens, idx, options /*, env */) { return options.breaks ? (options.xhtmlOut ? '
\n' : '
\n') : '\n' } - default_rules.text = function (tokens, idx /*, options, env */) { return escapeHtml(tokens[idx].content) } - default_rules.html_block = function (tokens, idx /*, options, env */) { return tokens[idx].content } @@ -114,14 +106,12 @@ default_rules.html_inline = function (tokens, idx /*, options, env */) { return tokens[idx].content } - /** * new Renderer() * * Creates new [[Renderer]] instance and fill [[Renderer#rules]] with defaults. **/ function Renderer () { - /** * Renderer#rules -> Object * @@ -153,7 +143,6 @@ function Renderer () { this.rules = assign({}, default_rules) } - /** * Renderer.renderAttrs(token) -> String * @@ -173,7 +162,6 @@ Renderer.prototype.renderAttrs = function renderAttrs (token) { return result } - /** * Renderer.renderToken(tokens, idx, options) -> String * - tokens (Array): list of tokens @@ -227,7 +215,6 @@ Renderer.prototype.renderToken = function renderToken (tokens, idx, options) { // Block-level tag containing an inline tag. // needLf = false - } else if (nextToken.nesting === -1 && nextToken.tag === token.tag) { // Opening tag + closing tag of the same type. E.g. `
  • `. // @@ -242,7 +229,6 @@ Renderer.prototype.renderToken = function renderToken (tokens, idx, options) { return result } - /** * Renderer.renderInline(tokens, options, env) -> String * - tokens (Array): list on block tokens to render @@ -268,7 +254,6 @@ Renderer.prototype.renderInline = function (tokens, options, env) { return result } - /** internal * Renderer.renderInlineAsText(tokens, options, env) -> String * - tokens (Array): list on block tokens to render @@ -295,7 +280,6 @@ Renderer.prototype.renderInlineAsText = function (tokens, options, env) { return result } - /** * Renderer.render(tokens, options, env) -> String * - tokens (Array): list on block tokens to render diff --git a/lib/ruler.mjs b/lib/ruler.mjs index 72f00a7..92c98e9 100644 --- a/lib/ruler.mjs +++ b/lib/ruler.mjs @@ -16,7 +16,6 @@ * [[MarkdownIt.use]]. **/ - /** * new Ruler() **/ @@ -40,10 +39,8 @@ function Ruler () { this.__cache__ = null } - // Helper methods, should not be used directly - // Find rule index by name // Ruler.prototype.__find__ = function (name) { @@ -55,7 +52,6 @@ Ruler.prototype.__find__ = function (name) { return -1 } - // Build rules lookup cache // Ruler.prototype.__compile__ = function () { @@ -87,7 +83,6 @@ Ruler.prototype.__compile__ = function () { }) } - /** * Ruler.at(name, fn [, options]) * - name (String): rule name to replace. @@ -124,7 +119,6 @@ Ruler.prototype.at = function (name, fn, options) { this.__cache__ = null } - /** * Ruler.before(beforeName, ruleName, fn [, options]) * - beforeName (String): new rule will be added before this one. @@ -165,7 +159,6 @@ Ruler.prototype.before = function (beforeName, ruleName, fn, options) { this.__cache__ = null } - /** * Ruler.after(afterName, ruleName, fn [, options]) * - afterName (String): new rule will be added after this one. @@ -242,7 +235,6 @@ Ruler.prototype.push = function (ruleName, fn, options) { this.__cache__ = null } - /** * Ruler.enable(list [, ignoreInvalid]) -> Array * - list (String|Array): list of rule names to enable. @@ -276,7 +268,6 @@ Ruler.prototype.enable = function (list, ignoreInvalid) { return result } - /** * Ruler.enableOnly(list [, ignoreInvalid]) * - list (String|Array): list of rule names to enable (whitelist). @@ -295,7 +286,6 @@ Ruler.prototype.enableOnly = function (list, ignoreInvalid) { this.enable(list, ignoreInvalid) } - /** * Ruler.disable(list [, ignoreInvalid]) -> Array * - list (String|Array): list of rule names to disable. @@ -329,7 +319,6 @@ Ruler.prototype.disable = function (list, ignoreInvalid) { return result } - /** * Ruler.getRules(chainName) -> Array * diff --git a/lib/rules_block/html_block.mjs b/lib/rules_block/html_block.mjs index 69435f0..197520f 100644 --- a/lib/rules_block/html_block.mjs +++ b/lib/rules_block/html_block.mjs @@ -16,7 +16,6 @@ const HTML_SEQUENCES = [ [new RegExp(HTML_OPEN_CLOSE_TAG_RE.source + '\\s*$'), /^$/, false] ] - export default function html_block (state, startLine, endLine, silent) { let pos = state.bMarks[startLine] + state.tShift[startLine] let max = state.eMarks[startLine] diff --git a/lib/rules_block/list.mjs b/lib/rules_block/list.mjs index 4d96ab7..fb53abd 100644 --- a/lib/rules_block/list.mjs +++ b/lib/rules_block/list.mjs @@ -49,7 +49,6 @@ function skipOrderedListMarker (state, startLine) { ch = state.src.charCodeAt(pos++) if (ch >= 0x30/* 0 */ && ch <= 0x39/* 9 */) { - // List marker should have no more than 9 digits // (prevents integer overflow in browsers) if (pos - start >= 10) { return -1 } @@ -88,7 +87,6 @@ function markTightParagraphs (state, idx) { } } - export default function list (state, startLine, endLine, silent) { let max, pos, start, token let nextLine = startLine @@ -136,10 +134,8 @@ export default function list (state, startLine, endLine, silent) { // If we're starting a new ordered list right after // a paragraph, it should start with 1. if (isTerminatingParagraph && markerValue !== 1) return false - } else if ((posAfterMarker = skipBulletListMarker(state, nextLine)) >= 0) { isOrdered = false - } else { return false } @@ -164,7 +160,6 @@ export default function list (state, startLine, endLine, silent) { if (markerValue !== 1) { token.attrs = [['start', markerValue]] } - } else { token = state.push('bullet_list_open', 'ul', 1) } diff --git a/lib/rules_block/state_block.mjs b/lib/rules_block/state_block.mjs index 5d2ce9d..3c2a876 100644 --- a/lib/rules_block/state_block.mjs +++ b/lib/rules_block/state_block.mjs @@ -3,7 +3,6 @@ import Token from '../token.mjs' import { isSpace } from '../common/utils.mjs' - function StateBlock (src, md, env, tokens) { this.src = src @@ -218,5 +217,4 @@ StateBlock.prototype.getLines = function getLines (begin, end, indent, keepLastL // re-export Token class to use in block rules StateBlock.prototype.Token = Token - export default StateBlock diff --git a/lib/rules_block/table.mjs b/lib/rules_block/table.mjs index bf8e8c7..6ec66b1 100644 --- a/lib/rules_block/table.mjs +++ b/lib/rules_block/table.mjs @@ -44,7 +44,6 @@ function escapedSplit (str) { return result } - export default function table (state, startLine, endLine, silent) { // should have at least two lines if (startLine + 2 > endLine) { return false } diff --git a/lib/rules_core/linkify.mjs b/lib/rules_core/linkify.mjs index 85e6b82..a225280 100644 --- a/lib/rules_core/linkify.mjs +++ b/lib/rules_core/linkify.mjs @@ -5,7 +5,6 @@ import { arrayReplaceAt } from '../common/utils.mjs' - function isLinkOpen (str) { return /^\s]/i.test(str) } @@ -13,7 +12,6 @@ function isLinkClose (str) { return /^<\/a\s*>/i.test(str) } - export default function linkify (state) { const blockTokens = state.tokens @@ -55,7 +53,6 @@ export default function linkify (state) { if (htmlLinkLevel > 0) { continue } if (currentToken.type === 'text' && state.md.linkify.test(currentToken.content)) { - const text = currentToken.content let links = state.md.linkify.match(text) diff --git a/lib/rules_core/normalize.mjs b/lib/rules_core/normalize.mjs index 9f1b88d..dfb67ef 100644 --- a/lib/rules_core/normalize.mjs +++ b/lib/rules_core/normalize.mjs @@ -1,11 +1,9 @@ // Normalize input string - // https://spec.commonmark.org/0.29/#line-ending const NEWLINES_RE = /\r\n?|\n/g const NULL_RE = /\0/g - export default function normalize (state) { let str diff --git a/lib/rules_core/replacements.mjs b/lib/rules_core/replacements.mjs index 8695757..b18ecd9 100644 --- a/lib/rules_core/replacements.mjs +++ b/lib/rules_core/replacements.mjs @@ -82,14 +82,12 @@ function replace_rare (inlineTokens) { } } - export default function replace (state) { let blkIdx if (!state.md.options.typographer) { return } for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { - if (state.tokens[blkIdx].type !== 'inline') { continue } if (SCOPED_ABBR_TEST_RE.test(state.tokens[blkIdx].content)) { @@ -99,6 +97,5 @@ export default function replace (state) { if (RARE_RE.test(state.tokens[blkIdx].content)) { replace_rare(state.tokens[blkIdx].children) } - } } diff --git a/lib/rules_core/smartquotes.mjs b/lib/rules_core/smartquotes.mjs index 8426e71..3b990ed 100644 --- a/lib/rules_core/smartquotes.mjs +++ b/lib/rules_core/smartquotes.mjs @@ -7,7 +7,6 @@ const QUOTE_TEST_RE = /['"]/ const QUOTE_RE = /['"]/g const APOSTROPHE = '\u2019' /* ’ */ - function replaceAt (str, index, ch) { return str.slice(0, index) + ch + str.slice(index + 1) } @@ -179,13 +178,11 @@ function process_inlines (tokens, state) { } } - export default function smartquotes (state) { /* eslint max-depth:0 */ if (!state.md.options.typographer) { return } for (let blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { - if (state.tokens[blkIdx].type !== 'inline' || !QUOTE_TEST_RE.test(state.tokens[blkIdx].content)) { continue diff --git a/lib/rules_core/state_core.mjs b/lib/rules_core/state_core.mjs index 655604c..a96c8fb 100644 --- a/lib/rules_core/state_core.mjs +++ b/lib/rules_core/state_core.mjs @@ -14,5 +14,4 @@ function StateCore (src, md, env) { // re-export Token class to use in core rules StateCore.prototype.Token = Token - export default StateCore diff --git a/lib/rules_core/text_join.mjs b/lib/rules_core/text_join.mjs index 288c05e..ee8f872 100644 --- a/lib/rules_core/text_join.mjs +++ b/lib/rules_core/text_join.mjs @@ -27,7 +27,6 @@ export default function text_join (state) { if (tokens[curr].type === 'text' && curr + 1 < max && tokens[curr + 1].type === 'text') { - // collapse two adjacent text nodes tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content } else { diff --git a/lib/rules_inline/autolink.mjs b/lib/rules_inline/autolink.mjs index f2894cd..e71e66f 100644 --- a/lib/rules_inline/autolink.mjs +++ b/lib/rules_inline/autolink.mjs @@ -5,7 +5,6 @@ const EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9 /* eslint-disable-next-line no-control-regex */ const AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.-]{1,31}):([^<>\x00-\x20]*)$/ - export default function autolink (state, silent) { let pos = state.pos diff --git a/lib/rules_inline/balance_pairs.mjs b/lib/rules_inline/balance_pairs.mjs index bc74606..8638d21 100644 --- a/lib/rules_inline/balance_pairs.mjs +++ b/lib/rules_inline/balance_pairs.mjs @@ -56,7 +56,6 @@ function processDelimiters (delimiters) { if (opener.marker !== closer.marker) continue if (opener.open && opener.end < 0) { - let isOddMatch = false // from spec: @@ -111,7 +110,6 @@ function processDelimiters (delimiters) { } } - export default function link_pairs (state) { const tokens_meta = state.tokens_meta const max = state.tokens_meta.length diff --git a/lib/rules_inline/emphasis.mjs b/lib/rules_inline/emphasis.mjs index 16b1bb5..f259255 100644 --- a/lib/rules_inline/emphasis.mjs +++ b/lib/rules_inline/emphasis.mjs @@ -48,7 +48,6 @@ function emphasis_tokenize (state, silent) { return true } - function postProcess (state, delimiters) { const max = delimiters.length @@ -103,7 +102,6 @@ function postProcess (state, delimiters) { } } - // Walk through delimiter list and replace text tokens with tags // function emphasis_post_process (state) { diff --git a/lib/rules_inline/entity.mjs b/lib/rules_inline/entity.mjs index 2ef149d..e65191d 100644 --- a/lib/rules_inline/entity.mjs +++ b/lib/rules_inline/entity.mjs @@ -3,11 +3,9 @@ import { decodeHTML } from 'entities' import { isValidEntityCode, fromCodePoint } from '../common/utils.mjs' - const DIGITAL_RE = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i const NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i - export default function entity (state, silent) { const pos = state.pos const max = state.posMax diff --git a/lib/rules_inline/escape.mjs b/lib/rules_inline/escape.mjs index c63ee5d..aa3728e 100644 --- a/lib/rules_inline/escape.mjs +++ b/lib/rules_inline/escape.mjs @@ -9,7 +9,6 @@ for (let i = 0; i < 256; i++) { ESCAPED.push(0) } '\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-' .split('').forEach(function (ch) { ESCAPED[ch.charCodeAt(0)] = 1 }) - export default function escape (state, silent) { let pos = state.pos const max = state.posMax diff --git a/lib/rules_inline/fragments_join.mjs b/lib/rules_inline/fragments_join.mjs index 04e579d..e89ef9e 100644 --- a/lib/rules_inline/fragments_join.mjs +++ b/lib/rules_inline/fragments_join.mjs @@ -23,7 +23,6 @@ export default function fragments_join (state) { if (tokens[curr].type === 'text' && curr + 1 < max && tokens[curr + 1].type === 'text') { - // collapse two adjacent text nodes tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content } else { diff --git a/lib/rules_inline/html_inline.mjs b/lib/rules_inline/html_inline.mjs index f89b54f..256efad 100644 --- a/lib/rules_inline/html_inline.mjs +++ b/lib/rules_inline/html_inline.mjs @@ -2,7 +2,6 @@ import { HTML_TAG_RE } from '../common/html_re.mjs' - function isLinkOpen (str) { return /^\s]/i.test(str) } @@ -10,14 +9,12 @@ function isLinkClose (str) { return /^<\/a\s*>/i.test(str) } - function isLetter (ch) { /* eslint no-bitwise:0 */ const lc = ch | 0x20 // to lower case return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */) } - export default function html_inline (state, silent) { if (!state.md.options.html) { return false } diff --git a/lib/rules_inline/image.mjs b/lib/rules_inline/image.mjs index 31b0b3c..32cbb31 100644 --- a/lib/rules_inline/image.mjs +++ b/lib/rules_inline/image.mjs @@ -2,7 +2,6 @@ import { normalizeReference, isSpace } from '../common/utils.mjs' - export default function image (state, silent) { let code, content, label, pos, ref, res, title, start let href = '' diff --git a/lib/rules_inline/linkify.mjs b/lib/rules_inline/linkify.mjs index a2304ba..fdc817a 100644 --- a/lib/rules_inline/linkify.mjs +++ b/lib/rules_inline/linkify.mjs @@ -3,7 +3,6 @@ // RFC3986: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) const SCHEME_RE = /(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$/i - export default function linkify (state, silent) { if (!state.md.options.linkify) return false if (state.linkLevel > 0) return false diff --git a/lib/rules_inline/newline.mjs b/lib/rules_inline/newline.mjs index f20b904..2c0e3ae 100644 --- a/lib/rules_inline/newline.mjs +++ b/lib/rules_inline/newline.mjs @@ -27,7 +27,6 @@ export default function newline (state, silent) { state.pending = state.pending.slice(0, -1) state.push('softbreak', 'br', 0) } - } else { state.push('softbreak', 'br', 0) } diff --git a/lib/rules_inline/state_inline.mjs b/lib/rules_inline/state_inline.mjs index 4cb2554..86a72d7 100644 --- a/lib/rules_inline/state_inline.mjs +++ b/lib/rules_inline/state_inline.mjs @@ -35,7 +35,6 @@ function StateInline (src, md, env, outTokens) { this.linkLevel = 0 } - // Flush pending text // StateInline.prototype.pushPending = function () { @@ -47,7 +46,6 @@ StateInline.prototype.pushPending = function () { return token } - // Push new token to "stream". // If pending text exists - flush it as text token // @@ -81,7 +79,6 @@ StateInline.prototype.push = function (type, tag, nesting) { return token } - // Scan a sequence of emphasis-like markers, and determine whether // it can start an emphasis sequence or end an emphasis sequence. // @@ -139,9 +136,7 @@ StateInline.prototype.scanDelims = function (start, canSplitWord) { return { can_open, can_close, length: count } } - // re-export Token class to use in block rules StateInline.prototype.Token = Token - export default StateInline diff --git a/lib/rules_inline/strikethrough.mjs b/lib/rules_inline/strikethrough.mjs index fea8514..ec52e29 100644 --- a/lib/rules_inline/strikethrough.mjs +++ b/lib/rules_inline/strikethrough.mjs @@ -44,7 +44,6 @@ function strikethrough_tokenize (state, silent) { return true } - function postProcess (state, delimiters) { let token const loneMarkers = [] @@ -79,7 +78,6 @@ function postProcess (state, delimiters) { if (state.tokens[endDelim.token - 1].type === 'text' && state.tokens[endDelim.token - 1].content === '~') { - loneMarkers.push(endDelim.token - 1) } } @@ -108,7 +106,6 @@ function postProcess (state, delimiters) { } } - // Walk through delimiter list and replace text tokens with tags // function strikethrough_postProcess (state) { @@ -124,7 +121,6 @@ function strikethrough_postProcess (state) { } } - export default { tokenize: strikethrough_tokenize, postProcess: strikethrough_postProcess diff --git a/lib/token.mjs b/lib/token.mjs index 2b2de48..706ae1d 100644 --- a/lib/token.mjs +++ b/lib/token.mjs @@ -113,7 +113,6 @@ function Token (type, tag, nesting) { this.hidden = false } - /** * Token.attrIndex(name) -> Number * @@ -130,7 +129,6 @@ Token.prototype.attrIndex = function attrIndex (name) { return -1 } - /** * Token.attrPush(attrData) * @@ -144,7 +142,6 @@ Token.prototype.attrPush = function attrPush (attrData) { } } - /** * Token.attrSet(name, value) * @@ -161,7 +158,6 @@ Token.prototype.attrSet = function attrSet (name, value) { } } - /** * Token.attrGet(name) * @@ -176,7 +172,6 @@ Token.prototype.attrGet = function attrGet (name) { return value } - /** * Token.attrJoin(name, value) * @@ -193,5 +188,4 @@ Token.prototype.attrJoin = function attrJoin (name, value) { } } - export default Token diff --git a/support/demo_template/index.mjs b/support/demo_template/index.mjs index 486c2a3..0ba8bf1 100644 --- a/support/demo_template/index.mjs +++ b/support/demo_template/index.mjs @@ -15,7 +15,6 @@ import md_mark from 'markdown-it-mark' import md_sub from 'markdown-it-sub' import md_sup from 'markdown-it-sup' - let mdHtml, mdSrc, permalink, scrollMap const defaults = { @@ -41,13 +40,10 @@ defaults.highlight = function (str, lang) { } if (lang && lang !== 'auto' && hljs.getLanguage(lang)) { - return '
    ' +
                  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)'), '

    test

    \n') assert.strictEqual(md.render('![test](http://example.com)'), '

    test

    \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) }) }) - })