Browse Source

standard: space before function params

pull/979/head
Vitaly Puzrin 1 year ago
parent
commit
0eb4cb96a4
  1. 2
      .eslintrc.yml
  2. 10
      benchmark/benchmark.mjs
  3. 2
      benchmark/implementations/commonmark-reference/index.mjs
  4. 2
      benchmark/implementations/current-commonmark/index.mjs
  5. 2
      benchmark/implementations/current/index.mjs
  6. 2
      benchmark/implementations/markdown-it-2.2.1-commonmark/index.mjs
  7. 2
      benchmark/implementations/marked/index.mjs
  8. 2
      bin/markdown-it.mjs
  9. 36
      lib/common/utils.mjs
  10. 2
      lib/helpers/parse_link_destination.mjs
  11. 2
      lib/helpers/parse_link_label.mjs
  12. 2
      lib/helpers/parse_link_title.mjs
  13. 8
      lib/index.mjs
  14. 2
      lib/parser_block.mjs
  15. 2
      lib/parser_core.mjs
  16. 2
      lib/parser_inline.mjs
  17. 6
      lib/renderer.mjs
  18. 2
      lib/ruler.mjs
  19. 2
      lib/rules_block/blockquote.mjs
  20. 2
      lib/rules_block/code.mjs
  21. 2
      lib/rules_block/fence.mjs
  22. 2
      lib/rules_block/heading.mjs
  23. 2
      lib/rules_block/hr.mjs
  24. 2
      lib/rules_block/html_block.mjs
  25. 2
      lib/rules_block/lheading.mjs
  26. 8
      lib/rules_block/list.mjs
  27. 2
      lib/rules_block/paragraph.mjs
  28. 2
      lib/rules_block/reference.mjs
  29. 16
      lib/rules_block/state_block.mjs
  30. 6
      lib/rules_block/table.mjs
  31. 2
      lib/rules_core/block.mjs
  32. 2
      lib/rules_core/inline.mjs
  33. 6
      lib/rules_core/linkify.mjs
  34. 2
      lib/rules_core/normalize.mjs
  35. 8
      lib/rules_core/replacements.mjs
  36. 6
      lib/rules_core/smartquotes.mjs
  37. 2
      lib/rules_core/state_core.mjs
  38. 2
      lib/rules_core/text_join.mjs
  39. 2
      lib/rules_inline/autolink.mjs
  40. 2
      lib/rules_inline/backticks.mjs
  41. 4
      lib/rules_inline/balance_pairs.mjs
  42. 6
      lib/rules_inline/emphasis.mjs
  43. 2
      lib/rules_inline/entity.mjs
  44. 2
      lib/rules_inline/escape.mjs
  45. 2
      lib/rules_inline/fragments_join.mjs
  46. 8
      lib/rules_inline/html_inline.mjs
  47. 2
      lib/rules_inline/image.mjs
  48. 2
      lib/rules_inline/link.mjs
  49. 2
      lib/rules_inline/linkify.mjs
  50. 2
      lib/rules_inline/newline.mjs
  51. 2
      lib/rules_inline/state_inline.mjs
  52. 6
      lib/rules_inline/strikethrough.mjs
  53. 4
      lib/rules_inline/text.mjs
  54. 12
      lib/token.mjs
  55. 2
      support/build_demo.mjs
  56. 16
      support/demo_template/index.mjs
  57. 2
      support/rollup.config.mjs
  58. 4
      support/specsplit.mjs
  59. 4
      test/commonmark.mjs
  60. 4
      test/misc.mjs
  61. 2
      test/pathological.mjs
  62. 38
      test/ruler.mjs

2
.eslintrc.yml

@ -147,7 +147,7 @@ rules:
#operator-linebreak: [ 2, after ]
semi: [ 2, never ]
semi-spacing: 2
space-before-function-paren: [ 2, { "anonymous": "always", "named": "never" } ]
space-before-function-paren: [2, always]
space-in-parens: [ 2, never ]
space-infix-ops: 2
space-unary-ops: 2

10
benchmark/benchmark.mjs

@ -33,7 +33,7 @@ fs.readdirSync(new URL('./samples', import.meta.url)).sort().forEach(sample => {
const title = `(${content.string.length} bytes)`
function onComplete() { cursor.write('\n') }
function onComplete () { cursor.write('\n') }
const suite = new Benchmark.Suite(
title,
@ -47,7 +47,7 @@ fs.readdirSync(new URL('./samples', import.meta.url)).sort().forEach(sample => {
suite.add(
impl.name,
{
onCycle: function onCycle(event) {
onCycle: function onCycle (event) {
cursor.horizontalAbsolute()
cursor.eraseLine()
cursor.write(' > ' + event.target)
@ -67,14 +67,14 @@ fs.readdirSync(new URL('./samples', import.meta.url)).sort().forEach(sample => {
})
function select(patterns) {
function select (patterns) {
const result = []
if (!(patterns instanceof Array)) {
patterns = [ patterns ]
}
function checkName(name) {
function checkName (name) {
return patterns.length === 0 || patterns.some(function (regexp) {
return regexp.test(name)
})
@ -90,7 +90,7 @@ function select(patterns) {
}
function run(files) {
function run (files) {
const selected = select(files)
if (selected.length > 0) {

2
benchmark/implementations/commonmark-reference/index.mjs

@ -6,6 +6,6 @@ const commonmark = require('../../extra/lib/node_modules/commonmark')
const parser = new commonmark.Parser()
const renderer = new commonmark.HtmlRenderer()
export function run(data) {
export function run (data) {
return renderer.render(parser.parse(data))
}

2
benchmark/implementations/current-commonmark/index.mjs

@ -9,6 +9,6 @@ const encode = md.utils.lib.mdurl.encode
md.normalizeLink = function (url) { return encode(url) }
md.normalizeLinkText = function (str) { return str }
export function run(data) {
export function run (data) {
return md.render(data)
}

2
benchmark/implementations/current/index.mjs

@ -6,6 +6,6 @@ const md = markdownit({
typographer: true
})
export function run(data) {
export function run (data) {
return md.render(data)
}

2
benchmark/implementations/markdown-it-2.2.1-commonmark/index.mjs

@ -5,6 +5,6 @@ const markdownit = require('../../extra/lib/node_modules/markdown-it')
const md = markdownit('commonmark')
export function run(data) {
export function run (data) {
return md.render(data)
}

2
benchmark/implementations/marked/index.mjs

@ -3,6 +3,6 @@ const require = createRequire(import.meta.url)
const marked = require('../../extra/lib/node_modules/marked')
export function run(data) {
export function run (data) {
return marked(data)
}

2
bin/markdown-it.mjs

@ -51,7 +51,7 @@ cli.add_argument('-o', '--output', {
const options = cli.parse_args()
function readFile(filename, encoding, callback) {
function readFile (filename, encoding, callback) {
if (options.file === '-') {
// read from stdin
const chunks = []

36
lib/common/utils.mjs

@ -6,19 +6,19 @@ import ucmicro from 'uc.micro'
import { decodeHTML } from 'entities'
import UNICODE_PUNCT_RE from 'uc.micro/categories/P/regex.js'
function _class(obj) { return Object.prototype.toString.call(obj) }
function _class (obj) { return Object.prototype.toString.call(obj) }
function isString(obj) { return _class(obj) === '[object String]' }
function isString (obj) { return _class(obj) === '[object String]' }
const _hasOwnProperty = Object.prototype.hasOwnProperty
function has(object, key) {
function has (object, key) {
return _hasOwnProperty.call(object, key)
}
// Merge objects
//
function assign(obj /*from1, from2, from3, ...*/) {
function assign (obj /*from1, from2, from3, ...*/) {
const sources = Array.prototype.slice.call(arguments, 1)
sources.forEach(function (source) {
@ -38,13 +38,13 @@ function assign(obj /*from1, from2, from3, ...*/) {
// Remove element from array and put another array at those position.
// Useful for some operations with tokens
function arrayReplaceAt(src, pos, newElements) {
function arrayReplaceAt (src, pos, newElements) {
return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1))
}
////////////////////////////////////////////////////////////////////////////////
function isValidEntityCode(c) {
function isValidEntityCode (c) {
/*eslint no-bitwise:0*/
// broken sequence
if (c >= 0xD800 && c <= 0xDFFF) { return false }
@ -61,7 +61,7 @@ function isValidEntityCode(c) {
return true
}
function fromCodePoint(c) {
function fromCodePoint (c) {
/*eslint no-bitwise:0*/
if (c > 0xffff) {
c -= 0x10000
@ -81,7 +81,7 @@ const UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.sourc
const DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i
function replaceEntityPattern(match, name) {
function replaceEntityPattern (match, name) {
if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) {
const code = name[1].toLowerCase() === 'x' ?
parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10)
@ -107,12 +107,12 @@ function replaceEntityPattern(match, name) {
return str.replace(ENTITY_RE, replaceEntityPattern);
}*/
function unescapeMd(str) {
function unescapeMd (str) {
if (str.indexOf('\\') < 0) { return str }
return str.replace(UNESCAPE_MD_RE, '$1')
}
function unescapeAll(str) {
function unescapeAll (str) {
if (str.indexOf('\\') < 0 && str.indexOf('&') < 0) { return str }
return str.replace(UNESCAPE_ALL_RE, function (match, escaped, entity) {
@ -132,11 +132,11 @@ const HTML_REPLACEMENTS = {
'"': '&quot;'
}
function replaceUnsafeChar(ch) {
function replaceUnsafeChar (ch) {
return HTML_REPLACEMENTS[ch]
}
function escapeHtml(str) {
function escapeHtml (str) {
if (HTML_ESCAPE_TEST_RE.test(str)) {
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar)
}
@ -147,13 +147,13 @@ function escapeHtml(str) {
const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g
function escapeRE(str) {
function escapeRE (str) {
return str.replace(REGEXP_ESCAPE_RE, '\\$&')
}
////////////////////////////////////////////////////////////////////////////////
function isSpace(code) {
function isSpace (code) {
switch (code) {
case 0x09:
case 0x20:
@ -163,7 +163,7 @@ function isSpace(code) {
}
// Zs (unicode class) || [\t\f\v\r\n]
function isWhiteSpace(code) {
function isWhiteSpace (code) {
if (code >= 0x2000 && code <= 0x200A) { return true }
switch (code) {
case 0x09: // \t
@ -187,7 +187,7 @@ function isWhiteSpace(code) {
/*eslint-disable max-len*/
// Currently without astral characters support.
function isPunctChar(ch) {
function isPunctChar (ch) {
return UNICODE_PUNCT_RE.test(ch)
}
@ -199,7 +199,7 @@ function isPunctChar(ch) {
//
// Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
//
function isMdAsciiPunct(ch) {
function isMdAsciiPunct (ch) {
switch (ch) {
case 0x21/* ! */:
case 0x22/* " */:
@ -241,7 +241,7 @@ function isMdAsciiPunct(ch) {
// Hepler to unify [reference labels].
//
function normalizeReference(str) {
function normalizeReference (str) {
// Trim and collapse whitespace
//
str = str.trim().replace(/\s+/g, ' ')

2
lib/helpers/parse_link_destination.mjs

@ -3,7 +3,7 @@
import { unescapeAll } from '../common/utils.mjs'
export default function parseLinkDestination(str, start, max) {
export default function parseLinkDestination (str, start, max) {
let code
let pos = start

2
lib/helpers/parse_link_label.mjs

@ -4,7 +4,7 @@
// returns the end of the label
//
export default function parseLinkLabel(state, start, disableNested) {
export default function parseLinkLabel (state, start, disableNested) {
let level, found, marker, prevPos
const max = state.posMax

2
lib/helpers/parse_link_title.mjs

@ -4,7 +4,7 @@
import { unescapeAll } from '../common/utils.mjs'
export default function parseLinkTitle(str, start, max) {
export default function parseLinkTitle (str, start, max) {
let code, marker
let lines = 0
let pos = start

8
lib/index.mjs

@ -32,7 +32,7 @@ const config = {
const BAD_PROTO_RE = /^(vbscript|javascript|file|data):/
const GOOD_DATA_RE = /^data:image\/(gif|png|jpeg|webp);/
function validateLink(url) {
function validateLink (url) {
// url should be normalized at this point, and existing entities are decoded
const str = url.trim().toLowerCase()
@ -44,7 +44,7 @@ function validateLink(url) {
const RECODE_HOSTNAME_FOR = [ 'http:', 'https:', 'mailto:' ]
function normalizeLink(url) {
function normalizeLink (url) {
const parsed = mdurl.parse(url, true)
if (parsed.hostname) {
@ -64,7 +64,7 @@ function normalizeLink(url) {
return mdurl.encode(mdurl.format(parsed))
}
function normalizeLinkText(url) {
function normalizeLinkText (url) {
const parsed = mdurl.parse(url, true)
if (parsed.hostname) {
@ -219,7 +219,7 @@ function normalizeLinkText(url) {
* ```
*
**/
function MarkdownIt(presetName, options) {
function MarkdownIt (presetName, options) {
if (!(this instanceof MarkdownIt)) {
return new MarkdownIt(presetName, options)
}

2
lib/parser_block.mjs

@ -39,7 +39,7 @@ const _rules = [
/**
* new ParserBlock()
**/
function ParserBlock() {
function ParserBlock () {
/**
* ParserBlock#ruler -> Ruler
*

2
lib/parser_core.mjs

@ -33,7 +33,7 @@ const _rules = [
/**
* new Core()
**/
function Core() {
function Core () {
/**
* Core#ruler -> Ruler
*

2
lib/parser_inline.mjs

@ -61,7 +61,7 @@ const _rules2 = [
/**
* new ParserInline()
**/
function ParserInline() {
function ParserInline () {
/**
* ParserInline#ruler -> Ruler
*

6
lib/renderer.mjs

@ -126,7 +126,7 @@ default_rules.html_inline = function (tokens, idx /*, options, env */) {
*
* Creates new [[Renderer]] instance and fill [[Renderer#rules]] with defaults.
**/
function Renderer() {
function Renderer () {
/**
* Renderer#rules -> Object
@ -165,7 +165,7 @@ function Renderer() {
*
* Render token attributes to string.
**/
Renderer.prototype.renderAttrs = function renderAttrs(token) {
Renderer.prototype.renderAttrs = function renderAttrs (token) {
let i, l, result
if (!token.attrs) { return '' }
@ -189,7 +189,7 @@ Renderer.prototype.renderAttrs = function renderAttrs(token) {
* Default token renderer. Can be overriden by custom function
* in [[Renderer#rules]].
**/
Renderer.prototype.renderToken = function renderToken(tokens, idx, options) {
Renderer.prototype.renderToken = function renderToken (tokens, idx, options) {
const token = tokens[idx]
let result = ''

2
lib/ruler.mjs

@ -20,7 +20,7 @@
/**
* new Ruler()
**/
function Ruler() {
function Ruler () {
// List of added rules. Each element is:
//
// {

2
lib/rules_block/blockquote.mjs

@ -2,7 +2,7 @@
import { isSpace } from '../common/utils.mjs'
export default function blockquote(state, startLine, endLine, silent) {
export default function blockquote (state, startLine, endLine, silent) {
let pos = state.bMarks[startLine] + state.tShift[startLine]
let max = state.eMarks[startLine]

2
lib/rules_block/code.mjs

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

2
lib/rules_block/fence.mjs

@ -1,6 +1,6 @@
// fences (``` lang, ~~~ lang)
export default function fence(state, startLine, endLine, silent) {
export default function fence (state, startLine, endLine, silent) {
let pos = state.bMarks[startLine] + state.tShift[startLine]
let max = state.eMarks[startLine]

2
lib/rules_block/heading.mjs

@ -2,7 +2,7 @@
import { isSpace } from '../common/utils.mjs'
export default function heading(state, startLine, endLine, silent) {
export default function heading (state, startLine, endLine, silent) {
let pos = state.bMarks[startLine] + state.tShift[startLine]
let max = state.eMarks[startLine]

2
lib/rules_block/hr.mjs

@ -2,7 +2,7 @@
import { isSpace } from '../common/utils.mjs'
export default function hr(state, startLine, endLine, silent) {
export default function hr (state, startLine, endLine, silent) {
const max = state.eMarks[startLine]
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false }

2
lib/rules_block/html_block.mjs

@ -17,7 +17,7 @@ const HTML_SEQUENCES = [
]
export default function html_block(state, startLine, endLine, silent) {
export default function html_block (state, startLine, endLine, silent) {
let pos = state.bMarks[startLine] + state.tShift[startLine]
let max = state.eMarks[startLine]

2
lib/rules_block/lheading.mjs

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

8
lib/rules_block/list.mjs

@ -4,7 +4,7 @@ import { isSpace } from '../common/utils.mjs'
// Search `[-+*][\n ]`, returns next pos after marker on success
// or -1 on fail.
function skipBulletListMarker(state, startLine) {
function skipBulletListMarker (state, startLine) {
const max = state.eMarks[startLine]
let pos = state.bMarks[startLine] + state.tShift[startLine]
@ -30,7 +30,7 @@ function skipBulletListMarker(state, startLine) {
// Search `\d+[.)][\n ]`, returns next pos after marker on success
// or -1 on fail.
function skipOrderedListMarker(state, startLine) {
function skipOrderedListMarker (state, startLine) {
const start = state.bMarks[startLine] + state.tShift[startLine]
const max = state.eMarks[startLine]
let pos = start
@ -76,7 +76,7 @@ function skipOrderedListMarker(state, startLine) {
return pos
}
function markTightParagraphs(state, idx) {
function markTightParagraphs (state, idx) {
const level = state.level + 2
for (let i = idx + 2, l = state.tokens.length - 2; i < l; i++) {
@ -89,7 +89,7 @@ function markTightParagraphs(state, idx) {
}
export default function list(state, startLine, endLine, silent) {
export default function list (state, startLine, endLine, silent) {
let max,
pos,
start,

2
lib/rules_block/paragraph.mjs

@ -1,6 +1,6 @@
// Paragraph
export default function paragraph(state, startLine, endLine) {
export default function paragraph (state, startLine, endLine) {
const terminatorRules = state.md.block.ruler.getRules('paragraph')
const oldParentType = state.parentType
let nextLine = startLine + 1

2
lib/rules_block/reference.mjs

@ -1,6 +1,6 @@
import { isSpace, normalizeReference } from '../common/utils.mjs'
export default function reference(state, startLine, _endLine, silent) {
export default function reference (state, startLine, _endLine, silent) {
let lines = 0
let pos = state.bMarks[startLine] + state.tShift[startLine]

16
lib/rules_block/state_block.mjs

@ -4,7 +4,7 @@ import Token from '../token.mjs'
import { isSpace } from '../common/utils.mjs'
function StateBlock(src, md, env, tokens) {
function StateBlock (src, md, env, tokens) {
this.src = src
// link to parser instance
@ -111,11 +111,11 @@ StateBlock.prototype.push = function (type, tag, nesting) {
return token
}
StateBlock.prototype.isEmpty = function isEmpty(line) {
StateBlock.prototype.isEmpty = function isEmpty (line) {
return this.bMarks[line] + this.tShift[line] >= this.eMarks[line]
}
StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) {
StateBlock.prototype.skipEmptyLines = function skipEmptyLines (from) {
for (let max = this.lineMax; from < max; from++) {
if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) {
break
@ -125,7 +125,7 @@ StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) {
}
// Skip spaces from given position.
StateBlock.prototype.skipSpaces = function skipSpaces(pos) {
StateBlock.prototype.skipSpaces = function skipSpaces (pos) {
for (let max = this.src.length; pos < max; pos++) {
const ch = this.src.charCodeAt(pos)
if (!isSpace(ch)) { break }
@ -134,7 +134,7 @@ StateBlock.prototype.skipSpaces = function skipSpaces(pos) {
}
// Skip spaces from given position in reverse.
StateBlock.prototype.skipSpacesBack = function skipSpacesBack(pos, min) {
StateBlock.prototype.skipSpacesBack = function skipSpacesBack (pos, min) {
if (pos <= min) { return pos }
while (pos > min) {
@ -144,7 +144,7 @@ StateBlock.prototype.skipSpacesBack = function skipSpacesBack(pos, min) {
}
// Skip char codes from given position
StateBlock.prototype.skipChars = function skipChars(pos, code) {
StateBlock.prototype.skipChars = function skipChars (pos, code) {
for (let max = this.src.length; pos < max; pos++) {
if (this.src.charCodeAt(pos) !== code) { break }
}
@ -152,7 +152,7 @@ StateBlock.prototype.skipChars = function skipChars(pos, code) {
}
// Skip char codes reverse from given position - 1
StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code, min) {
StateBlock.prototype.skipCharsBack = function skipCharsBack (pos, code, min) {
if (pos <= min) { return pos }
while (pos > min) {
@ -162,7 +162,7 @@ StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code, min) {
}
// cut lines range from source.
StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
StateBlock.prototype.getLines = function getLines (begin, end, indent, keepLastLF) {
if (begin >= end) {
return ''
}

6
lib/rules_block/table.mjs

@ -2,14 +2,14 @@
import { isSpace } from '../common/utils.mjs'
function getLine(state, line) {
function getLine (state, line) {
const pos = state.bMarks[line] + state.tShift[line],
max = state.eMarks[line]
return state.src.slice(pos, max)
}
function escapedSplit(str) {
function escapedSplit (str) {
const result = []
const max = str.length
@ -45,7 +45,7 @@ function escapedSplit(str) {
}
export default function table(state, startLine, endLine, silent) {
export default function table (state, startLine, endLine, silent) {
// should have at least two lines
if (startLine + 2 > endLine) { return false }

2
lib/rules_core/block.mjs

@ -1,4 +1,4 @@
export default function block(state) {
export default function block (state) {
let token
if (state.inlineMode) {

2
lib/rules_core/inline.mjs

@ -1,4 +1,4 @@
export default function inline(state) {
export default function inline (state) {
const tokens = state.tokens
// Parse inlines

6
lib/rules_core/linkify.mjs

@ -6,15 +6,15 @@
import { arrayReplaceAt } from '../common/utils.mjs'
function isLinkOpen(str) {
function isLinkOpen (str) {
return /^<a[>\s]/i.test(str)
}
function isLinkClose(str) {
function isLinkClose (str) {
return /^<\/a\s*>/i.test(str)
}
export default function linkify(state) {
export default function linkify (state) {
const blockTokens = state.tokens
if (!state.md.options.linkify) { return }

2
lib/rules_core/normalize.mjs

@ -6,7 +6,7 @@ const NEWLINES_RE = /\r\n?|\n/g
const NULL_RE = /\0/g
export default function normalize(state) {
export default function normalize (state) {
let str
// Normalize newlines

8
lib/rules_core/replacements.mjs

@ -26,11 +26,11 @@ const SCOPED_ABBR = {
tm: '™'
}
function replaceFn(match, name) {
function replaceFn (match, name) {
return SCOPED_ABBR[name.toLowerCase()]
}
function replace_scoped(inlineTokens) {
function replace_scoped (inlineTokens) {
let i, token, inside_autolink = 0
for (i = inlineTokens.length - 1; i >= 0; i--) {
@ -50,7 +50,7 @@ function replace_scoped(inlineTokens) {
}
}
function replace_rare(inlineTokens) {
function replace_rare (inlineTokens) {
let i, token, inside_autolink = 0
for (i = inlineTokens.length - 1; i >= 0; i--) {
@ -83,7 +83,7 @@ function replace_rare(inlineTokens) {
}
export default function replace(state) {
export default function replace (state) {
let blkIdx
if (!state.md.options.typographer) { return }

6
lib/rules_core/smartquotes.mjs

@ -8,11 +8,11 @@ const QUOTE_RE = /['"]/g
const APOSTROPHE = '\u2019' /* ’ */
function replaceAt(str, index, ch) {
function replaceAt (str, index, ch) {
return str.slice(0, index) + ch + str.slice(index + 1)
}
function process_inlines(tokens, state) {
function process_inlines (tokens, state) {
let j
const stack = []
@ -180,7 +180,7 @@ function process_inlines(tokens, state) {
}
export default function smartquotes(state) {
export default function smartquotes (state) {
/*eslint max-depth:0*/
if (!state.md.options.typographer) { return }

2
lib/rules_core/state_core.mjs

@ -3,7 +3,7 @@
import Token from '../token.mjs'
function StateCore(src, md, env) {
function StateCore (src, md, env) {
this.src = src
this.env = env
this.tokens = []

2
lib/rules_core/text_join.mjs

@ -6,7 +6,7 @@
// For example, `\:)` shouldn't be replaced with an emoji.
//
export default function text_join(state) {
export default function text_join (state) {
let curr, last
const blockTokens = state.tokens
const l = blockTokens.length

2
lib/rules_inline/autolink.mjs

@ -5,7 +5,7 @@ const EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-
const AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)$/
export default function autolink(state, silent) {
export default function autolink (state, silent) {
let pos = state.pos
if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false }

2
lib/rules_inline/backticks.mjs

@ -1,6 +1,6 @@
// Parse backticks
export default function backtick(state, silent) {
export default function backtick (state, silent) {
let pos = state.pos
const ch = state.src.charCodeAt(pos)

4
lib/rules_inline/balance_pairs.mjs

@ -1,7 +1,7 @@
// For each opening emphasis-like marker find a matching closing one
//
function processDelimiters(delimiters) {
function processDelimiters (delimiters) {
const openersBottom = {}
const max = delimiters.length
@ -111,7 +111,7 @@ function processDelimiters(delimiters) {
}
export default function link_pairs(state) {
export default function link_pairs (state) {
const tokens_meta = state.tokens_meta
const max = state.tokens_meta.length

6
lib/rules_inline/emphasis.mjs

@ -3,7 +3,7 @@
// Insert each marker as a separate text token, and add it to delimiter list
//
function emphasis_tokenize(state, silent) {
function emphasis_tokenize (state, silent) {
const start = state.pos
const marker = state.src.charCodeAt(start)
@ -49,7 +49,7 @@ function emphasis_tokenize(state, silent) {
}
function postProcess(state, delimiters) {
function postProcess (state, delimiters) {
const max = delimiters.length
for (let i = max - 1; i >= 0; i--) {
@ -106,7 +106,7 @@ function postProcess(state, delimiters) {
// Walk through delimiter list and replace text tokens with tags
//
function emphasis_post_process(state) {
function emphasis_post_process (state) {
const tokens_meta = state.tokens_meta
const max = state.tokens_meta.length

2
lib/rules_inline/entity.mjs

@ -8,7 +8,7 @@ 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) {
export default function entity (state, silent) {
const pos = state.pos
const max = state.posMax

2
lib/rules_inline/escape.mjs

@ -10,7 +10,7 @@ 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) {
export default function escape (state, silent) {
let pos = state.pos
const max = state.posMax

2
lib/rules_inline/fragments_join.mjs

@ -7,7 +7,7 @@
// into opening/closing tags (which messes up levels inside).
//
export default function fragments_join(state) {
export default function fragments_join (state) {
let curr, last,
level = 0
const tokens = state.tokens

8
lib/rules_inline/html_inline.mjs

@ -3,22 +3,22 @@
import { HTML_TAG_RE } from '../common/html_re.mjs'
function isLinkOpen(str) {
function isLinkOpen (str) {
return /^<a[>\s]/i.test(str)
}
function isLinkClose(str) {
function isLinkClose (str) {
return /^<\/a\s*>/i.test(str)
}
function isLetter(ch) {
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) {
export default function html_inline (state, silent) {
if (!state.md.options.html) { return false }
// Check start

2
lib/rules_inline/image.mjs

@ -3,7 +3,7 @@
import { normalizeReference, isSpace } from '../common/utils.mjs'
export default function image(state, silent) {
export default function image (state, silent) {
let code,
content,
label,

2
lib/rules_inline/link.mjs

@ -2,7 +2,7 @@
import { normalizeReference, isSpace } from '../common/utils.mjs'
export default function link(state, silent) {
export default function link (state, silent) {
let code,
label,
res,

2
lib/rules_inline/linkify.mjs

@ -4,7 +4,7 @@
const SCHEME_RE = /(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$/i
export default function linkify(state, silent) {
export default function linkify (state, silent) {
if (!state.md.options.linkify) return false
if (state.linkLevel > 0) return false

2
lib/rules_inline/newline.mjs

@ -2,7 +2,7 @@
import { isSpace } from '../common/utils.mjs'
export default function newline(state, silent) {
export default function newline (state, silent) {
let pos = state.pos
if (state.src.charCodeAt(pos) !== 0x0A/* \n */) { return false }

2
lib/rules_inline/state_inline.mjs

@ -3,7 +3,7 @@
import Token from '../token.mjs'
import { isWhiteSpace, isPunctChar, isMdAsciiPunct } from '../common/utils.mjs'
function StateInline(src, md, env, outTokens) {
function StateInline (src, md, env, outTokens) {
this.src = src
this.env = env
this.md = md

6
lib/rules_inline/strikethrough.mjs

@ -3,7 +3,7 @@
// Insert each marker as a separate text token, and add it to delimiter list
//
function strikethrough_tokenize(state, silent) {
function strikethrough_tokenize (state, silent) {
const start = state.pos
const marker = state.src.charCodeAt(start)
@ -45,7 +45,7 @@ function strikethrough_tokenize(state, silent) {
}
function postProcess(state, delimiters) {
function postProcess (state, delimiters) {
let token
const loneMarkers = []
const max = delimiters.length
@ -111,7 +111,7 @@ function postProcess(state, delimiters) {
// Walk through delimiter list and replace text tokens with tags
//
function strikethrough_postProcess(state) {
function strikethrough_postProcess (state) {
const tokens_meta = state.tokens_meta
const max = state.tokens_meta.length

4
lib/rules_inline/text.mjs

@ -8,7 +8,7 @@
// !!!! Don't confuse with "Markdown ASCII Punctuation" chars
// http://spec.commonmark.org/0.15/#ascii-punctuation-character
function isTerminatorChar(ch) {
function isTerminatorChar (ch) {
switch (ch) {
case 0x0A/* \n */:
case 0x21/* ! */:
@ -39,7 +39,7 @@ function isTerminatorChar(ch) {
}
}
export default function text(state, silent) {
export default function text (state, silent) {
let pos = state.pos
while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) {

12
lib/token.mjs

@ -9,7 +9,7 @@
*
* Create new token and fill passed properties.
**/
function Token(type, tag, nesting) {
function Token (type, tag, nesting) {
/**
* Token#type -> String
*
@ -119,7 +119,7 @@ function Token(type, tag, nesting) {
*
* Search attribute index by name.
**/
Token.prototype.attrIndex = function attrIndex(name) {
Token.prototype.attrIndex = function attrIndex (name) {
if (!this.attrs) { return -1 }
const attrs = this.attrs
@ -136,7 +136,7 @@ Token.prototype.attrIndex = function attrIndex(name) {
*
* Add `[ name, value ]` attribute to list. Init attrs if necessary
**/
Token.prototype.attrPush = function attrPush(attrData) {
Token.prototype.attrPush = function attrPush (attrData) {
if (this.attrs) {
this.attrs.push(attrData)
} else {
@ -150,7 +150,7 @@ Token.prototype.attrPush = function attrPush(attrData) {
*
* Set `name` attribute to `value`. Override old value if exists.
**/
Token.prototype.attrSet = function attrSet(name, value) {
Token.prototype.attrSet = function attrSet (name, value) {
const idx = this.attrIndex(name),
attrData = [ name, value ]
@ -167,7 +167,7 @@ Token.prototype.attrSet = function attrSet(name, value) {
*
* Get the value of attribute `name`, or null if it does not exist.
**/
Token.prototype.attrGet = function attrGet(name) {
Token.prototype.attrGet = function attrGet (name) {
const idx = this.attrIndex(name)
let value = null
if (idx >= 0) {
@ -183,7 +183,7 @@ Token.prototype.attrGet = function attrGet(name) {
* Join value to existing attribute via space. Or create new attribute if not
* exists. Useful to operate with token classes.
**/
Token.prototype.attrJoin = function attrJoin(name, value) {
Token.prototype.attrJoin = function attrJoin (name, value) {
const idx = this.attrIndex(name)
if (idx < 0) {

2
support/build_demo.mjs

@ -3,7 +3,7 @@
import shell from 'shelljs'
import { readFileSync, writeFileSync } from 'fs'
function escape(input) {
function escape (input) {
return input
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')

16
support/demo_template/index.mjs

@ -62,7 +62,7 @@ defaults.highlight = function (str, lang) {
return '<pre><code class="hljs">' + esc(str) + '</code></pre>'
}
function setOptionClass(name, val) {
function setOptionClass (name, val) {
if (val) {
$('body').addClass('opt_' + name)
} else {
@ -70,7 +70,7 @@ function setOptionClass(name, val) {
}
}
function setResultView(val) {
function setResultView (val) {
$('body').removeClass('result-as-html')
$('body').removeClass('result-as-src')
$('body').removeClass('result-as-debug')
@ -78,7 +78,7 @@ function setResultView(val) {
defaults._view = val
}
function mdInit() {
function mdInit () {
if (defaults._strict) {
mdHtml = window.markdownit('commonmark')
mdSrc = window.markdownit('commonmark')
@ -120,7 +120,7 @@ function mdInit() {
//
// - We track only headings and paragraphs on first level. That's enough.
// - Footnotes content causes jumps. Level limit filter it automatically.
function injectLineNumbers(tokens, idx, options, env, slf) {
function injectLineNumbers (tokens, idx, options, env, slf) {
let line
if (tokens[idx].map && tokens[idx].level === 0) {
line = tokens[idx].map[0]
@ -133,7 +133,7 @@ function mdInit() {
mdHtml.renderer.rules.paragraph_open = mdHtml.renderer.rules.heading_open = injectLineNumbers
}
function setHighlightedlContent(selector, content, lang) {
function setHighlightedlContent (selector, content, lang) {
if (window.hljs) {
$(selector).html(window.hljs.highlight(content, { language: lang }).value)
} else {
@ -141,7 +141,7 @@ function setHighlightedlContent(selector, content, lang) {
}
}
function updateResult() {
function updateResult () {
const source = $('.source').val()
// Update only active view to avoid slowdowns
@ -181,7 +181,7 @@ function updateResult() {
// Build offsets for each line (lines can be wrapped)
// That's a bit dirty to process each line everytime, but ok for demo.
// Optimizations are required only for big texts.
function buildScrollMap() {
function buildScrollMap () {
const textarea = $('.source')
const sourceLikeDiv = $('<div />').css({
@ -295,7 +295,7 @@ const syncSrcScroll = _.debounce(function () {
}, 50, { maxWait: 50 })
function loadPermalink() {
function loadPermalink () {
if (!location.hash) { return }

2
support/rollup.config.mjs

@ -43,7 +43,7 @@ export default {
nodeResolve({ preferBuiltins: true }),
commonjs(),
{
banner() {
banner () {
return `/*! ${pkg.name} ${pkg.version} https://github.com/${pkg.repository} @license ${pkg.license} */`
}
}

4
support/specsplit.mjs

@ -33,13 +33,13 @@ const options = cli.parse_args()
////////////////////////////////////////////////////////////////////////////////
function normalize(text) {
function normalize (text) {
return text.replace(/<blockquote>\n<\/blockquote>/g, '<blockquote></blockquote>')
}
////////////////////////////////////////////////////////////////////////////////
function readFile(filename, encoding, callback) {
function readFile (filename, encoding, callback) {
if (options.file === '-') {
// read from stdin

4
test/commonmark.mjs

@ -5,12 +5,12 @@ import markdownit from '../index.mjs'
import { assert } from 'chai'
function normalize(text) {
function normalize (text) {
return text.replace(/<blockquote>\n<\/blockquote>/g, '<blockquote></blockquote>')
}
function generate(path, md) {
function generate (path, md) {
load(path, function (data) {
data.meta = data.meta || {}

4
test/misc.mjs

@ -30,7 +30,7 @@ describe('API', function () {
it('plugin', function () {
let succeeded = false
function plugin(slf, opts) { if (opts === 'bar') { succeeded = true } }
function plugin (slf, opts) { if (opts === 'bar') { succeeded = true } }
const md = markdownit()
@ -410,7 +410,7 @@ describe('smartquotes', function () {
describe('Ordered list info', function () {
const md = markdownit()
function type_filter(tokens, type) {
function type_filter (tokens, type) {
return tokens.filter(function (t) { return t.type === type })
}

2
test/pathological.mjs

@ -5,7 +5,7 @@ import { Worker as JestWorker } from 'jest-worker'
import { readFileSync } from 'fs'
async function test_pattern(str) {
async function test_pattern (str) {
const worker = new JestWorker(
new URL('./pathological_worker.js', import.meta.url),
{

38
test/ruler.mjs

@ -7,8 +7,8 @@ describe('Ruler', function () {
const ruler = new Ruler()
let res = 0
ruler.push('test', function foo() { res = 1 })
ruler.at('test', function bar() { res = 2 })
ruler.push('test', function foo () { res = 1 })
ruler.at('test', function bar () { res = 2 })
const rules = ruler.getRules('')
@ -22,9 +22,9 @@ describe('Ruler', function () {
const ruler = new Ruler()
let res = 0
ruler.push('test', function foo() { res = 1 })
ruler.before('test', 'before_test', function fooBefore() { res = -10 })
ruler.after('test', 'after_test', function fooAfter() { res = 10 })
ruler.push('test', function foo () { res = 1 })
ruler.before('test', 'before_test', function fooBefore () { res = -10 })
ruler.after('test', 'after_test', function fooAfter () { res = 10 })
const rules = ruler.getRules('')
@ -42,8 +42,8 @@ describe('Ruler', function () {
const ruler = new Ruler()
let rules
ruler.push('test', function foo() {})
ruler.push('test2', function bar() {})
ruler.push('test', function foo () {})
ruler.push('test2', function bar () {})
rules = ruler.getRules('')
assert.strictEqual(rules.length, 2)
@ -68,8 +68,8 @@ describe('Ruler', function () {
const ruler = new Ruler()
let rules
ruler.push('test', function foo() {})
ruler.push('test2', function bar() {})
ruler.push('test', function foo () {})
ruler.push('test2', function bar () {})
ruler.disable([ 'test', 'test2' ])
rules = ruler.getRules('')
@ -83,8 +83,8 @@ describe('Ruler', function () {
it('should enable rules by whitelist', function () {
const ruler = new Ruler()
ruler.push('test', function foo() {})
ruler.push('test2', function bar() {})
ruler.push('test', function foo () {})
ruler.push('test2', function bar () {})
ruler.enableOnly('test')
const rules = ruler.getRules('')
@ -96,9 +96,9 @@ describe('Ruler', function () {
const ruler = new Ruler()
let rules
ruler.push('test', function foo() {})
ruler.push('test2', function bar() {}, { alt: [ 'alt1' ] })
ruler.push('test2', function bar() {}, { alt: [ 'alt1', 'alt2' ] })
ruler.push('test', function foo () {})
ruler.push('test2', function bar () {}, { alt: [ 'alt1' ] })
ruler.push('test2', function bar () {}, { alt: [ 'alt1', 'alt2' ] })
rules = ruler.getRules('')
assert.strictEqual(rules.length, 3)
@ -112,16 +112,16 @@ describe('Ruler', function () {
it('should fail on invalid rule name', function () {
const ruler = new Ruler()
ruler.push('test', function foo() {})
ruler.push('test', function foo () {})
assert.throws(function () {
ruler.at('invalid name', function bar() {})
ruler.at('invalid name', function bar () {})
})
assert.throws(function () {
ruler.before('invalid name', function bar() {})
ruler.before('invalid name', function bar () {})
})
assert.throws(function () {
ruler.after('invalid name', function bar() {})
ruler.after('invalid name', function bar () {})
})
assert.throws(function () {
ruler.enable('invalid name')
@ -135,7 +135,7 @@ describe('Ruler', function () {
it('should not fail on invalid rule name in silent mode', function () {
const ruler = new Ruler()
ruler.push('test', function foo() {})
ruler.push('test', function foo () {})
assert.doesNotThrow(function () {
ruler.enable('invalid name', true)

Loading…
Cancel
Save