This commit is contained in:
67
node_modules/remark-stringify/lib/util/copy-identifier-encoding.js
generated
vendored
Normal file
67
node_modules/remark-stringify/lib/util/copy-identifier-encoding.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
'use strict'
|
||||
|
||||
var entityPrefixLength = require('./entity-prefix-length')
|
||||
|
||||
module.exports = copy
|
||||
|
||||
var ampersand = '&'
|
||||
|
||||
var punctuationExppresion = /[-!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~_]/
|
||||
|
||||
// For shortcut and collapsed reference links, the contents is also an
|
||||
// identifier, so we need to restore the original encoding and escaping
|
||||
// that were present in the source string.
|
||||
//
|
||||
// This function takes the unescaped & unencoded value from shortcut’s
|
||||
// child nodes and the identifier and encodes the former according to
|
||||
// the latter.
|
||||
function copy(value, identifier) {
|
||||
var length = value.length
|
||||
var count = identifier.length
|
||||
var result = []
|
||||
var position = 0
|
||||
var index = 0
|
||||
var start
|
||||
|
||||
while (index < length) {
|
||||
// Take next non-punctuation characters from `value`.
|
||||
start = index
|
||||
|
||||
while (index < length && !punctuationExppresion.test(value.charAt(index))) {
|
||||
index += 1
|
||||
}
|
||||
|
||||
result.push(value.slice(start, index))
|
||||
|
||||
// Advance `position` to the next punctuation character.
|
||||
while (
|
||||
position < count &&
|
||||
!punctuationExppresion.test(identifier.charAt(position))
|
||||
) {
|
||||
position += 1
|
||||
}
|
||||
|
||||
// Take next punctuation characters from `identifier`.
|
||||
start = position
|
||||
|
||||
while (
|
||||
position < count &&
|
||||
punctuationExppresion.test(identifier.charAt(position))
|
||||
) {
|
||||
if (identifier.charAt(position) === ampersand) {
|
||||
position += entityPrefixLength(identifier.slice(position))
|
||||
}
|
||||
|
||||
position += 1
|
||||
}
|
||||
|
||||
result.push(identifier.slice(start, position))
|
||||
|
||||
// Advance `index` to the next non-punctuation character.
|
||||
while (index < length && punctuationExppresion.test(value.charAt(index))) {
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
return result.join('')
|
||||
}
|
||||
17
node_modules/remark-stringify/lib/util/enclose-title.js
generated
vendored
Normal file
17
node_modules/remark-stringify/lib/util/enclose-title.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = enclose
|
||||
|
||||
var quotationMark = '"'
|
||||
var apostrophe = "'"
|
||||
|
||||
// There is currently no way to support nested delimiters across Markdown.pl,
|
||||
// CommonMark, and GitHub (RedCarpet). The following code supports Markdown.pl
|
||||
// and GitHub.
|
||||
// CommonMark is not supported when mixing double- and single quotes inside a
|
||||
// title.
|
||||
function enclose(title) {
|
||||
var delimiter =
|
||||
title.indexOf(quotationMark) === -1 ? quotationMark : apostrophe
|
||||
return delimiter + title + delimiter
|
||||
}
|
||||
33
node_modules/remark-stringify/lib/util/enclose-uri.js
generated
vendored
Normal file
33
node_modules/remark-stringify/lib/util/enclose-uri.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict'
|
||||
|
||||
var count = require('ccount')
|
||||
|
||||
module.exports = enclose
|
||||
|
||||
var leftParenthesis = '('
|
||||
var rightParenthesis = ')'
|
||||
var lessThan = '<'
|
||||
var greaterThan = '>'
|
||||
|
||||
var expression = /\s/
|
||||
|
||||
// Wrap `url` in angle brackets when needed, or when
|
||||
// forced.
|
||||
// In links, images, and definitions, the URL part needs
|
||||
// to be enclosed when it:
|
||||
//
|
||||
// - has a length of `0`
|
||||
// - contains white-space
|
||||
// - has more or less opening than closing parentheses
|
||||
function enclose(uri, always) {
|
||||
if (
|
||||
always ||
|
||||
uri.length === 0 ||
|
||||
expression.test(uri) ||
|
||||
count(uri, leftParenthesis) !== count(uri, rightParenthesis)
|
||||
) {
|
||||
return lessThan + uri + greaterThan
|
||||
}
|
||||
|
||||
return uri
|
||||
}
|
||||
33
node_modules/remark-stringify/lib/util/enter-link-reference.js
generated
vendored
Normal file
33
node_modules/remark-stringify/lib/util/enter-link-reference.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict'
|
||||
|
||||
var identity = require('./identity')
|
||||
|
||||
module.exports = enter
|
||||
|
||||
// Shortcut and collapsed link references need no escaping and encoding during
|
||||
// the processing of child nodes (it must be implied from identifier).
|
||||
//
|
||||
// This toggler turns encoding and escaping off for shortcut and collapsed
|
||||
// references.
|
||||
//
|
||||
// Implies `enterLink`.
|
||||
function enter(compiler, node) {
|
||||
var encode = compiler.encode
|
||||
var escape = compiler.escape
|
||||
var exitLink = compiler.enterLink()
|
||||
|
||||
if (node.referenceType !== 'shortcut' && node.referenceType !== 'collapsed') {
|
||||
return exitLink
|
||||
}
|
||||
|
||||
compiler.escape = identity
|
||||
compiler.encode = identity
|
||||
|
||||
return exit
|
||||
|
||||
function exit() {
|
||||
compiler.encode = encode
|
||||
compiler.escape = escape
|
||||
exitLink()
|
||||
}
|
||||
}
|
||||
23
node_modules/remark-stringify/lib/util/entity-prefix-length.js
generated
vendored
Normal file
23
node_modules/remark-stringify/lib/util/entity-prefix-length.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict'
|
||||
|
||||
var decode = require('parse-entities')
|
||||
|
||||
module.exports = length
|
||||
|
||||
var ampersand = '&'
|
||||
|
||||
// Returns the length of HTML entity that is a prefix of the given string
|
||||
// (excluding the ampersand), 0 if it does not start with an entity.
|
||||
function length(value) {
|
||||
var prefix
|
||||
|
||||
/* istanbul ignore if - Currently also tested for at implemention, but we
|
||||
* keep it here because that’s proper. */
|
||||
if (value.charAt(0) !== ampersand) {
|
||||
return 0
|
||||
}
|
||||
|
||||
prefix = value.split(ampersand, 2).join(ampersand)
|
||||
|
||||
return prefix.length - decode(prefix).length
|
||||
}
|
||||
7
node_modules/remark-stringify/lib/util/identity.js
generated
vendored
Normal file
7
node_modules/remark-stringify/lib/util/identity.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = identity
|
||||
|
||||
function identity(value) {
|
||||
return value
|
||||
}
|
||||
27
node_modules/remark-stringify/lib/util/label.js
generated
vendored
Normal file
27
node_modules/remark-stringify/lib/util/label.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = label
|
||||
|
||||
var leftSquareBracket = '['
|
||||
var rightSquareBracket = ']'
|
||||
|
||||
var shortcut = 'shortcut'
|
||||
var collapsed = 'collapsed'
|
||||
|
||||
// Stringify a reference label.
|
||||
// Because link references are easily, mistakingly, created (for example,
|
||||
// `[foo]`), reference nodes have an extra property depicting how it looked in
|
||||
// the original document, so stringification can cause minimal changes.
|
||||
function label(node) {
|
||||
var type = node.referenceType
|
||||
|
||||
if (type === shortcut) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return (
|
||||
leftSquareBracket +
|
||||
(type === collapsed ? '' : node.label || node.identifier) +
|
||||
rightSquareBracket
|
||||
)
|
||||
}
|
||||
26
node_modules/remark-stringify/lib/util/pad.js
generated
vendored
Normal file
26
node_modules/remark-stringify/lib/util/pad.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
var repeat = require('repeat-string')
|
||||
|
||||
module.exports = pad
|
||||
|
||||
var lineFeed = '\n'
|
||||
var space = ' '
|
||||
|
||||
var tabSize = 4
|
||||
|
||||
// Pad `value` with `level * tabSize` spaces. Respects lines. Ignores empty
|
||||
// lines.
|
||||
function pad(value, level) {
|
||||
var values = value.split(lineFeed)
|
||||
var index = values.length
|
||||
var padding = repeat(space, level * tabSize)
|
||||
|
||||
while (index--) {
|
||||
if (values[index].length !== 0) {
|
||||
values[index] = padding + values[index]
|
||||
}
|
||||
}
|
||||
|
||||
return values.join(lineFeed)
|
||||
}
|
||||
Reference in New Issue
Block a user