Browse Source

lint: reduce empty lines

pull/979/head
Vitaly Puzrin 5 months ago
parent
commit
8b815a6072
  1. 2
      .eslintrc.yml
  2. 2
      benchmark/benchmark.mjs
  3. 4
      bin/markdown-it.mjs
  4. 9
      lib/common/utils.mjs
  5. 1
      lib/helpers/parse_link_title.mjs
  6. 15
      lib/index.mjs
  7. 5
      lib/parser_block.mjs
  8. 4
      lib/parser_core.mjs
  9. 8
      lib/parser_inline.mjs
  10. 16
      lib/renderer.mjs
  11. 11
      lib/ruler.mjs
  12. 1
      lib/rules_block/html_block.mjs
  13. 5
      lib/rules_block/list.mjs
  14. 2
      lib/rules_block/state_block.mjs
  15. 1
      lib/rules_block/table.mjs
  16. 3
      lib/rules_core/linkify.mjs
  17. 2
      lib/rules_core/normalize.mjs
  18. 3
      lib/rules_core/replacements.mjs
  19. 3
      lib/rules_core/smartquotes.mjs
  20. 1
      lib/rules_core/state_core.mjs
  21. 1
      lib/rules_core/text_join.mjs
  22. 1
      lib/rules_inline/autolink.mjs
  23. 2
      lib/rules_inline/balance_pairs.mjs
  24. 2
      lib/rules_inline/emphasis.mjs
  25. 2
      lib/rules_inline/entity.mjs
  26. 1
      lib/rules_inline/escape.mjs
  27. 1
      lib/rules_inline/fragments_join.mjs
  28. 3
      lib/rules_inline/html_inline.mjs
  29. 1
      lib/rules_inline/image.mjs
  30. 1
      lib/rules_inline/linkify.mjs
  31. 1
      lib/rules_inline/newline.mjs
  32. 5
      lib/rules_inline/state_inline.mjs
  33. 4
      lib/rules_inline/strikethrough.mjs
  34. 6
      lib/token.mjs
  35. 15
      support/demo_template/index.mjs
  36. 4
      support/specsplit.mjs
  37. 4
      test/babelmark-responder.mjs
  38. 3
      test/commonmark.mjs
  39. 1
      test/markdown-it.mjs
  40. 20
      test/misc.mjs
  41. 4
      test/pathological.mjs
  42. 9
      test/ruler.mjs
  43. 3
      test/token.mjs
  44. 3
      test/utils.mjs

2
.eslintrc.yml

@ -21,5 +21,3 @@ rules:
camelcase: 0
key-spacing: 0
no-multi-spaces: 0
no-multiple-empty-lines: 0
padded-blocks: 0

2
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)

4
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) ||

9
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).

1
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

15
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

5
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

4
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

8
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

16
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) {
'</code>'
}
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) {
'</code></pre>\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 `<pre><code${slf.renderAttrs(token)}>${highlighted}</code></pre>\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 ? '<br />\n' : '<br>\n'
}
@ -101,12 +95,10 @@ default_rules.softbreak = function (tokens, idx, options /*, env */) {
return options.breaks ? (options.xhtmlOut ? '<br />\n' : '<br>\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. `<li></li>`.
//
@ -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

11
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
*

1
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]

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

2
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

1
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 }

3
lib/rules_core/linkify.mjs

@ -5,7 +5,6 @@
import { arrayReplaceAt } from '../common/utils.mjs'
function isLinkOpen (str) {
return /^<a[>\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)

2
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

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

3
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

1
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

1
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 {

1
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

2
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

2
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) {

2
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

1
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

1
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 {

3
lib/rules_inline/html_inline.mjs

@ -2,7 +2,6 @@
import { HTML_TAG_RE } from '../common/html_re.mjs'
function isLinkOpen (str) {
return /^<a[>\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 }

1
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 = ''

1
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

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

5
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

4
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

6
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

15
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 '<pre class="hljs language-' + esc(lang.toLowerCase()) + '"><code>' +
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
'</code></pre>'
} 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 () {

4
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(/<blockquote>\n<\/blockquote>/g, '<blockquote></blockquote>')
}
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 = []

4
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(/<!DOCTYPE html>/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()
})

3
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(/<blockquote>\n<\/blockquote>/g, '<blockquote></blockquote>')
}
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')

1
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,

20
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)'), '<p><a href="LINK">test</a></p>\n')
assert.strictEqual(md.render('![test](http://example.com)'), '<p><img src="LINK" alt="test"></p>\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)'), '<p>[test](http://example.com)</p>\n')
assert.strictEqual(md.render('![test](http://example.com)'), '<p>![test](http://example.com)</p>\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 () {
'<p>[[[[[[[[[[[[[[[[[[foo]()</p>\n'
)
})
})
describe('smartquotes', function () {
const md = markdownit({
typographer: true,
@ -403,10 +386,8 @@ describe('smartquotes', function () {
'<p>[[[a <em>b (((((c <em>d</em> e)))) f</em> g]]</p>\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()

4
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')

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

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

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

Loading…
Cancel
Save