This commit is contained in:
27
node_modules/mdast-util-to-markdown/lib/configure.js
generated
vendored
Normal file
27
node_modules/mdast-util-to-markdown/lib/configure.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
module.exports = configure
|
||||
|
||||
function configure(base, extension) {
|
||||
var index = -1
|
||||
var key
|
||||
|
||||
// First do subextensions.
|
||||
if (extension.extensions) {
|
||||
while (++index < extension.extensions.length) {
|
||||
configure(base, extension.extensions[index])
|
||||
}
|
||||
}
|
||||
|
||||
for (key in extension) {
|
||||
if (key === 'extensions') {
|
||||
// Empty.
|
||||
} else if (key === 'unsafe' || key === 'join') {
|
||||
base[key] = base[key].concat(extension[key] || [])
|
||||
} else if (key === 'handlers') {
|
||||
base[key] = Object.assign(base[key], extension[key] || {})
|
||||
} else {
|
||||
base.options[key] = extension[key]
|
||||
}
|
||||
}
|
||||
|
||||
return base
|
||||
}
|
||||
15
node_modules/mdast-util-to-markdown/lib/handle/blockquote.js
generated
vendored
Normal file
15
node_modules/mdast-util-to-markdown/lib/handle/blockquote.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = blockquote
|
||||
|
||||
var flow = require('../util/container-flow')
|
||||
var indentLines = require('../util/indent-lines')
|
||||
|
||||
function blockquote(node, _, context) {
|
||||
var exit = context.enter('blockquote')
|
||||
var value = indentLines(flow(node, context), map)
|
||||
exit()
|
||||
return value
|
||||
}
|
||||
|
||||
function map(line, index, blank) {
|
||||
return '>' + (blank ? '' : ' ') + line
|
||||
}
|
||||
20
node_modules/mdast-util-to-markdown/lib/handle/break.js
generated
vendored
Normal file
20
node_modules/mdast-util-to-markdown/lib/handle/break.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
module.exports = hardBreak
|
||||
|
||||
var patternInScope = require('../util/pattern-in-scope')
|
||||
|
||||
function hardBreak(node, _, context, safe) {
|
||||
var index = -1
|
||||
|
||||
while (++index < context.unsafe.length) {
|
||||
// If we can’t put eols in this construct (setext headings, tables), use a
|
||||
// space instead.
|
||||
if (
|
||||
context.unsafe[index].character === '\n' &&
|
||||
patternInScope(context.stack, context.unsafe[index])
|
||||
) {
|
||||
return /[ \t]/.test(safe.before) ? '' : ' '
|
||||
}
|
||||
}
|
||||
|
||||
return '\\\n'
|
||||
}
|
||||
64
node_modules/mdast-util-to-markdown/lib/handle/code.js
generated
vendored
Normal file
64
node_modules/mdast-util-to-markdown/lib/handle/code.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
module.exports = code
|
||||
|
||||
var repeat = require('repeat-string')
|
||||
var streak = require('longest-streak')
|
||||
var formatCodeAsIndented = require('../util/format-code-as-indented')
|
||||
var checkFence = require('../util/check-fence')
|
||||
var indentLines = require('../util/indent-lines')
|
||||
var safe = require('../util/safe')
|
||||
|
||||
function code(node, _, context) {
|
||||
var marker = checkFence(context)
|
||||
var raw = node.value || ''
|
||||
var suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
|
||||
var value
|
||||
var sequence
|
||||
var exit
|
||||
var subexit
|
||||
|
||||
if (formatCodeAsIndented(node, context)) {
|
||||
exit = context.enter('codeIndented')
|
||||
value = indentLines(raw, map)
|
||||
} else {
|
||||
sequence = repeat(marker, Math.max(streak(raw, marker) + 1, 3))
|
||||
exit = context.enter('codeFenced')
|
||||
value = sequence
|
||||
|
||||
if (node.lang) {
|
||||
subexit = context.enter('codeFencedLang' + suffix)
|
||||
value += safe(context, node.lang, {
|
||||
before: '`',
|
||||
after: ' ',
|
||||
encode: ['`']
|
||||
})
|
||||
subexit()
|
||||
}
|
||||
|
||||
if (node.lang && node.meta) {
|
||||
subexit = context.enter('codeFencedMeta' + suffix)
|
||||
value +=
|
||||
' ' +
|
||||
safe(context, node.meta, {
|
||||
before: ' ',
|
||||
after: '\n',
|
||||
encode: ['`']
|
||||
})
|
||||
subexit()
|
||||
}
|
||||
|
||||
value += '\n'
|
||||
|
||||
if (raw) {
|
||||
value += raw + '\n'
|
||||
}
|
||||
|
||||
value += sequence
|
||||
}
|
||||
|
||||
exit()
|
||||
return value
|
||||
}
|
||||
|
||||
function map(line, _, blank) {
|
||||
return (blank ? '' : ' ') + line
|
||||
}
|
||||
46
node_modules/mdast-util-to-markdown/lib/handle/definition.js
generated
vendored
Normal file
46
node_modules/mdast-util-to-markdown/lib/handle/definition.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
module.exports = definition
|
||||
|
||||
var association = require('../util/association')
|
||||
var checkQuote = require('../util/check-quote')
|
||||
var safe = require('../util/safe')
|
||||
|
||||
function definition(node, _, context) {
|
||||
var marker = checkQuote(context)
|
||||
var suffix = marker === '"' ? 'Quote' : 'Apostrophe'
|
||||
var exit = context.enter('definition')
|
||||
var subexit = context.enter('label')
|
||||
var value =
|
||||
'[' + safe(context, association(node), {before: '[', after: ']'}) + ']: '
|
||||
|
||||
subexit()
|
||||
|
||||
if (
|
||||
// If there’s no url, or…
|
||||
!node.url ||
|
||||
// If there’s whitespace, enclosed is prettier.
|
||||
/[ \t\r\n]/.test(node.url)
|
||||
) {
|
||||
subexit = context.enter('destinationLiteral')
|
||||
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>'
|
||||
} else {
|
||||
// No whitespace, raw is prettier.
|
||||
subexit = context.enter('destinationRaw')
|
||||
value += safe(context, node.url, {before: ' ', after: ' '})
|
||||
}
|
||||
|
||||
subexit()
|
||||
|
||||
if (node.title) {
|
||||
subexit = context.enter('title' + suffix)
|
||||
value +=
|
||||
' ' +
|
||||
marker +
|
||||
safe(context, node.title, {before: marker, after: marker}) +
|
||||
marker
|
||||
subexit()
|
||||
}
|
||||
|
||||
exit()
|
||||
|
||||
return value
|
||||
}
|
||||
21
node_modules/mdast-util-to-markdown/lib/handle/emphasis.js
generated
vendored
Normal file
21
node_modules/mdast-util-to-markdown/lib/handle/emphasis.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = emphasis
|
||||
emphasis.peek = emphasisPeek
|
||||
|
||||
var checkEmphasis = require('../util/check-emphasis')
|
||||
var phrasing = require('../util/container-phrasing')
|
||||
|
||||
// To do: there are cases where emphasis cannot “form” depending on the
|
||||
// previous or next character of sequences.
|
||||
// There’s no way around that though, except for injecting zero-width stuff.
|
||||
// Do we need to safeguard against that?
|
||||
function emphasis(node, _, context) {
|
||||
var marker = checkEmphasis(context)
|
||||
var exit = context.enter('emphasis')
|
||||
var value = phrasing(node, context, {before: marker, after: marker})
|
||||
exit()
|
||||
return marker + value + marker
|
||||
}
|
||||
|
||||
function emphasisPeek(node, _, context) {
|
||||
return context.options.emphasis || '*'
|
||||
}
|
||||
48
node_modules/mdast-util-to-markdown/lib/handle/heading.js
generated
vendored
Normal file
48
node_modules/mdast-util-to-markdown/lib/handle/heading.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
module.exports = heading
|
||||
|
||||
var repeat = require('repeat-string')
|
||||
var formatHeadingAsSetext = require('../util/format-heading-as-setext')
|
||||
var phrasing = require('../util/container-phrasing')
|
||||
|
||||
function heading(node, _, context) {
|
||||
var rank = Math.max(Math.min(6, node.depth || 1), 1)
|
||||
var exit
|
||||
var subexit
|
||||
var value
|
||||
var sequence
|
||||
|
||||
if (formatHeadingAsSetext(node, context)) {
|
||||
exit = context.enter('headingSetext')
|
||||
subexit = context.enter('phrasing')
|
||||
value = phrasing(node, context, {before: '\n', after: '\n'})
|
||||
subexit()
|
||||
exit()
|
||||
|
||||
return (
|
||||
value +
|
||||
'\n' +
|
||||
repeat(
|
||||
rank === 1 ? '=' : '-',
|
||||
// The whole size…
|
||||
value.length -
|
||||
// Minus the position of the character after the last EOL (or
|
||||
// 0 if there is none)…
|
||||
(Math.max(value.lastIndexOf('\r'), value.lastIndexOf('\n')) + 1)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
sequence = repeat('#', rank)
|
||||
exit = context.enter('headingAtx')
|
||||
subexit = context.enter('phrasing')
|
||||
value = phrasing(node, context, {before: '# ', after: '\n'})
|
||||
value = value ? sequence + ' ' + value : sequence
|
||||
if (context.options.closeAtx) {
|
||||
value += ' ' + sequence
|
||||
}
|
||||
|
||||
subexit()
|
||||
exit()
|
||||
|
||||
return value
|
||||
}
|
||||
10
node_modules/mdast-util-to-markdown/lib/handle/html.js
generated
vendored
Normal file
10
node_modules/mdast-util-to-markdown/lib/handle/html.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = html
|
||||
html.peek = htmlPeek
|
||||
|
||||
function html(node) {
|
||||
return node.value || ''
|
||||
}
|
||||
|
||||
function htmlPeek() {
|
||||
return '<'
|
||||
}
|
||||
37
node_modules/mdast-util-to-markdown/lib/handle/image-reference.js
generated
vendored
Normal file
37
node_modules/mdast-util-to-markdown/lib/handle/image-reference.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
module.exports = imageReference
|
||||
imageReference.peek = imageReferencePeek
|
||||
|
||||
var association = require('../util/association')
|
||||
var safe = require('../util/safe')
|
||||
|
||||
function imageReference(node, _, context) {
|
||||
var type = node.referenceType
|
||||
var exit = context.enter('imageReference')
|
||||
var subexit = context.enter('label')
|
||||
var alt = safe(context, node.alt, {before: '[', after: ']'})
|
||||
var value = '![' + alt + ']'
|
||||
var reference
|
||||
var stack
|
||||
|
||||
subexit()
|
||||
// Hide the fact that we’re in phrasing, because escapes don’t work.
|
||||
stack = context.stack
|
||||
context.stack = []
|
||||
subexit = context.enter('reference')
|
||||
reference = safe(context, association(node), {before: '[', after: ']'})
|
||||
subexit()
|
||||
context.stack = stack
|
||||
exit()
|
||||
|
||||
if (type === 'full' || !alt || alt !== reference) {
|
||||
value += '[' + reference + ']'
|
||||
} else if (type !== 'shortcut') {
|
||||
value += '[]'
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function imageReferencePeek() {
|
||||
return '!'
|
||||
}
|
||||
53
node_modules/mdast-util-to-markdown/lib/handle/image.js
generated
vendored
Normal file
53
node_modules/mdast-util-to-markdown/lib/handle/image.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
module.exports = image
|
||||
image.peek = imagePeek
|
||||
|
||||
var checkQuote = require('../util/check-quote')
|
||||
var safe = require('../util/safe')
|
||||
|
||||
function image(node, _, context) {
|
||||
var quote = checkQuote(context)
|
||||
var suffix = quote === '"' ? 'Quote' : 'Apostrophe'
|
||||
var exit = context.enter('image')
|
||||
var subexit = context.enter('label')
|
||||
var value = '![' + safe(context, node.alt, {before: '[', after: ']'}) + ']('
|
||||
|
||||
subexit()
|
||||
|
||||
if (
|
||||
// If there’s no url but there is a title…
|
||||
(!node.url && node.title) ||
|
||||
// Or if there’s markdown whitespace or an eol, enclose.
|
||||
/[ \t\r\n]/.test(node.url)
|
||||
) {
|
||||
subexit = context.enter('destinationLiteral')
|
||||
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>'
|
||||
} else {
|
||||
// No whitespace, raw is prettier.
|
||||
subexit = context.enter('destinationRaw')
|
||||
value += safe(context, node.url, {
|
||||
before: '(',
|
||||
after: node.title ? ' ' : ')'
|
||||
})
|
||||
}
|
||||
|
||||
subexit()
|
||||
|
||||
if (node.title) {
|
||||
subexit = context.enter('title' + suffix)
|
||||
value +=
|
||||
' ' +
|
||||
quote +
|
||||
safe(context, node.title, {before: quote, after: quote}) +
|
||||
quote
|
||||
subexit()
|
||||
}
|
||||
|
||||
value += ')'
|
||||
exit()
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function imagePeek() {
|
||||
return '!'
|
||||
}
|
||||
20
node_modules/mdast-util-to-markdown/lib/handle/index.js
generated
vendored
Normal file
20
node_modules/mdast-util-to-markdown/lib/handle/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
exports.blockquote = require('./blockquote')
|
||||
exports.break = require('./break')
|
||||
exports.code = require('./code')
|
||||
exports.definition = require('./definition')
|
||||
exports.emphasis = require('./emphasis')
|
||||
exports.hardBreak = require('./break')
|
||||
exports.heading = require('./heading')
|
||||
exports.html = require('./html')
|
||||
exports.image = require('./image')
|
||||
exports.imageReference = require('./image-reference')
|
||||
exports.inlineCode = require('./inline-code')
|
||||
exports.link = require('./link')
|
||||
exports.linkReference = require('./link-reference')
|
||||
exports.list = require('./list')
|
||||
exports.listItem = require('./list-item')
|
||||
exports.paragraph = require('./paragraph')
|
||||
exports.root = require('./root')
|
||||
exports.strong = require('./strong')
|
||||
exports.text = require('./text')
|
||||
exports.thematicBreak = require('./thematic-break')
|
||||
69
node_modules/mdast-util-to-markdown/lib/handle/inline-code.js
generated
vendored
Normal file
69
node_modules/mdast-util-to-markdown/lib/handle/inline-code.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
module.exports = inlineCode
|
||||
inlineCode.peek = inlineCodePeek
|
||||
|
||||
var patternCompile = require('../util/pattern-compile')
|
||||
|
||||
function inlineCode(node, parent, context) {
|
||||
var value = node.value || ''
|
||||
var sequence = '`'
|
||||
var index = -1
|
||||
var pattern
|
||||
var expression
|
||||
var match
|
||||
var position
|
||||
|
||||
// If there is a single grave accent on its own in the code, use a fence of
|
||||
// two.
|
||||
// If there are two in a row, use one.
|
||||
while (new RegExp('(^|[^`])' + sequence + '([^`]|$)').test(value)) {
|
||||
sequence += '`'
|
||||
}
|
||||
|
||||
// If this is not just spaces or eols (tabs don’t count), and either the
|
||||
// first or last character are a space, eol, or tick, then pad with spaces.
|
||||
if (
|
||||
/[^ \r\n]/.test(value) &&
|
||||
(/[ \r\n`]/.test(value.charAt(0)) ||
|
||||
/[ \r\n`]/.test(value.charAt(value.length - 1)))
|
||||
) {
|
||||
value = ' ' + value + ' '
|
||||
}
|
||||
|
||||
// We have a potential problem: certain characters after eols could result in
|
||||
// blocks being seen.
|
||||
// For example, if someone injected the string `'\n# b'`, then that would
|
||||
// result in an ATX heading.
|
||||
// We can’t escape characters in `inlineCode`, but because eols are
|
||||
// transformed to spaces when going from markdown to HTML anyway, we can swap
|
||||
// them out.
|
||||
while (++index < context.unsafe.length) {
|
||||
pattern = context.unsafe[index]
|
||||
|
||||
// Only look for `atBreak`s.
|
||||
// Btw: note that `atBreak` patterns will always start the regex at LF or
|
||||
// CR.
|
||||
if (!pattern.atBreak) continue
|
||||
|
||||
expression = patternCompile(pattern)
|
||||
|
||||
while ((match = expression.exec(value))) {
|
||||
position = match.index
|
||||
|
||||
// Support CRLF (patterns only look for one of the characters).
|
||||
if (
|
||||
value.charCodeAt(position) === 10 /* `\n` */ &&
|
||||
value.charCodeAt(position - 1) === 13 /* `\r` */
|
||||
) {
|
||||
position--
|
||||
}
|
||||
|
||||
value = value.slice(0, position) + ' ' + value.slice(match.index + 1)
|
||||
}
|
||||
}
|
||||
|
||||
return sequence + value + sequence
|
||||
}
|
||||
|
||||
function inlineCodePeek() {
|
||||
return '`'
|
||||
}
|
||||
38
node_modules/mdast-util-to-markdown/lib/handle/link-reference.js
generated
vendored
Normal file
38
node_modules/mdast-util-to-markdown/lib/handle/link-reference.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
module.exports = linkReference
|
||||
linkReference.peek = linkReferencePeek
|
||||
|
||||
var association = require('../util/association')
|
||||
var phrasing = require('../util/container-phrasing')
|
||||
var safe = require('../util/safe')
|
||||
|
||||
function linkReference(node, _, context) {
|
||||
var type = node.referenceType
|
||||
var exit = context.enter('linkReference')
|
||||
var subexit = context.enter('label')
|
||||
var text = phrasing(node, context, {before: '[', after: ']'})
|
||||
var value = '[' + text + ']'
|
||||
var reference
|
||||
var stack
|
||||
|
||||
subexit()
|
||||
// Hide the fact that we’re in phrasing, because escapes don’t work.
|
||||
stack = context.stack
|
||||
context.stack = []
|
||||
subexit = context.enter('reference')
|
||||
reference = safe(context, association(node), {before: '[', after: ']'})
|
||||
subexit()
|
||||
context.stack = stack
|
||||
exit()
|
||||
|
||||
if (type === 'full' || !text || text !== reference) {
|
||||
value += '[' + reference + ']'
|
||||
} else if (type !== 'shortcut') {
|
||||
value += '[]'
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function linkReferencePeek() {
|
||||
return '['
|
||||
}
|
||||
70
node_modules/mdast-util-to-markdown/lib/handle/link.js
generated
vendored
Normal file
70
node_modules/mdast-util-to-markdown/lib/handle/link.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
module.exports = link
|
||||
link.peek = linkPeek
|
||||
|
||||
var checkQuote = require('../util/check-quote')
|
||||
var formatLinkAsAutolink = require('../util/format-link-as-autolink')
|
||||
var phrasing = require('../util/container-phrasing')
|
||||
var safe = require('../util/safe')
|
||||
|
||||
function link(node, _, context) {
|
||||
var quote = checkQuote(context)
|
||||
var suffix = quote === '"' ? 'Quote' : 'Apostrophe'
|
||||
var exit
|
||||
var subexit
|
||||
var value
|
||||
var stack
|
||||
|
||||
if (formatLinkAsAutolink(node, context)) {
|
||||
// Hide the fact that we’re in phrasing, because escapes don’t work.
|
||||
stack = context.stack
|
||||
context.stack = []
|
||||
exit = context.enter('autolink')
|
||||
value = '<' + phrasing(node, context, {before: '<', after: '>'}) + '>'
|
||||
exit()
|
||||
context.stack = stack
|
||||
return value
|
||||
}
|
||||
|
||||
exit = context.enter('link')
|
||||
subexit = context.enter('label')
|
||||
value = '[' + phrasing(node, context, {before: '[', after: ']'}) + ']('
|
||||
subexit()
|
||||
|
||||
if (
|
||||
// If there’s no url but there is a title…
|
||||
(!node.url && node.title) ||
|
||||
// Or if there’s markdown whitespace or an eol, enclose.
|
||||
/[ \t\r\n]/.test(node.url)
|
||||
) {
|
||||
subexit = context.enter('destinationLiteral')
|
||||
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>'
|
||||
} else {
|
||||
// No whitespace, raw is prettier.
|
||||
subexit = context.enter('destinationRaw')
|
||||
value += safe(context, node.url, {
|
||||
before: '(',
|
||||
after: node.title ? ' ' : ')'
|
||||
})
|
||||
}
|
||||
|
||||
subexit()
|
||||
|
||||
if (node.title) {
|
||||
subexit = context.enter('title' + suffix)
|
||||
value +=
|
||||
' ' +
|
||||
quote +
|
||||
safe(context, node.title, {before: quote, after: quote}) +
|
||||
quote
|
||||
subexit()
|
||||
}
|
||||
|
||||
value += ')'
|
||||
|
||||
exit()
|
||||
return value
|
||||
}
|
||||
|
||||
function linkPeek(node, _, context) {
|
||||
return formatLinkAsAutolink(node, context) ? '<' : '['
|
||||
}
|
||||
47
node_modules/mdast-util-to-markdown/lib/handle/list-item.js
generated
vendored
Normal file
47
node_modules/mdast-util-to-markdown/lib/handle/list-item.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
module.exports = listItem
|
||||
|
||||
var repeat = require('repeat-string')
|
||||
var checkBullet = require('../util/check-bullet')
|
||||
var checkListItemIndent = require('../util/check-list-item-indent')
|
||||
var flow = require('../util/container-flow')
|
||||
var indentLines = require('../util/indent-lines')
|
||||
|
||||
function listItem(node, parent, context) {
|
||||
var bullet = checkBullet(context)
|
||||
var listItemIndent = checkListItemIndent(context)
|
||||
var size
|
||||
var value
|
||||
var exit
|
||||
|
||||
if (parent && parent.ordered) {
|
||||
bullet =
|
||||
(parent.start > -1 ? parent.start : 1) +
|
||||
(context.options.incrementListMarker === false
|
||||
? 0
|
||||
: parent.children.indexOf(node)) +
|
||||
'.'
|
||||
}
|
||||
|
||||
size = bullet.length + 1
|
||||
|
||||
if (
|
||||
listItemIndent === 'tab' ||
|
||||
(listItemIndent === 'mixed' && ((parent && parent.spread) || node.spread))
|
||||
) {
|
||||
size = Math.ceil(size / 4) * 4
|
||||
}
|
||||
|
||||
exit = context.enter('listItem')
|
||||
value = indentLines(flow(node, context), map)
|
||||
exit()
|
||||
|
||||
return value
|
||||
|
||||
function map(line, index, blank) {
|
||||
if (index) {
|
||||
return (blank ? '' : repeat(' ', size)) + line
|
||||
}
|
||||
|
||||
return (blank ? bullet : bullet + repeat(' ', size - bullet.length)) + line
|
||||
}
|
||||
}
|
||||
10
node_modules/mdast-util-to-markdown/lib/handle/list.js
generated
vendored
Normal file
10
node_modules/mdast-util-to-markdown/lib/handle/list.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = list
|
||||
|
||||
var flow = require('../util/container-flow')
|
||||
|
||||
function list(node, _, context) {
|
||||
var exit = context.enter('list')
|
||||
var value = flow(node, context)
|
||||
exit()
|
||||
return value
|
||||
}
|
||||
12
node_modules/mdast-util-to-markdown/lib/handle/paragraph.js
generated
vendored
Normal file
12
node_modules/mdast-util-to-markdown/lib/handle/paragraph.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
module.exports = paragraph
|
||||
|
||||
var phrasing = require('../util/container-phrasing')
|
||||
|
||||
function paragraph(node, _, context) {
|
||||
var exit = context.enter('paragraph')
|
||||
var subexit = context.enter('phrasing')
|
||||
var value = phrasing(node, context, {before: '\n', after: '\n'})
|
||||
subexit()
|
||||
exit()
|
||||
return value
|
||||
}
|
||||
7
node_modules/mdast-util-to-markdown/lib/handle/root.js
generated
vendored
Normal file
7
node_modules/mdast-util-to-markdown/lib/handle/root.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = root
|
||||
|
||||
var flow = require('../util/container-flow')
|
||||
|
||||
function root(node, _, context) {
|
||||
return flow(node, context)
|
||||
}
|
||||
21
node_modules/mdast-util-to-markdown/lib/handle/strong.js
generated
vendored
Normal file
21
node_modules/mdast-util-to-markdown/lib/handle/strong.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = strong
|
||||
strong.peek = strongPeek
|
||||
|
||||
var checkStrong = require('../util/check-strong')
|
||||
var phrasing = require('../util/container-phrasing')
|
||||
|
||||
// To do: there are cases where emphasis cannot “form” depending on the
|
||||
// previous or next character of sequences.
|
||||
// There’s no way around that though, except for injecting zero-width stuff.
|
||||
// Do we need to safeguard against that?
|
||||
function strong(node, _, context) {
|
||||
var marker = checkStrong(context)
|
||||
var exit = context.enter('strong')
|
||||
var value = phrasing(node, context, {before: marker, after: marker})
|
||||
exit()
|
||||
return marker + marker + value + marker + marker
|
||||
}
|
||||
|
||||
function strongPeek(node, _, context) {
|
||||
return context.options.strong || '*'
|
||||
}
|
||||
7
node_modules/mdast-util-to-markdown/lib/handle/text.js
generated
vendored
Normal file
7
node_modules/mdast-util-to-markdown/lib/handle/text.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = text
|
||||
|
||||
var safe = require('../util/safe')
|
||||
|
||||
function text(node, parent, context, safeOptions) {
|
||||
return safe(context, node.value, safeOptions)
|
||||
}
|
||||
14
node_modules/mdast-util-to-markdown/lib/handle/thematic-break.js
generated
vendored
Normal file
14
node_modules/mdast-util-to-markdown/lib/handle/thematic-break.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
module.exports = thematicBreak
|
||||
|
||||
var repeat = require('repeat-string')
|
||||
var checkRepeat = require('../util/check-rule-repeat')
|
||||
var checkRule = require('../util/check-rule')
|
||||
|
||||
function thematicBreak(node, parent, context) {
|
||||
var value = repeat(
|
||||
checkRule(context) + (context.options.ruleSpaces ? ' ' : ''),
|
||||
checkRepeat(context)
|
||||
)
|
||||
|
||||
return context.options.ruleSpaces ? value.slice(0, -1) : value
|
||||
}
|
||||
73
node_modules/mdast-util-to-markdown/lib/index.js
generated
vendored
Normal file
73
node_modules/mdast-util-to-markdown/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
module.exports = toMarkdown
|
||||
|
||||
var zwitch = require('zwitch')
|
||||
var configure = require('./configure')
|
||||
var defaultHandlers = require('./handle')
|
||||
var defaultJoin = require('./join')
|
||||
var defaultUnsafe = require('./unsafe')
|
||||
|
||||
function toMarkdown(tree, options) {
|
||||
var settings = options || {}
|
||||
var context = {
|
||||
enter: enter,
|
||||
stack: [],
|
||||
unsafe: [],
|
||||
join: [],
|
||||
handlers: {},
|
||||
options: {}
|
||||
}
|
||||
var result
|
||||
|
||||
configure(context, {
|
||||
unsafe: defaultUnsafe,
|
||||
join: defaultJoin,
|
||||
handlers: defaultHandlers
|
||||
})
|
||||
configure(context, settings)
|
||||
|
||||
if (context.options.tightDefinitions) {
|
||||
context.join = [joinDefinition].concat(context.join)
|
||||
}
|
||||
|
||||
context.handle = zwitch('type', {
|
||||
invalid: invalid,
|
||||
unknown: unknown,
|
||||
handlers: context.handlers
|
||||
})
|
||||
|
||||
result = context.handle(tree, null, context, {before: '\n', after: '\n'})
|
||||
|
||||
if (
|
||||
result &&
|
||||
result.charCodeAt(result.length - 1) !== 10 &&
|
||||
result.charCodeAt(result.length - 1) !== 13
|
||||
) {
|
||||
result += '\n'
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
function enter(name) {
|
||||
context.stack.push(name)
|
||||
return exit
|
||||
|
||||
function exit() {
|
||||
context.stack.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function invalid(value) {
|
||||
throw new Error('Cannot handle value `' + value + '`, expected node')
|
||||
}
|
||||
|
||||
function unknown(node) {
|
||||
throw new Error('Cannot handle unknown node `' + node.type + '`')
|
||||
}
|
||||
|
||||
function joinDefinition(left, right) {
|
||||
// No blank line between adjacent definitions.
|
||||
if (left.type === 'definition' && left.type === right.type) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
37
node_modules/mdast-util-to-markdown/lib/join.js
generated
vendored
Normal file
37
node_modules/mdast-util-to-markdown/lib/join.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
module.exports = [joinDefaults]
|
||||
|
||||
var formatCodeAsIndented = require('./util/format-code-as-indented')
|
||||
var formatHeadingAsSetext = require('./util/format-heading-as-setext')
|
||||
|
||||
function joinDefaults(left, right, parent, context) {
|
||||
if (
|
||||
// Two lists with the same marker.
|
||||
(right.type === 'list' &&
|
||||
right.type === left.type &&
|
||||
Boolean(left.ordered) === Boolean(right.ordered)) ||
|
||||
// Indented code after list or another indented code.
|
||||
(right.type === 'code' &&
|
||||
formatCodeAsIndented(right, context) &&
|
||||
(left.type === 'list' ||
|
||||
(left.type === right.type && formatCodeAsIndented(left, context))))
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Join children of a list or an item.
|
||||
// In which case, `parent` has a `spread` field.
|
||||
if (typeof parent.spread === 'boolean') {
|
||||
if (
|
||||
left.type === 'paragraph' &&
|
||||
// Two paragraphs.
|
||||
(left.type === right.type ||
|
||||
right.type === 'definition' ||
|
||||
// Paragraph followed by a setext heading.
|
||||
(right.type === 'heading' && formatHeadingAsSetext(right, context)))
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
return parent.spread ? 1 : 0
|
||||
}
|
||||
}
|
||||
110
node_modules/mdast-util-to-markdown/lib/unsafe.js
generated
vendored
Normal file
110
node_modules/mdast-util-to-markdown/lib/unsafe.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
module.exports = [
|
||||
{
|
||||
character: '\t',
|
||||
inConstruct: ['codeFencedLangGraveAccent', 'codeFencedLangTilde']
|
||||
},
|
||||
{
|
||||
character: '\r',
|
||||
inConstruct: [
|
||||
'codeFencedLangGraveAccent',
|
||||
'codeFencedLangTilde',
|
||||
'codeFencedMetaGraveAccent',
|
||||
'codeFencedMetaTilde',
|
||||
'destinationLiteral',
|
||||
'headingAtx'
|
||||
]
|
||||
},
|
||||
{
|
||||
character: '\n',
|
||||
inConstruct: [
|
||||
'codeFencedLangGraveAccent',
|
||||
'codeFencedLangTilde',
|
||||
'codeFencedMetaGraveAccent',
|
||||
'codeFencedMetaTilde',
|
||||
'destinationLiteral',
|
||||
'headingAtx'
|
||||
]
|
||||
},
|
||||
{
|
||||
character: ' ',
|
||||
inConstruct: ['codeFencedLangGraveAccent', 'codeFencedLangTilde']
|
||||
},
|
||||
// An exclamation mark can start an image, if it is followed by a link or
|
||||
// a link reference.
|
||||
{character: '!', after: '\\[', inConstruct: 'phrasing'},
|
||||
// A quote can break out of a title.
|
||||
{character: '"', inConstruct: 'titleQuote'},
|
||||
// A number sign could start an ATX heading if it starts a line.
|
||||
{atBreak: true, character: '#'},
|
||||
{character: '#', inConstruct: 'headingAtx', after: '(?:[\r\n]|$)'},
|
||||
// Dollar sign and percentage are not used in markdown.
|
||||
// An ampersand could start a character reference.
|
||||
{character: '&', after: '[#A-Za-z]', inConstruct: 'phrasing'},
|
||||
// An apostrophe can break out of a title.
|
||||
{character: "'", inConstruct: 'titleApostrophe'},
|
||||
// A left paren could break out of a destination raw.
|
||||
{character: '(', inConstruct: 'destinationRaw'},
|
||||
{before: '\\]', character: '(', inConstruct: 'phrasing'},
|
||||
// A right paren could start a list item or break out of a destination
|
||||
// raw.
|
||||
{atBreak: true, before: '\\d+', character: ')'},
|
||||
{character: ')', inConstruct: 'destinationRaw'},
|
||||
// An asterisk can start thematic breaks, list items, emphasis, strong.
|
||||
{atBreak: true, character: '*'},
|
||||
{character: '*', inConstruct: 'phrasing'},
|
||||
// A plus sign could start a list item.
|
||||
{atBreak: true, character: '+'},
|
||||
// A dash can start thematic breaks, list items, and setext heading
|
||||
// underlines.
|
||||
{atBreak: true, character: '-'},
|
||||
// A dot could start a list item.
|
||||
{atBreak: true, before: '\\d+', character: '.', after: '(?:[ \t\r\n]|$)'},
|
||||
// Slash, colon, and semicolon are not used in markdown for constructs.
|
||||
// A less than can start html (flow or text) or an autolink.
|
||||
// HTML could start with an exclamation mark (declaration, cdata, comment),
|
||||
// slash (closing tag), question mark (instruction), or a letter (tag).
|
||||
// An autolink also starts with a letter.
|
||||
// Finally, it could break out of a destination literal.
|
||||
{atBreak: true, character: '<', after: '[!/?A-Za-z]'},
|
||||
{character: '<', after: '[!/?A-Za-z]', inConstruct: 'phrasing'},
|
||||
{character: '<', inConstruct: 'destinationLiteral'},
|
||||
// An equals to can start setext heading underlines.
|
||||
{atBreak: true, character: '='},
|
||||
// A greater than can start block quotes and it can break out of a
|
||||
// destination literal.
|
||||
{atBreak: true, character: '>'},
|
||||
{character: '>', inConstruct: 'destinationLiteral'},
|
||||
// Question mark and at sign are not used in markdown for constructs.
|
||||
// A left bracket can start definitions, references, labels,
|
||||
{atBreak: true, character: '['},
|
||||
{character: '[', inConstruct: ['phrasing', 'label', 'reference']},
|
||||
// A backslash can start an escape (when followed by punctuation) or a
|
||||
// hard break (when followed by an eol).
|
||||
// Note: typical escapes are handled in `safe`!
|
||||
{character: '\\', after: '[\\r\\n]', inConstruct: 'phrasing'},
|
||||
// A right bracket can exit labels.
|
||||
{
|
||||
character: ']',
|
||||
inConstruct: ['label', 'reference']
|
||||
},
|
||||
// Caret is not used in markdown for constructs.
|
||||
// An underscore can start emphasis, strong, or a thematic break.
|
||||
{atBreak: true, character: '_'},
|
||||
{before: '[^A-Za-z]', character: '_', inConstruct: 'phrasing'},
|
||||
{character: '_', after: '[^A-Za-z]', inConstruct: 'phrasing'},
|
||||
// A grave accent can start code (fenced or text), or it can break out of
|
||||
// a grave accent code fence.
|
||||
{atBreak: true, character: '`'},
|
||||
{
|
||||
character: '`',
|
||||
inConstruct: [
|
||||
'codeFencedLangGraveAccent',
|
||||
'codeFencedMetaGraveAccent',
|
||||
'phrasing'
|
||||
]
|
||||
},
|
||||
// Left brace, vertical bar, right brace are not used in markdown for
|
||||
// constructs.
|
||||
// A tilde can start code (fenced).
|
||||
{atBreak: true, character: '~'}
|
||||
]
|
||||
30
node_modules/mdast-util-to-markdown/lib/util/association.js
generated
vendored
Normal file
30
node_modules/mdast-util-to-markdown/lib/util/association.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
module.exports = association
|
||||
|
||||
var decode = require('parse-entities/decode-entity')
|
||||
|
||||
var characterEscape = /\\([!-/:-@[-`{-~])/g
|
||||
var characterReference = /&(#(\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi
|
||||
|
||||
// The `label` of an association is the string value: character escapes and
|
||||
// references work, and casing is intact.
|
||||
// The `identifier` is used to match one association to another: controversially,
|
||||
// character escapes and references don’t work in this matching: `©` does
|
||||
// not match `©`, and `\+` does not match `+`.
|
||||
// But casing is ignored (and whitespace) is trimmed and collapsed: ` A\nb`
|
||||
// matches `a b`.
|
||||
// So, we do prefer the label when figuring out how we’re going to serialize:
|
||||
// it has whitespace, casing, and we can ignore most useless character escapes
|
||||
// and all character references.
|
||||
function association(node) {
|
||||
if (node.label || !node.identifier) {
|
||||
return node.label || ''
|
||||
}
|
||||
|
||||
return node.identifier
|
||||
.replace(characterEscape, '$1')
|
||||
.replace(characterReference, decodeIfPossible)
|
||||
}
|
||||
|
||||
function decodeIfPossible($0, $1) {
|
||||
return decode($1) || $0
|
||||
}
|
||||
15
node_modules/mdast-util-to-markdown/lib/util/check-bullet.js
generated
vendored
Normal file
15
node_modules/mdast-util-to-markdown/lib/util/check-bullet.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = checkBullet
|
||||
|
||||
function checkBullet(context) {
|
||||
var marker = context.options.bullet || '*'
|
||||
|
||||
if (marker !== '*' && marker !== '+' && marker !== '-') {
|
||||
throw new Error(
|
||||
'Cannot serialize items with `' +
|
||||
marker +
|
||||
'` for `options.bullet`, expected `*`, `+`, or `-`'
|
||||
)
|
||||
}
|
||||
|
||||
return marker
|
||||
}
|
||||
15
node_modules/mdast-util-to-markdown/lib/util/check-emphasis.js
generated
vendored
Normal file
15
node_modules/mdast-util-to-markdown/lib/util/check-emphasis.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = checkEmphasis
|
||||
|
||||
function checkEmphasis(context) {
|
||||
var marker = context.options.emphasis || '*'
|
||||
|
||||
if (marker !== '*' && marker !== '_') {
|
||||
throw new Error(
|
||||
'Cannot serialize emphasis with `' +
|
||||
marker +
|
||||
'` for `options.emphasis`, expected `*`, or `_`'
|
||||
)
|
||||
}
|
||||
|
||||
return marker
|
||||
}
|
||||
15
node_modules/mdast-util-to-markdown/lib/util/check-fence.js
generated
vendored
Normal file
15
node_modules/mdast-util-to-markdown/lib/util/check-fence.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = checkFence
|
||||
|
||||
function checkFence(context) {
|
||||
var marker = context.options.fence || '`'
|
||||
|
||||
if (marker !== '`' && marker !== '~') {
|
||||
throw new Error(
|
||||
'Cannot serialize code with `' +
|
||||
marker +
|
||||
'` for `options.fence`, expected `` ` `` or `~`'
|
||||
)
|
||||
}
|
||||
|
||||
return marker
|
||||
}
|
||||
19
node_modules/mdast-util-to-markdown/lib/util/check-list-item-indent.js
generated
vendored
Normal file
19
node_modules/mdast-util-to-markdown/lib/util/check-list-item-indent.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
module.exports = checkListItemIndent
|
||||
|
||||
function checkListItemIndent(context) {
|
||||
var style = context.options.listItemIndent || 'tab'
|
||||
|
||||
if (style === 1 || style === '1') {
|
||||
return 'one'
|
||||
}
|
||||
|
||||
if (style !== 'tab' && style !== 'one' && style !== 'mixed') {
|
||||
throw new Error(
|
||||
'Cannot serialize items with `' +
|
||||
style +
|
||||
'` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`'
|
||||
)
|
||||
}
|
||||
|
||||
return style
|
||||
}
|
||||
15
node_modules/mdast-util-to-markdown/lib/util/check-quote.js
generated
vendored
Normal file
15
node_modules/mdast-util-to-markdown/lib/util/check-quote.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = checkQuote
|
||||
|
||||
function checkQuote(context) {
|
||||
var marker = context.options.quote || '"'
|
||||
|
||||
if (marker !== '"' && marker !== "'") {
|
||||
throw new Error(
|
||||
'Cannot serialize title with `' +
|
||||
marker +
|
||||
'` for `options.quote`, expected `"`, or `\'`'
|
||||
)
|
||||
}
|
||||
|
||||
return marker
|
||||
}
|
||||
15
node_modules/mdast-util-to-markdown/lib/util/check-rule-repeat.js
generated
vendored
Normal file
15
node_modules/mdast-util-to-markdown/lib/util/check-rule-repeat.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = checkRule
|
||||
|
||||
function checkRule(context) {
|
||||
var repetition = context.options.ruleRepetition || 3
|
||||
|
||||
if (repetition < 3) {
|
||||
throw new Error(
|
||||
'Cannot serialize rules with repetition `' +
|
||||
repetition +
|
||||
'` for `options.ruleRepetition`, expected `3` or more'
|
||||
)
|
||||
}
|
||||
|
||||
return repetition
|
||||
}
|
||||
15
node_modules/mdast-util-to-markdown/lib/util/check-rule.js
generated
vendored
Normal file
15
node_modules/mdast-util-to-markdown/lib/util/check-rule.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = checkRule
|
||||
|
||||
function checkRule(context) {
|
||||
var marker = context.options.rule || '*'
|
||||
|
||||
if (marker !== '*' && marker !== '-' && marker !== '_') {
|
||||
throw new Error(
|
||||
'Cannot serialize rules with `' +
|
||||
marker +
|
||||
'` for `options.rule`, expected `*`, `-`, or `_`'
|
||||
)
|
||||
}
|
||||
|
||||
return marker
|
||||
}
|
||||
15
node_modules/mdast-util-to-markdown/lib/util/check-strong.js
generated
vendored
Normal file
15
node_modules/mdast-util-to-markdown/lib/util/check-strong.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = checkStrong
|
||||
|
||||
function checkStrong(context) {
|
||||
var marker = context.options.strong || '*'
|
||||
|
||||
if (marker !== '*' && marker !== '_') {
|
||||
throw new Error(
|
||||
'Cannot serialize strong with `' +
|
||||
marker +
|
||||
'` for `options.strong`, expected `*`, or `_`'
|
||||
)
|
||||
}
|
||||
|
||||
return marker
|
||||
}
|
||||
47
node_modules/mdast-util-to-markdown/lib/util/container-flow.js
generated
vendored
Normal file
47
node_modules/mdast-util-to-markdown/lib/util/container-flow.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
module.exports = flow
|
||||
|
||||
var repeat = require('repeat-string')
|
||||
|
||||
function flow(parent, context) {
|
||||
var children = parent.children || []
|
||||
var results = []
|
||||
var index = -1
|
||||
var child
|
||||
|
||||
while (++index < children.length) {
|
||||
child = children[index]
|
||||
|
||||
results.push(
|
||||
context.handle(child, parent, context, {before: '\n', after: '\n'})
|
||||
)
|
||||
|
||||
if (index + 1 < children.length) {
|
||||
results.push(between(child, children[index + 1]))
|
||||
}
|
||||
}
|
||||
|
||||
return results.join('')
|
||||
|
||||
function between(left, right) {
|
||||
var index = -1
|
||||
var result
|
||||
|
||||
while (++index < context.join.length) {
|
||||
result = context.join[index](left, right, parent, context)
|
||||
|
||||
if (result === true || result === 1) {
|
||||
break
|
||||
}
|
||||
|
||||
if (typeof result === 'number') {
|
||||
return repeat('\n', 1 + Number(result))
|
||||
}
|
||||
|
||||
if (result === false) {
|
||||
return '\n\n<!---->\n\n'
|
||||
}
|
||||
}
|
||||
|
||||
return '\n\n'
|
||||
}
|
||||
}
|
||||
57
node_modules/mdast-util-to-markdown/lib/util/container-phrasing.js
generated
vendored
Normal file
57
node_modules/mdast-util-to-markdown/lib/util/container-phrasing.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
module.exports = phrasing
|
||||
|
||||
function phrasing(parent, context, safeOptions) {
|
||||
var children = parent.children || []
|
||||
var results = []
|
||||
var index = -1
|
||||
var before = safeOptions.before
|
||||
var after
|
||||
var handle
|
||||
var child
|
||||
|
||||
while (++index < children.length) {
|
||||
child = children[index]
|
||||
|
||||
if (index + 1 < children.length) {
|
||||
handle = context.handle.handlers[children[index + 1].type]
|
||||
if (handle && handle.peek) handle = handle.peek
|
||||
after = handle
|
||||
? handle(children[index + 1], parent, context, {
|
||||
before: '',
|
||||
after: ''
|
||||
}).charAt(0)
|
||||
: ''
|
||||
} else {
|
||||
after = safeOptions.after
|
||||
}
|
||||
|
||||
// In some cases, html (text) can be found in phrasing right after an eol.
|
||||
// When we’d serialize that, in most cases that would be seen as html
|
||||
// (flow).
|
||||
// As we can’t escape or so to prevent it from happening, we take a somewhat
|
||||
// reasonable approach: replace that eol with a space.
|
||||
// See: <https://github.com/syntax-tree/mdast-util-to-markdown/issues/15>
|
||||
if (
|
||||
results.length > 0 &&
|
||||
(before === '\r' || before === '\n') &&
|
||||
child.type === 'html'
|
||||
) {
|
||||
results[results.length - 1] = results[results.length - 1].replace(
|
||||
/(\r?\n|\r)$/,
|
||||
' '
|
||||
)
|
||||
before = ' '
|
||||
}
|
||||
|
||||
results.push(
|
||||
context.handle(child, parent, context, {
|
||||
before: before,
|
||||
after: after
|
||||
})
|
||||
)
|
||||
|
||||
before = results[results.length - 1].slice(-1)
|
||||
}
|
||||
|
||||
return results.join('')
|
||||
}
|
||||
14
node_modules/mdast-util-to-markdown/lib/util/format-code-as-indented.js
generated
vendored
Normal file
14
node_modules/mdast-util-to-markdown/lib/util/format-code-as-indented.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
module.exports = formatCodeAsIndented
|
||||
|
||||
function formatCodeAsIndented(node, context) {
|
||||
return (
|
||||
!context.options.fences &&
|
||||
node.value &&
|
||||
// If there’s no info…
|
||||
!node.lang &&
|
||||
// And there’s a non-whitespace character…
|
||||
/[^ \r\n]/.test(node.value) &&
|
||||
// And the value doesn’t start or end in a blank…
|
||||
!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(node.value)
|
||||
)
|
||||
}
|
||||
9
node_modules/mdast-util-to-markdown/lib/util/format-heading-as-setext.js
generated
vendored
Normal file
9
node_modules/mdast-util-to-markdown/lib/util/format-heading-as-setext.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = formatHeadingAsSetext
|
||||
|
||||
var toString = require('mdast-util-to-string')
|
||||
|
||||
function formatHeadingAsSetext(node, context) {
|
||||
return (
|
||||
context.options.setext && (!node.depth || node.depth < 3) && toString(node)
|
||||
)
|
||||
}
|
||||
26
node_modules/mdast-util-to-markdown/lib/util/format-link-as-autolink.js
generated
vendored
Normal file
26
node_modules/mdast-util-to-markdown/lib/util/format-link-as-autolink.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
module.exports = formatLinkAsAutolink
|
||||
|
||||
var toString = require('mdast-util-to-string')
|
||||
|
||||
function formatLinkAsAutolink(node, context) {
|
||||
var raw = toString(node)
|
||||
|
||||
return (
|
||||
!context.options.resourceLink &&
|
||||
// If there’s a url…
|
||||
node.url &&
|
||||
// And there’s a no title…
|
||||
!node.title &&
|
||||
// And the content of `node` is a single text node…
|
||||
node.children &&
|
||||
node.children.length === 1 &&
|
||||
node.children[0].type === 'text' &&
|
||||
// And if the url is the same as the content…
|
||||
(raw === node.url || 'mailto:' + raw === node.url) &&
|
||||
// And that starts w/ a protocol…
|
||||
/^[a-z][a-z+.-]+:/i.test(node.url) &&
|
||||
// And that doesn’t contain ASCII control codes (character escapes and
|
||||
// references don’t work) or angle brackets…
|
||||
!/[\0- <>\u007F]/.test(node.url)
|
||||
)
|
||||
}
|
||||
25
node_modules/mdast-util-to-markdown/lib/util/indent-lines.js
generated
vendored
Normal file
25
node_modules/mdast-util-to-markdown/lib/util/indent-lines.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
module.exports = indentLines
|
||||
|
||||
var eol = /\r?\n|\r/g
|
||||
|
||||
function indentLines(value, map) {
|
||||
var result = []
|
||||
var start = 0
|
||||
var line = 0
|
||||
var match
|
||||
|
||||
while ((match = eol.exec(value))) {
|
||||
one(value.slice(start, match.index))
|
||||
result.push(match[0])
|
||||
start = match.index + match[0].length
|
||||
line++
|
||||
}
|
||||
|
||||
one(value.slice(start))
|
||||
|
||||
return result.join('')
|
||||
|
||||
function one(value) {
|
||||
result.push(map(value, line, !value))
|
||||
}
|
||||
}
|
||||
25
node_modules/mdast-util-to-markdown/lib/util/pattern-compile.js
generated
vendored
Normal file
25
node_modules/mdast-util-to-markdown/lib/util/pattern-compile.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
module.exports = patternCompile
|
||||
|
||||
function patternCompile(pattern) {
|
||||
var before
|
||||
var after
|
||||
|
||||
if (!pattern._compiled) {
|
||||
before = pattern.before ? '(?:' + pattern.before + ')' : ''
|
||||
after = pattern.after ? '(?:' + pattern.after + ')' : ''
|
||||
|
||||
if (pattern.atBreak) {
|
||||
before = '[\\r\\n][\\t ]*' + before
|
||||
}
|
||||
|
||||
pattern._compiled = new RegExp(
|
||||
(before ? '(' + before + ')' : '') +
|
||||
(/[|\\{}()[\]^$+*?.-]/.test(pattern.character) ? '\\' : '') +
|
||||
pattern.character +
|
||||
(after || ''),
|
||||
'g'
|
||||
)
|
||||
}
|
||||
|
||||
return pattern._compiled
|
||||
}
|
||||
30
node_modules/mdast-util-to-markdown/lib/util/pattern-in-scope.js
generated
vendored
Normal file
30
node_modules/mdast-util-to-markdown/lib/util/pattern-in-scope.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
module.exports = patternInScope
|
||||
|
||||
function patternInScope(stack, pattern) {
|
||||
return (
|
||||
listInScope(stack, pattern.inConstruct, true) &&
|
||||
!listInScope(stack, pattern.notInConstruct)
|
||||
)
|
||||
}
|
||||
|
||||
function listInScope(stack, list, none) {
|
||||
var index
|
||||
|
||||
if (!list) {
|
||||
return none
|
||||
}
|
||||
|
||||
if (typeof list === 'string') {
|
||||
list = [list]
|
||||
}
|
||||
|
||||
index = -1
|
||||
|
||||
while (++index < list.length) {
|
||||
if (stack.indexOf(list[index]) !== -1) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
139
node_modules/mdast-util-to-markdown/lib/util/safe.js
generated
vendored
Normal file
139
node_modules/mdast-util-to-markdown/lib/util/safe.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
module.exports = safe
|
||||
|
||||
var patternCompile = require('./pattern-compile')
|
||||
var patternInScope = require('./pattern-in-scope')
|
||||
|
||||
function safe(context, input, config) {
|
||||
var value = (config.before || '') + (input || '') + (config.after || '')
|
||||
var positions = []
|
||||
var result = []
|
||||
var infos = {}
|
||||
var index = -1
|
||||
var before
|
||||
var after
|
||||
var position
|
||||
var pattern
|
||||
var expression
|
||||
var match
|
||||
var start
|
||||
var end
|
||||
|
||||
while (++index < context.unsafe.length) {
|
||||
pattern = context.unsafe[index]
|
||||
|
||||
if (!patternInScope(context.stack, pattern)) {
|
||||
continue
|
||||
}
|
||||
|
||||
expression = patternCompile(pattern)
|
||||
|
||||
while ((match = expression.exec(value))) {
|
||||
before = 'before' in pattern || pattern.atBreak
|
||||
after = 'after' in pattern
|
||||
|
||||
position = match.index + (before ? match[1].length : 0)
|
||||
|
||||
if (positions.indexOf(position) === -1) {
|
||||
positions.push(position)
|
||||
infos[position] = {before: before, after: after}
|
||||
} else {
|
||||
if (infos[position].before && !before) {
|
||||
infos[position].before = false
|
||||
}
|
||||
|
||||
if (infos[position].after && !after) {
|
||||
infos[position].after = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
positions.sort(numerical)
|
||||
|
||||
start = config.before ? config.before.length : 0
|
||||
end = value.length - (config.after ? config.after.length : 0)
|
||||
index = -1
|
||||
|
||||
while (++index < positions.length) {
|
||||
position = positions[index]
|
||||
|
||||
if (
|
||||
// Character before or after matched:
|
||||
position < start ||
|
||||
position >= end
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
// If this character is supposed to be escaped because it has a condition on
|
||||
// the next character, and the next character is definitly being escaped,
|
||||
// then skip this escape.
|
||||
if (
|
||||
position + 1 < end &&
|
||||
positions[index + 1] === position + 1 &&
|
||||
infos[position].after &&
|
||||
!infos[position + 1].before &&
|
||||
!infos[position + 1].after
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (start !== position) {
|
||||
// If we have to use a character reference, an ampersand would be more
|
||||
// correct, but as backslashes only care about punctuation, either will
|
||||
// do the trick
|
||||
result.push(escapeBackslashes(value.slice(start, position), '\\'))
|
||||
}
|
||||
|
||||
start = position
|
||||
|
||||
if (
|
||||
/[!-/:-@[-`{-~]/.test(value.charAt(position)) &&
|
||||
(!config.encode || config.encode.indexOf(value.charAt(position)) === -1)
|
||||
) {
|
||||
// Character escape.
|
||||
result.push('\\')
|
||||
} else {
|
||||
// Character reference.
|
||||
result.push(
|
||||
'&#x' + value.charCodeAt(position).toString(16).toUpperCase() + ';'
|
||||
)
|
||||
start++
|
||||
}
|
||||
}
|
||||
|
||||
result.push(escapeBackslashes(value.slice(start, end), config.after))
|
||||
|
||||
return result.join('')
|
||||
}
|
||||
|
||||
function numerical(a, b) {
|
||||
return a - b
|
||||
}
|
||||
|
||||
function escapeBackslashes(value, after) {
|
||||
var expression = /\\(?=[!-/:-@[-`{-~])/g
|
||||
var positions = []
|
||||
var results = []
|
||||
var index = -1
|
||||
var start = 0
|
||||
var whole = value + after
|
||||
var match
|
||||
|
||||
while ((match = expression.exec(whole))) {
|
||||
positions.push(match.index)
|
||||
}
|
||||
|
||||
while (++index < positions.length) {
|
||||
if (start !== positions[index]) {
|
||||
results.push(value.slice(start, positions[index]))
|
||||
}
|
||||
|
||||
results.push('\\')
|
||||
start = positions[index]
|
||||
}
|
||||
|
||||
results.push(value.slice(start))
|
||||
|
||||
return results.join('')
|
||||
}
|
||||
Reference in New Issue
Block a user