This commit is contained in:
823
node_modules/mdast-util-from-markdown/dist/index.js
generated
vendored
Normal file
823
node_modules/mdast-util-from-markdown/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,823 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = fromMarkdown
|
||||
|
||||
// These three are compiled away in the `dist/`
|
||||
|
||||
var toString = require('mdast-util-to-string')
|
||||
var assign = require('micromark/dist/constant/assign')
|
||||
var own = require('micromark/dist/constant/has-own-property')
|
||||
var normalizeIdentifier = require('micromark/dist/util/normalize-identifier')
|
||||
var safeFromInt = require('micromark/dist/util/safe-from-int')
|
||||
var parser = require('micromark/dist/parse')
|
||||
var preprocessor = require('micromark/dist/preprocess')
|
||||
var postprocess = require('micromark/dist/postprocess')
|
||||
var decode = require('parse-entities/decode-entity')
|
||||
var stringifyPosition = require('unist-util-stringify-position')
|
||||
|
||||
function fromMarkdown(value, encoding, options) {
|
||||
if (typeof encoding !== 'string') {
|
||||
options = encoding
|
||||
encoding = undefined
|
||||
}
|
||||
|
||||
return compiler(options)(
|
||||
postprocess(
|
||||
parser(options).document().write(preprocessor()(value, encoding, true))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Note this compiler only understand complete buffering, not streaming.
|
||||
function compiler(options) {
|
||||
var settings = options || {}
|
||||
var config = configure(
|
||||
{
|
||||
transforms: [],
|
||||
canContainEols: [
|
||||
'emphasis',
|
||||
'fragment',
|
||||
'heading',
|
||||
'paragraph',
|
||||
'strong'
|
||||
],
|
||||
|
||||
enter: {
|
||||
autolink: opener(link),
|
||||
autolinkProtocol: onenterdata,
|
||||
autolinkEmail: onenterdata,
|
||||
atxHeading: opener(heading),
|
||||
blockQuote: opener(blockQuote),
|
||||
characterEscape: onenterdata,
|
||||
characterReference: onenterdata,
|
||||
codeFenced: opener(codeFlow),
|
||||
codeFencedFenceInfo: buffer,
|
||||
codeFencedFenceMeta: buffer,
|
||||
codeIndented: opener(codeFlow, buffer),
|
||||
codeText: opener(codeText, buffer),
|
||||
codeTextData: onenterdata,
|
||||
data: onenterdata,
|
||||
codeFlowValue: onenterdata,
|
||||
definition: opener(definition),
|
||||
definitionDestinationString: buffer,
|
||||
definitionLabelString: buffer,
|
||||
definitionTitleString: buffer,
|
||||
emphasis: opener(emphasis),
|
||||
hardBreakEscape: opener(hardBreak),
|
||||
hardBreakTrailing: opener(hardBreak),
|
||||
htmlFlow: opener(html, buffer),
|
||||
htmlFlowData: onenterdata,
|
||||
htmlText: opener(html, buffer),
|
||||
htmlTextData: onenterdata,
|
||||
image: opener(image),
|
||||
label: buffer,
|
||||
link: opener(link),
|
||||
listItem: opener(listItem),
|
||||
listItemValue: onenterlistitemvalue,
|
||||
listOrdered: opener(list, onenterlistordered),
|
||||
listUnordered: opener(list),
|
||||
paragraph: opener(paragraph),
|
||||
reference: onenterreference,
|
||||
referenceString: buffer,
|
||||
resourceDestinationString: buffer,
|
||||
resourceTitleString: buffer,
|
||||
setextHeading: opener(heading),
|
||||
strong: opener(strong),
|
||||
thematicBreak: opener(thematicBreak)
|
||||
},
|
||||
|
||||
exit: {
|
||||
atxHeading: closer(),
|
||||
atxHeadingSequence: onexitatxheadingsequence,
|
||||
autolink: closer(),
|
||||
autolinkEmail: onexitautolinkemail,
|
||||
autolinkProtocol: onexitautolinkprotocol,
|
||||
blockQuote: closer(),
|
||||
characterEscapeValue: onexitdata,
|
||||
characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker,
|
||||
characterReferenceMarkerNumeric: onexitcharacterreferencemarker,
|
||||
characterReferenceValue: onexitcharacterreferencevalue,
|
||||
codeFenced: closer(onexitcodefenced),
|
||||
codeFencedFence: onexitcodefencedfence,
|
||||
codeFencedFenceInfo: onexitcodefencedfenceinfo,
|
||||
codeFencedFenceMeta: onexitcodefencedfencemeta,
|
||||
codeFlowValue: onexitdata,
|
||||
codeIndented: closer(onexitcodeindented),
|
||||
codeText: closer(onexitcodetext),
|
||||
codeTextData: onexitdata,
|
||||
data: onexitdata,
|
||||
definition: closer(),
|
||||
definitionDestinationString: onexitdefinitiondestinationstring,
|
||||
definitionLabelString: onexitdefinitionlabelstring,
|
||||
definitionTitleString: onexitdefinitiontitlestring,
|
||||
emphasis: closer(),
|
||||
hardBreakEscape: closer(onexithardbreak),
|
||||
hardBreakTrailing: closer(onexithardbreak),
|
||||
htmlFlow: closer(onexithtmlflow),
|
||||
htmlFlowData: onexitdata,
|
||||
htmlText: closer(onexithtmltext),
|
||||
htmlTextData: onexitdata,
|
||||
image: closer(onexitimage),
|
||||
label: onexitlabel,
|
||||
labelText: onexitlabeltext,
|
||||
lineEnding: onexitlineending,
|
||||
link: closer(onexitlink),
|
||||
listItem: closer(),
|
||||
listOrdered: closer(),
|
||||
listUnordered: closer(),
|
||||
paragraph: closer(),
|
||||
referenceString: onexitreferencestring,
|
||||
resourceDestinationString: onexitresourcedestinationstring,
|
||||
resourceTitleString: onexitresourcetitlestring,
|
||||
resource: onexitresource,
|
||||
setextHeading: closer(onexitsetextheading),
|
||||
setextHeadingLineSequence: onexitsetextheadinglinesequence,
|
||||
setextHeadingText: onexitsetextheadingtext,
|
||||
strong: closer(),
|
||||
thematicBreak: closer()
|
||||
}
|
||||
},
|
||||
|
||||
settings.mdastExtensions || []
|
||||
)
|
||||
|
||||
var data = {}
|
||||
|
||||
return compile
|
||||
|
||||
function compile(events) {
|
||||
var tree = {type: 'root', children: []}
|
||||
var stack = [tree]
|
||||
var tokenStack = []
|
||||
var listStack = []
|
||||
var index = -1
|
||||
var handler
|
||||
var listStart
|
||||
|
||||
var context = {
|
||||
stack: stack,
|
||||
tokenStack: tokenStack,
|
||||
config: config,
|
||||
enter: enter,
|
||||
exit: exit,
|
||||
buffer: buffer,
|
||||
resume: resume,
|
||||
setData: setData,
|
||||
getData: getData
|
||||
}
|
||||
|
||||
while (++index < events.length) {
|
||||
// We preprocess lists to add `listItem` tokens, and to infer whether
|
||||
// items the list itself are spread out.
|
||||
if (
|
||||
events[index][1].type === 'listOrdered' ||
|
||||
events[index][1].type === 'listUnordered'
|
||||
) {
|
||||
if (events[index][0] === 'enter') {
|
||||
listStack.push(index)
|
||||
} else {
|
||||
listStart = listStack.pop(index)
|
||||
index = prepareList(events, listStart, index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
index = -1
|
||||
|
||||
while (++index < events.length) {
|
||||
handler = config[events[index][0]]
|
||||
|
||||
if (own.call(handler, events[index][1].type)) {
|
||||
handler[events[index][1].type].call(
|
||||
assign({sliceSerialize: events[index][2].sliceSerialize}, context),
|
||||
events[index][1]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (tokenStack.length) {
|
||||
throw new Error(
|
||||
'Cannot close document, a token (`' +
|
||||
tokenStack[tokenStack.length - 1].type +
|
||||
'`, ' +
|
||||
stringifyPosition({
|
||||
start: tokenStack[tokenStack.length - 1].start,
|
||||
end: tokenStack[tokenStack.length - 1].end
|
||||
}) +
|
||||
') is still open'
|
||||
)
|
||||
}
|
||||
|
||||
// Figure out `root` position.
|
||||
tree.position = {
|
||||
start: point(
|
||||
events.length ? events[0][1].start : {line: 1, column: 1, offset: 0}
|
||||
),
|
||||
|
||||
end: point(
|
||||
events.length
|
||||
? events[events.length - 2][1].end
|
||||
: {line: 1, column: 1, offset: 0}
|
||||
)
|
||||
}
|
||||
|
||||
index = -1
|
||||
while (++index < config.transforms.length) {
|
||||
tree = config.transforms[index](tree) || tree
|
||||
}
|
||||
|
||||
return tree
|
||||
}
|
||||
|
||||
function prepareList(events, start, length) {
|
||||
var index = start - 1
|
||||
var containerBalance = -1
|
||||
var listSpread = false
|
||||
var listItem
|
||||
var tailIndex
|
||||
var lineIndex
|
||||
var tailEvent
|
||||
var event
|
||||
var firstBlankLineIndex
|
||||
var atMarker
|
||||
|
||||
while (++index <= length) {
|
||||
event = events[index]
|
||||
|
||||
if (
|
||||
event[1].type === 'listUnordered' ||
|
||||
event[1].type === 'listOrdered' ||
|
||||
event[1].type === 'blockQuote'
|
||||
) {
|
||||
if (event[0] === 'enter') {
|
||||
containerBalance++
|
||||
} else {
|
||||
containerBalance--
|
||||
}
|
||||
|
||||
atMarker = undefined
|
||||
} else if (event[1].type === 'lineEndingBlank') {
|
||||
if (event[0] === 'enter') {
|
||||
if (
|
||||
listItem &&
|
||||
!atMarker &&
|
||||
!containerBalance &&
|
||||
!firstBlankLineIndex
|
||||
) {
|
||||
firstBlankLineIndex = index
|
||||
}
|
||||
|
||||
atMarker = undefined
|
||||
}
|
||||
} else if (
|
||||
event[1].type === 'linePrefix' ||
|
||||
event[1].type === 'listItemValue' ||
|
||||
event[1].type === 'listItemMarker' ||
|
||||
event[1].type === 'listItemPrefix' ||
|
||||
event[1].type === 'listItemPrefixWhitespace'
|
||||
) {
|
||||
// Empty.
|
||||
} else {
|
||||
atMarker = undefined
|
||||
}
|
||||
|
||||
if (
|
||||
(!containerBalance &&
|
||||
event[0] === 'enter' &&
|
||||
event[1].type === 'listItemPrefix') ||
|
||||
(containerBalance === -1 &&
|
||||
event[0] === 'exit' &&
|
||||
(event[1].type === 'listUnordered' ||
|
||||
event[1].type === 'listOrdered'))
|
||||
) {
|
||||
if (listItem) {
|
||||
tailIndex = index
|
||||
lineIndex = undefined
|
||||
|
||||
while (tailIndex--) {
|
||||
tailEvent = events[tailIndex]
|
||||
|
||||
if (
|
||||
tailEvent[1].type === 'lineEnding' ||
|
||||
tailEvent[1].type === 'lineEndingBlank'
|
||||
) {
|
||||
if (tailEvent[0] === 'exit') continue
|
||||
|
||||
if (lineIndex) {
|
||||
events[lineIndex][1].type = 'lineEndingBlank'
|
||||
listSpread = true
|
||||
}
|
||||
|
||||
tailEvent[1].type = 'lineEnding'
|
||||
lineIndex = tailIndex
|
||||
} else if (
|
||||
tailEvent[1].type === 'linePrefix' ||
|
||||
tailEvent[1].type === 'blockQuotePrefix' ||
|
||||
tailEvent[1].type === 'blockQuotePrefixWhitespace' ||
|
||||
tailEvent[1].type === 'blockQuoteMarker' ||
|
||||
tailEvent[1].type === 'listItemIndent'
|
||||
) {
|
||||
// Empty
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
firstBlankLineIndex &&
|
||||
(!lineIndex || firstBlankLineIndex < lineIndex)
|
||||
) {
|
||||
listItem._spread = true
|
||||
}
|
||||
|
||||
// Fix position.
|
||||
listItem.end = point(
|
||||
lineIndex ? events[lineIndex][1].start : event[1].end
|
||||
)
|
||||
|
||||
events.splice(lineIndex || index, 0, ['exit', listItem, event[2]])
|
||||
index++
|
||||
length++
|
||||
}
|
||||
|
||||
// Create a new list item.
|
||||
if (event[1].type === 'listItemPrefix') {
|
||||
listItem = {
|
||||
type: 'listItem',
|
||||
_spread: false,
|
||||
start: point(event[1].start)
|
||||
}
|
||||
|
||||
events.splice(index, 0, ['enter', listItem, event[2]])
|
||||
index++
|
||||
length++
|
||||
firstBlankLineIndex = undefined
|
||||
atMarker = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
events[start][1]._spread = listSpread
|
||||
return length
|
||||
}
|
||||
|
||||
function setData(key, value) {
|
||||
data[key] = value
|
||||
}
|
||||
|
||||
function getData(key) {
|
||||
return data[key]
|
||||
}
|
||||
|
||||
function point(d) {
|
||||
return {line: d.line, column: d.column, offset: d.offset}
|
||||
}
|
||||
|
||||
function opener(create, and) {
|
||||
return open
|
||||
|
||||
function open(token) {
|
||||
enter.call(this, create(token), token)
|
||||
if (and) and.call(this, token)
|
||||
}
|
||||
}
|
||||
|
||||
function buffer() {
|
||||
this.stack.push({type: 'fragment', children: []})
|
||||
}
|
||||
|
||||
function enter(node, token) {
|
||||
this.stack[this.stack.length - 1].children.push(node)
|
||||
this.stack.push(node)
|
||||
this.tokenStack.push(token)
|
||||
node.position = {start: point(token.start)}
|
||||
return node
|
||||
}
|
||||
|
||||
function closer(and) {
|
||||
return close
|
||||
|
||||
function close(token) {
|
||||
if (and) and.call(this, token)
|
||||
exit.call(this, token)
|
||||
}
|
||||
}
|
||||
|
||||
function exit(token) {
|
||||
var node = this.stack.pop()
|
||||
var open = this.tokenStack.pop()
|
||||
|
||||
if (!open) {
|
||||
throw new Error(
|
||||
'Cannot close `' +
|
||||
token.type +
|
||||
'` (' +
|
||||
stringifyPosition({start: token.start, end: token.end}) +
|
||||
'): it’s not open'
|
||||
)
|
||||
} else if (open.type !== token.type) {
|
||||
throw new Error(
|
||||
'Cannot close `' +
|
||||
token.type +
|
||||
'` (' +
|
||||
stringifyPosition({start: token.start, end: token.end}) +
|
||||
'): a different token (`' +
|
||||
open.type +
|
||||
'`, ' +
|
||||
stringifyPosition({start: open.start, end: open.end}) +
|
||||
') is open'
|
||||
)
|
||||
}
|
||||
|
||||
node.position.end = point(token.end)
|
||||
return node
|
||||
}
|
||||
|
||||
function resume() {
|
||||
return toString(this.stack.pop())
|
||||
}
|
||||
|
||||
//
|
||||
// Handlers.
|
||||
//
|
||||
|
||||
function onenterlistordered() {
|
||||
setData('expectingFirstListItemValue', true)
|
||||
}
|
||||
|
||||
function onenterlistitemvalue(token) {
|
||||
if (getData('expectingFirstListItemValue')) {
|
||||
this.stack[this.stack.length - 2].start = parseInt(
|
||||
this.sliceSerialize(token),
|
||||
10
|
||||
)
|
||||
|
||||
setData('expectingFirstListItemValue')
|
||||
}
|
||||
}
|
||||
|
||||
function onexitcodefencedfenceinfo() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].lang = data
|
||||
}
|
||||
|
||||
function onexitcodefencedfencemeta() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].meta = data
|
||||
}
|
||||
|
||||
function onexitcodefencedfence() {
|
||||
// Exit if this is the closing fence.
|
||||
if (getData('flowCodeInside')) return
|
||||
this.buffer()
|
||||
setData('flowCodeInside', true)
|
||||
}
|
||||
|
||||
function onexitcodefenced() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data.replace(
|
||||
/^(\r?\n|\r)|(\r?\n|\r)$/g,
|
||||
''
|
||||
)
|
||||
|
||||
setData('flowCodeInside')
|
||||
}
|
||||
|
||||
function onexitcodeindented() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data
|
||||
}
|
||||
|
||||
function onexitdefinitionlabelstring(token) {
|
||||
// Discard label, use the source content instead.
|
||||
var label = this.resume()
|
||||
this.stack[this.stack.length - 1].label = label
|
||||
this.stack[this.stack.length - 1].identifier = normalizeIdentifier(
|
||||
this.sliceSerialize(token)
|
||||
).toLowerCase()
|
||||
}
|
||||
|
||||
function onexitdefinitiontitlestring() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].title = data
|
||||
}
|
||||
|
||||
function onexitdefinitiondestinationstring() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].url = data
|
||||
}
|
||||
|
||||
function onexitatxheadingsequence(token) {
|
||||
if (!this.stack[this.stack.length - 1].depth) {
|
||||
this.stack[this.stack.length - 1].depth = this.sliceSerialize(
|
||||
token
|
||||
).length
|
||||
}
|
||||
}
|
||||
|
||||
function onexitsetextheadingtext() {
|
||||
setData('setextHeadingSlurpLineEnding', true)
|
||||
}
|
||||
|
||||
function onexitsetextheadinglinesequence(token) {
|
||||
this.stack[this.stack.length - 1].depth =
|
||||
this.sliceSerialize(token).charCodeAt(0) === 61 ? 1 : 2
|
||||
}
|
||||
|
||||
function onexitsetextheading() {
|
||||
setData('setextHeadingSlurpLineEnding')
|
||||
}
|
||||
|
||||
function onenterdata(token) {
|
||||
var siblings = this.stack[this.stack.length - 1].children
|
||||
var tail = siblings[siblings.length - 1]
|
||||
|
||||
if (!tail || tail.type !== 'text') {
|
||||
// Add a new text node.
|
||||
tail = text()
|
||||
tail.position = {start: point(token.start)}
|
||||
this.stack[this.stack.length - 1].children.push(tail)
|
||||
}
|
||||
|
||||
this.stack.push(tail)
|
||||
}
|
||||
|
||||
function onexitdata(token) {
|
||||
var tail = this.stack.pop()
|
||||
tail.value += this.sliceSerialize(token)
|
||||
tail.position.end = point(token.end)
|
||||
}
|
||||
|
||||
function onexitlineending(token) {
|
||||
var context = this.stack[this.stack.length - 1]
|
||||
|
||||
// If we’re at a hard break, include the line ending in there.
|
||||
if (getData('atHardBreak')) {
|
||||
context.children[context.children.length - 1].position.end = point(
|
||||
token.end
|
||||
)
|
||||
|
||||
setData('atHardBreak')
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
!getData('setextHeadingSlurpLineEnding') &&
|
||||
config.canContainEols.indexOf(context.type) > -1
|
||||
) {
|
||||
onenterdata.call(this, token)
|
||||
onexitdata.call(this, token)
|
||||
}
|
||||
}
|
||||
|
||||
function onexithardbreak() {
|
||||
setData('atHardBreak', true)
|
||||
}
|
||||
|
||||
function onexithtmlflow() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data
|
||||
}
|
||||
|
||||
function onexithtmltext() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data
|
||||
}
|
||||
|
||||
function onexitcodetext() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data
|
||||
}
|
||||
|
||||
function onexitlink() {
|
||||
var context = this.stack[this.stack.length - 1]
|
||||
|
||||
// To do: clean.
|
||||
if (getData('inReference')) {
|
||||
context.type += 'Reference'
|
||||
context.referenceType = getData('referenceType') || 'shortcut'
|
||||
delete context.url
|
||||
delete context.title
|
||||
} else {
|
||||
delete context.identifier
|
||||
delete context.label
|
||||
delete context.referenceType
|
||||
}
|
||||
|
||||
setData('referenceType')
|
||||
}
|
||||
|
||||
function onexitimage() {
|
||||
var context = this.stack[this.stack.length - 1]
|
||||
|
||||
// To do: clean.
|
||||
if (getData('inReference')) {
|
||||
context.type += 'Reference'
|
||||
context.referenceType = getData('referenceType') || 'shortcut'
|
||||
delete context.url
|
||||
delete context.title
|
||||
} else {
|
||||
delete context.identifier
|
||||
delete context.label
|
||||
delete context.referenceType
|
||||
}
|
||||
|
||||
setData('referenceType')
|
||||
}
|
||||
|
||||
function onexitlabeltext(token) {
|
||||
this.stack[this.stack.length - 2].identifier = normalizeIdentifier(
|
||||
this.sliceSerialize(token)
|
||||
).toLowerCase()
|
||||
}
|
||||
|
||||
function onexitlabel() {
|
||||
var fragment = this.stack[this.stack.length - 1]
|
||||
var value = this.resume()
|
||||
|
||||
this.stack[this.stack.length - 1].label = value
|
||||
|
||||
// Assume a reference.
|
||||
setData('inReference', true)
|
||||
|
||||
if (this.stack[this.stack.length - 1].type === 'link') {
|
||||
this.stack[this.stack.length - 1].children = fragment.children
|
||||
} else {
|
||||
this.stack[this.stack.length - 1].alt = value
|
||||
}
|
||||
}
|
||||
|
||||
function onexitresourcedestinationstring() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].url = data
|
||||
}
|
||||
|
||||
function onexitresourcetitlestring() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].title = data
|
||||
}
|
||||
|
||||
function onexitresource() {
|
||||
setData('inReference')
|
||||
}
|
||||
|
||||
function onenterreference() {
|
||||
setData('referenceType', 'collapsed')
|
||||
}
|
||||
|
||||
function onexitreferencestring(token) {
|
||||
var label = this.resume()
|
||||
this.stack[this.stack.length - 1].label = label
|
||||
this.stack[this.stack.length - 1].identifier = normalizeIdentifier(
|
||||
this.sliceSerialize(token)
|
||||
).toLowerCase()
|
||||
setData('referenceType', 'full')
|
||||
}
|
||||
|
||||
function onexitcharacterreferencemarker(token) {
|
||||
setData('characterReferenceType', token.type)
|
||||
}
|
||||
|
||||
function onexitcharacterreferencevalue(token) {
|
||||
var data = this.sliceSerialize(token)
|
||||
var type = getData('characterReferenceType')
|
||||
var value
|
||||
var tail
|
||||
|
||||
if (type) {
|
||||
value = safeFromInt(
|
||||
data,
|
||||
type === 'characterReferenceMarkerNumeric' ? 10 : 16
|
||||
)
|
||||
|
||||
setData('characterReferenceType')
|
||||
} else {
|
||||
value = decode(data)
|
||||
}
|
||||
|
||||
tail = this.stack.pop()
|
||||
tail.value += value
|
||||
tail.position.end = point(token.end)
|
||||
}
|
||||
|
||||
function onexitautolinkprotocol(token) {
|
||||
onexitdata.call(this, token)
|
||||
this.stack[this.stack.length - 1].url = this.sliceSerialize(token)
|
||||
}
|
||||
|
||||
function onexitautolinkemail(token) {
|
||||
onexitdata.call(this, token)
|
||||
this.stack[this.stack.length - 1].url =
|
||||
'mailto:' + this.sliceSerialize(token)
|
||||
}
|
||||
|
||||
//
|
||||
// Creaters.
|
||||
//
|
||||
|
||||
function blockQuote() {
|
||||
return {type: 'blockquote', children: []}
|
||||
}
|
||||
|
||||
function codeFlow() {
|
||||
return {type: 'code', lang: null, meta: null, value: ''}
|
||||
}
|
||||
|
||||
function codeText() {
|
||||
return {type: 'inlineCode', value: ''}
|
||||
}
|
||||
|
||||
function definition() {
|
||||
return {
|
||||
type: 'definition',
|
||||
identifier: '',
|
||||
label: null,
|
||||
title: null,
|
||||
url: ''
|
||||
}
|
||||
}
|
||||
|
||||
function emphasis() {
|
||||
return {type: 'emphasis', children: []}
|
||||
}
|
||||
|
||||
function heading() {
|
||||
return {type: 'heading', depth: undefined, children: []}
|
||||
}
|
||||
|
||||
function hardBreak() {
|
||||
return {type: 'break'}
|
||||
}
|
||||
|
||||
function html() {
|
||||
return {type: 'html', value: ''}
|
||||
}
|
||||
|
||||
function image() {
|
||||
return {type: 'image', title: null, url: '', alt: null}
|
||||
}
|
||||
|
||||
function link() {
|
||||
return {type: 'link', title: null, url: '', children: []}
|
||||
}
|
||||
|
||||
function list(token) {
|
||||
return {
|
||||
type: 'list',
|
||||
ordered: token.type === 'listOrdered',
|
||||
start: null,
|
||||
spread: token._spread,
|
||||
children: []
|
||||
}
|
||||
}
|
||||
|
||||
function listItem(token) {
|
||||
return {
|
||||
type: 'listItem',
|
||||
spread: token._spread,
|
||||
checked: null,
|
||||
children: []
|
||||
}
|
||||
}
|
||||
|
||||
function paragraph() {
|
||||
return {type: 'paragraph', children: []}
|
||||
}
|
||||
|
||||
function strong() {
|
||||
return {type: 'strong', children: []}
|
||||
}
|
||||
|
||||
function text() {
|
||||
return {type: 'text', value: ''}
|
||||
}
|
||||
|
||||
function thematicBreak() {
|
||||
return {type: 'thematicBreak'}
|
||||
}
|
||||
}
|
||||
|
||||
function configure(config, extensions) {
|
||||
var index = -1
|
||||
|
||||
while (++index < extensions.length) {
|
||||
extension(config, extensions[index])
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
function extension(config, extension) {
|
||||
var key
|
||||
var left
|
||||
|
||||
for (key in extension) {
|
||||
left = own.call(config, key) ? config[key] : (config[key] = {})
|
||||
|
||||
if (key === 'canContainEols' || key === 'transforms') {
|
||||
config[key] = [].concat(left, extension[key])
|
||||
} else {
|
||||
Object.assign(left, extension[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
3
node_modules/mdast-util-from-markdown/index.js
generated
vendored
Normal file
3
node_modules/mdast-util-from-markdown/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = require('./dist')
|
||||
819
node_modules/mdast-util-from-markdown/lib/index.js
generated
vendored
Normal file
819
node_modules/mdast-util-from-markdown/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,819 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = fromMarkdown
|
||||
|
||||
// These three are compiled away in the `dist/`
|
||||
var codes = require('micromark/dist/character/codes')
|
||||
var constants = require('micromark/dist/constant/constants')
|
||||
var types = require('micromark/dist/constant/types')
|
||||
|
||||
var toString = require('mdast-util-to-string')
|
||||
var assign = require('micromark/dist/constant/assign')
|
||||
var own = require('micromark/dist/constant/has-own-property')
|
||||
var normalizeIdentifier = require('micromark/dist/util/normalize-identifier')
|
||||
var safeFromInt = require('micromark/dist/util/safe-from-int')
|
||||
var parser = require('micromark/dist/parse')
|
||||
var preprocessor = require('micromark/dist/preprocess')
|
||||
var postprocess = require('micromark/dist/postprocess')
|
||||
var decode = require('parse-entities/decode-entity')
|
||||
var stringifyPosition = require('unist-util-stringify-position')
|
||||
|
||||
function fromMarkdown(value, encoding, options) {
|
||||
if (typeof encoding !== 'string') {
|
||||
options = encoding
|
||||
encoding = undefined
|
||||
}
|
||||
|
||||
return compiler(options)(
|
||||
postprocess(
|
||||
parser(options).document().write(preprocessor()(value, encoding, true))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Note this compiler only understand complete buffering, not streaming.
|
||||
function compiler(options) {
|
||||
var settings = options || {}
|
||||
var config = configure(
|
||||
{
|
||||
transforms: [],
|
||||
canContainEols: [
|
||||
'emphasis',
|
||||
'fragment',
|
||||
'heading',
|
||||
'paragraph',
|
||||
'strong'
|
||||
],
|
||||
enter: {
|
||||
autolink: opener(link),
|
||||
autolinkProtocol: onenterdata,
|
||||
autolinkEmail: onenterdata,
|
||||
atxHeading: opener(heading),
|
||||
blockQuote: opener(blockQuote),
|
||||
characterEscape: onenterdata,
|
||||
characterReference: onenterdata,
|
||||
codeFenced: opener(codeFlow),
|
||||
codeFencedFenceInfo: buffer,
|
||||
codeFencedFenceMeta: buffer,
|
||||
codeIndented: opener(codeFlow, buffer),
|
||||
codeText: opener(codeText, buffer),
|
||||
codeTextData: onenterdata,
|
||||
data: onenterdata,
|
||||
codeFlowValue: onenterdata,
|
||||
definition: opener(definition),
|
||||
definitionDestinationString: buffer,
|
||||
definitionLabelString: buffer,
|
||||
definitionTitleString: buffer,
|
||||
emphasis: opener(emphasis),
|
||||
hardBreakEscape: opener(hardBreak),
|
||||
hardBreakTrailing: opener(hardBreak),
|
||||
htmlFlow: opener(html, buffer),
|
||||
htmlFlowData: onenterdata,
|
||||
htmlText: opener(html, buffer),
|
||||
htmlTextData: onenterdata,
|
||||
image: opener(image),
|
||||
label: buffer,
|
||||
link: opener(link),
|
||||
listItem: opener(listItem),
|
||||
listItemValue: onenterlistitemvalue,
|
||||
listOrdered: opener(list, onenterlistordered),
|
||||
listUnordered: opener(list),
|
||||
paragraph: opener(paragraph),
|
||||
reference: onenterreference,
|
||||
referenceString: buffer,
|
||||
resourceDestinationString: buffer,
|
||||
resourceTitleString: buffer,
|
||||
setextHeading: opener(heading),
|
||||
strong: opener(strong),
|
||||
thematicBreak: opener(thematicBreak)
|
||||
},
|
||||
exit: {
|
||||
atxHeading: closer(),
|
||||
atxHeadingSequence: onexitatxheadingsequence,
|
||||
autolink: closer(),
|
||||
autolinkEmail: onexitautolinkemail,
|
||||
autolinkProtocol: onexitautolinkprotocol,
|
||||
blockQuote: closer(),
|
||||
characterEscapeValue: onexitdata,
|
||||
characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker,
|
||||
characterReferenceMarkerNumeric: onexitcharacterreferencemarker,
|
||||
characterReferenceValue: onexitcharacterreferencevalue,
|
||||
codeFenced: closer(onexitcodefenced),
|
||||
codeFencedFence: onexitcodefencedfence,
|
||||
codeFencedFenceInfo: onexitcodefencedfenceinfo,
|
||||
codeFencedFenceMeta: onexitcodefencedfencemeta,
|
||||
codeFlowValue: onexitdata,
|
||||
codeIndented: closer(onexitcodeindented),
|
||||
codeText: closer(onexitcodetext),
|
||||
codeTextData: onexitdata,
|
||||
data: onexitdata,
|
||||
definition: closer(),
|
||||
definitionDestinationString: onexitdefinitiondestinationstring,
|
||||
definitionLabelString: onexitdefinitionlabelstring,
|
||||
definitionTitleString: onexitdefinitiontitlestring,
|
||||
emphasis: closer(),
|
||||
hardBreakEscape: closer(onexithardbreak),
|
||||
hardBreakTrailing: closer(onexithardbreak),
|
||||
htmlFlow: closer(onexithtmlflow),
|
||||
htmlFlowData: onexitdata,
|
||||
htmlText: closer(onexithtmltext),
|
||||
htmlTextData: onexitdata,
|
||||
image: closer(onexitimage),
|
||||
label: onexitlabel,
|
||||
labelText: onexitlabeltext,
|
||||
lineEnding: onexitlineending,
|
||||
link: closer(onexitlink),
|
||||
listItem: closer(),
|
||||
listOrdered: closer(),
|
||||
listUnordered: closer(),
|
||||
paragraph: closer(),
|
||||
referenceString: onexitreferencestring,
|
||||
resourceDestinationString: onexitresourcedestinationstring,
|
||||
resourceTitleString: onexitresourcetitlestring,
|
||||
resource: onexitresource,
|
||||
setextHeading: closer(onexitsetextheading),
|
||||
setextHeadingLineSequence: onexitsetextheadinglinesequence,
|
||||
setextHeadingText: onexitsetextheadingtext,
|
||||
strong: closer(),
|
||||
thematicBreak: closer()
|
||||
}
|
||||
},
|
||||
settings.mdastExtensions || []
|
||||
)
|
||||
|
||||
var data = {}
|
||||
|
||||
return compile
|
||||
|
||||
function compile(events) {
|
||||
var tree = {type: 'root', children: []}
|
||||
var stack = [tree]
|
||||
var tokenStack = []
|
||||
var listStack = []
|
||||
var index = -1
|
||||
var handler
|
||||
var listStart
|
||||
|
||||
var context = {
|
||||
stack: stack,
|
||||
tokenStack: tokenStack,
|
||||
config: config,
|
||||
enter: enter,
|
||||
exit: exit,
|
||||
buffer: buffer,
|
||||
resume: resume,
|
||||
setData: setData,
|
||||
getData: getData
|
||||
}
|
||||
|
||||
while (++index < events.length) {
|
||||
// We preprocess lists to add `listItem` tokens, and to infer whether
|
||||
// items the list itself are spread out.
|
||||
if (
|
||||
events[index][1].type === types.listOrdered ||
|
||||
events[index][1].type === types.listUnordered
|
||||
) {
|
||||
if (events[index][0] === 'enter') {
|
||||
listStack.push(index)
|
||||
} else {
|
||||
listStart = listStack.pop(index)
|
||||
index = prepareList(events, listStart, index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
index = -1
|
||||
|
||||
while (++index < events.length) {
|
||||
handler = config[events[index][0]]
|
||||
|
||||
if (own.call(handler, events[index][1].type)) {
|
||||
handler[events[index][1].type].call(
|
||||
assign({sliceSerialize: events[index][2].sliceSerialize}, context),
|
||||
events[index][1]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (tokenStack.length) {
|
||||
throw new Error(
|
||||
'Cannot close document, a token (`' +
|
||||
tokenStack[tokenStack.length - 1].type +
|
||||
'`, ' +
|
||||
stringifyPosition({
|
||||
start: tokenStack[tokenStack.length - 1].start,
|
||||
end: tokenStack[tokenStack.length - 1].end
|
||||
}) +
|
||||
') is still open'
|
||||
)
|
||||
}
|
||||
|
||||
// Figure out `root` position.
|
||||
tree.position = {
|
||||
start: point(
|
||||
events.length ? events[0][1].start : {line: 1, column: 1, offset: 0}
|
||||
),
|
||||
end: point(
|
||||
events.length
|
||||
? events[events.length - 2][1].end
|
||||
: {line: 1, column: 1, offset: 0}
|
||||
)
|
||||
}
|
||||
|
||||
index = -1
|
||||
while (++index < config.transforms.length) {
|
||||
tree = config.transforms[index](tree) || tree
|
||||
}
|
||||
|
||||
return tree
|
||||
}
|
||||
|
||||
function prepareList(events, start, length) {
|
||||
var index = start - 1
|
||||
var containerBalance = -1
|
||||
var listSpread = false
|
||||
var listItem
|
||||
var tailIndex
|
||||
var lineIndex
|
||||
var tailEvent
|
||||
var event
|
||||
var firstBlankLineIndex
|
||||
var atMarker
|
||||
|
||||
while (++index <= length) {
|
||||
event = events[index]
|
||||
|
||||
if (
|
||||
event[1].type === types.listUnordered ||
|
||||
event[1].type === types.listOrdered ||
|
||||
event[1].type === types.blockQuote
|
||||
) {
|
||||
if (event[0] === 'enter') {
|
||||
containerBalance++
|
||||
} else {
|
||||
containerBalance--
|
||||
}
|
||||
|
||||
atMarker = undefined
|
||||
} else if (event[1].type === types.lineEndingBlank) {
|
||||
if (event[0] === 'enter') {
|
||||
if (
|
||||
listItem &&
|
||||
!atMarker &&
|
||||
!containerBalance &&
|
||||
!firstBlankLineIndex
|
||||
) {
|
||||
firstBlankLineIndex = index
|
||||
}
|
||||
|
||||
atMarker = undefined
|
||||
}
|
||||
} else if (
|
||||
event[1].type === types.linePrefix ||
|
||||
event[1].type === types.listItemValue ||
|
||||
event[1].type === types.listItemMarker ||
|
||||
event[1].type === types.listItemPrefix ||
|
||||
event[1].type === types.listItemPrefixWhitespace
|
||||
) {
|
||||
// Empty.
|
||||
} else {
|
||||
atMarker = undefined
|
||||
}
|
||||
|
||||
if (
|
||||
(!containerBalance &&
|
||||
event[0] === 'enter' &&
|
||||
event[1].type === types.listItemPrefix) ||
|
||||
(containerBalance === -1 &&
|
||||
event[0] === 'exit' &&
|
||||
(event[1].type === types.listUnordered ||
|
||||
event[1].type === types.listOrdered))
|
||||
) {
|
||||
if (listItem) {
|
||||
tailIndex = index
|
||||
lineIndex = undefined
|
||||
|
||||
while (tailIndex--) {
|
||||
tailEvent = events[tailIndex]
|
||||
|
||||
if (
|
||||
tailEvent[1].type === types.lineEnding ||
|
||||
tailEvent[1].type === types.lineEndingBlank
|
||||
) {
|
||||
if (tailEvent[0] === 'exit') continue
|
||||
|
||||
if (lineIndex) {
|
||||
events[lineIndex][1].type = types.lineEndingBlank
|
||||
listSpread = true
|
||||
}
|
||||
|
||||
tailEvent[1].type = types.lineEnding
|
||||
lineIndex = tailIndex
|
||||
} else if (
|
||||
tailEvent[1].type === types.linePrefix ||
|
||||
tailEvent[1].type === types.blockQuotePrefix ||
|
||||
tailEvent[1].type === types.blockQuotePrefixWhitespace ||
|
||||
tailEvent[1].type === types.blockQuoteMarker ||
|
||||
tailEvent[1].type === types.listItemIndent
|
||||
) {
|
||||
// Empty
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
firstBlankLineIndex &&
|
||||
(!lineIndex || firstBlankLineIndex < lineIndex)
|
||||
) {
|
||||
listItem._spread = true
|
||||
}
|
||||
|
||||
// Fix position.
|
||||
listItem.end = point(
|
||||
lineIndex ? events[lineIndex][1].start : event[1].end
|
||||
)
|
||||
|
||||
events.splice(lineIndex || index, 0, ['exit', listItem, event[2]])
|
||||
index++
|
||||
length++
|
||||
}
|
||||
|
||||
// Create a new list item.
|
||||
if (event[1].type === types.listItemPrefix) {
|
||||
listItem = {
|
||||
type: 'listItem',
|
||||
_spread: false,
|
||||
start: point(event[1].start)
|
||||
}
|
||||
events.splice(index, 0, ['enter', listItem, event[2]])
|
||||
index++
|
||||
length++
|
||||
firstBlankLineIndex = undefined
|
||||
atMarker = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
events[start][1]._spread = listSpread
|
||||
return length
|
||||
}
|
||||
|
||||
function setData(key, value) {
|
||||
data[key] = value
|
||||
}
|
||||
|
||||
function getData(key) {
|
||||
return data[key]
|
||||
}
|
||||
|
||||
function point(d) {
|
||||
return {line: d.line, column: d.column, offset: d.offset}
|
||||
}
|
||||
|
||||
function opener(create, and) {
|
||||
return open
|
||||
|
||||
function open(token) {
|
||||
enter.call(this, create(token), token)
|
||||
if (and) and.call(this, token)
|
||||
}
|
||||
}
|
||||
|
||||
function buffer() {
|
||||
this.stack.push({type: 'fragment', children: []})
|
||||
}
|
||||
|
||||
function enter(node, token) {
|
||||
this.stack[this.stack.length - 1].children.push(node)
|
||||
this.stack.push(node)
|
||||
this.tokenStack.push(token)
|
||||
node.position = {start: point(token.start)}
|
||||
return node
|
||||
}
|
||||
|
||||
function closer(and) {
|
||||
return close
|
||||
|
||||
function close(token) {
|
||||
if (and) and.call(this, token)
|
||||
exit.call(this, token)
|
||||
}
|
||||
}
|
||||
|
||||
function exit(token) {
|
||||
var node = this.stack.pop()
|
||||
var open = this.tokenStack.pop()
|
||||
|
||||
if (!open) {
|
||||
throw new Error(
|
||||
'Cannot close `' +
|
||||
token.type +
|
||||
'` (' +
|
||||
stringifyPosition({start: token.start, end: token.end}) +
|
||||
'): it’s not open'
|
||||
)
|
||||
} else if (open.type !== token.type) {
|
||||
throw new Error(
|
||||
'Cannot close `' +
|
||||
token.type +
|
||||
'` (' +
|
||||
stringifyPosition({start: token.start, end: token.end}) +
|
||||
'): a different token (`' +
|
||||
open.type +
|
||||
'`, ' +
|
||||
stringifyPosition({start: open.start, end: open.end}) +
|
||||
') is open'
|
||||
)
|
||||
}
|
||||
|
||||
node.position.end = point(token.end)
|
||||
return node
|
||||
}
|
||||
|
||||
function resume() {
|
||||
return toString(this.stack.pop())
|
||||
}
|
||||
|
||||
//
|
||||
// Handlers.
|
||||
//
|
||||
|
||||
function onenterlistordered() {
|
||||
setData('expectingFirstListItemValue', true)
|
||||
}
|
||||
|
||||
function onenterlistitemvalue(token) {
|
||||
if (getData('expectingFirstListItemValue')) {
|
||||
this.stack[this.stack.length - 2].start = parseInt(
|
||||
this.sliceSerialize(token),
|
||||
constants.numericBaseDecimal
|
||||
)
|
||||
setData('expectingFirstListItemValue')
|
||||
}
|
||||
}
|
||||
|
||||
function onexitcodefencedfenceinfo() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].lang = data
|
||||
}
|
||||
|
||||
function onexitcodefencedfencemeta() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].meta = data
|
||||
}
|
||||
|
||||
function onexitcodefencedfence() {
|
||||
// Exit if this is the closing fence.
|
||||
if (getData('flowCodeInside')) return
|
||||
this.buffer()
|
||||
setData('flowCodeInside', true)
|
||||
}
|
||||
|
||||
function onexitcodefenced() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data.replace(
|
||||
/^(\r?\n|\r)|(\r?\n|\r)$/g,
|
||||
''
|
||||
)
|
||||
setData('flowCodeInside')
|
||||
}
|
||||
|
||||
function onexitcodeindented() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data
|
||||
}
|
||||
|
||||
function onexitdefinitionlabelstring(token) {
|
||||
// Discard label, use the source content instead.
|
||||
var label = this.resume()
|
||||
this.stack[this.stack.length - 1].label = label
|
||||
this.stack[this.stack.length - 1].identifier = normalizeIdentifier(
|
||||
this.sliceSerialize(token)
|
||||
).toLowerCase()
|
||||
}
|
||||
|
||||
function onexitdefinitiontitlestring() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].title = data
|
||||
}
|
||||
|
||||
function onexitdefinitiondestinationstring() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].url = data
|
||||
}
|
||||
|
||||
function onexitatxheadingsequence(token) {
|
||||
if (!this.stack[this.stack.length - 1].depth) {
|
||||
this.stack[this.stack.length - 1].depth = this.sliceSerialize(
|
||||
token
|
||||
).length
|
||||
}
|
||||
}
|
||||
|
||||
function onexitsetextheadingtext() {
|
||||
setData('setextHeadingSlurpLineEnding', true)
|
||||
}
|
||||
|
||||
function onexitsetextheadinglinesequence(token) {
|
||||
this.stack[this.stack.length - 1].depth =
|
||||
this.sliceSerialize(token).charCodeAt(0) === codes.equalsTo ? 1 : 2
|
||||
}
|
||||
|
||||
function onexitsetextheading() {
|
||||
setData('setextHeadingSlurpLineEnding')
|
||||
}
|
||||
|
||||
function onenterdata(token) {
|
||||
var siblings = this.stack[this.stack.length - 1].children
|
||||
var tail = siblings[siblings.length - 1]
|
||||
|
||||
if (!tail || tail.type !== 'text') {
|
||||
// Add a new text node.
|
||||
tail = text()
|
||||
tail.position = {start: point(token.start)}
|
||||
this.stack[this.stack.length - 1].children.push(tail)
|
||||
}
|
||||
|
||||
this.stack.push(tail)
|
||||
}
|
||||
|
||||
function onexitdata(token) {
|
||||
var tail = this.stack.pop()
|
||||
tail.value += this.sliceSerialize(token)
|
||||
tail.position.end = point(token.end)
|
||||
}
|
||||
|
||||
function onexitlineending(token) {
|
||||
var context = this.stack[this.stack.length - 1]
|
||||
|
||||
// If we’re at a hard break, include the line ending in there.
|
||||
if (getData('atHardBreak')) {
|
||||
context.children[context.children.length - 1].position.end = point(
|
||||
token.end
|
||||
)
|
||||
setData('atHardBreak')
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
!getData('setextHeadingSlurpLineEnding') &&
|
||||
config.canContainEols.indexOf(context.type) > -1
|
||||
) {
|
||||
onenterdata.call(this, token)
|
||||
onexitdata.call(this, token)
|
||||
}
|
||||
}
|
||||
|
||||
function onexithardbreak() {
|
||||
setData('atHardBreak', true)
|
||||
}
|
||||
|
||||
function onexithtmlflow() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data
|
||||
}
|
||||
|
||||
function onexithtmltext() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data
|
||||
}
|
||||
|
||||
function onexitcodetext() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].value = data
|
||||
}
|
||||
|
||||
function onexitlink() {
|
||||
var context = this.stack[this.stack.length - 1]
|
||||
|
||||
// To do: clean.
|
||||
if (getData('inReference')) {
|
||||
context.type += 'Reference'
|
||||
context.referenceType = getData('referenceType') || 'shortcut'
|
||||
delete context.url
|
||||
delete context.title
|
||||
} else {
|
||||
delete context.identifier
|
||||
delete context.label
|
||||
delete context.referenceType
|
||||
}
|
||||
|
||||
setData('referenceType')
|
||||
}
|
||||
|
||||
function onexitimage() {
|
||||
var context = this.stack[this.stack.length - 1]
|
||||
|
||||
// To do: clean.
|
||||
if (getData('inReference')) {
|
||||
context.type += 'Reference'
|
||||
context.referenceType = getData('referenceType') || 'shortcut'
|
||||
delete context.url
|
||||
delete context.title
|
||||
} else {
|
||||
delete context.identifier
|
||||
delete context.label
|
||||
delete context.referenceType
|
||||
}
|
||||
|
||||
setData('referenceType')
|
||||
}
|
||||
|
||||
function onexitlabeltext(token) {
|
||||
this.stack[this.stack.length - 2].identifier = normalizeIdentifier(
|
||||
this.sliceSerialize(token)
|
||||
).toLowerCase()
|
||||
}
|
||||
|
||||
function onexitlabel() {
|
||||
var fragment = this.stack[this.stack.length - 1]
|
||||
var value = this.resume()
|
||||
|
||||
this.stack[this.stack.length - 1].label = value
|
||||
|
||||
// Assume a reference.
|
||||
setData('inReference', true)
|
||||
|
||||
if (this.stack[this.stack.length - 1].type === 'link') {
|
||||
this.stack[this.stack.length - 1].children = fragment.children
|
||||
} else {
|
||||
this.stack[this.stack.length - 1].alt = value
|
||||
}
|
||||
}
|
||||
|
||||
function onexitresourcedestinationstring() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].url = data
|
||||
}
|
||||
|
||||
function onexitresourcetitlestring() {
|
||||
var data = this.resume()
|
||||
this.stack[this.stack.length - 1].title = data
|
||||
}
|
||||
|
||||
function onexitresource() {
|
||||
setData('inReference')
|
||||
}
|
||||
|
||||
function onenterreference() {
|
||||
setData('referenceType', 'collapsed')
|
||||
}
|
||||
|
||||
function onexitreferencestring(token) {
|
||||
var label = this.resume()
|
||||
this.stack[this.stack.length - 1].label = label
|
||||
this.stack[this.stack.length - 1].identifier = normalizeIdentifier(
|
||||
this.sliceSerialize(token)
|
||||
).toLowerCase()
|
||||
setData('referenceType', 'full')
|
||||
}
|
||||
|
||||
function onexitcharacterreferencemarker(token) {
|
||||
setData('characterReferenceType', token.type)
|
||||
}
|
||||
|
||||
function onexitcharacterreferencevalue(token) {
|
||||
var data = this.sliceSerialize(token)
|
||||
var type = getData('characterReferenceType')
|
||||
var value
|
||||
var tail
|
||||
|
||||
if (type) {
|
||||
value = safeFromInt(
|
||||
data,
|
||||
type === types.characterReferenceMarkerNumeric
|
||||
? constants.numericBaseDecimal
|
||||
: constants.numericBaseHexadecimal
|
||||
)
|
||||
setData('characterReferenceType')
|
||||
} else {
|
||||
value = decode(data)
|
||||
}
|
||||
|
||||
tail = this.stack.pop()
|
||||
tail.value += value
|
||||
tail.position.end = point(token.end)
|
||||
}
|
||||
|
||||
function onexitautolinkprotocol(token) {
|
||||
onexitdata.call(this, token)
|
||||
this.stack[this.stack.length - 1].url = this.sliceSerialize(token)
|
||||
}
|
||||
|
||||
function onexitautolinkemail(token) {
|
||||
onexitdata.call(this, token)
|
||||
this.stack[this.stack.length - 1].url =
|
||||
'mailto:' + this.sliceSerialize(token)
|
||||
}
|
||||
|
||||
//
|
||||
// Creaters.
|
||||
//
|
||||
|
||||
function blockQuote() {
|
||||
return {type: 'blockquote', children: []}
|
||||
}
|
||||
|
||||
function codeFlow() {
|
||||
return {type: 'code', lang: null, meta: null, value: ''}
|
||||
}
|
||||
|
||||
function codeText() {
|
||||
return {type: 'inlineCode', value: ''}
|
||||
}
|
||||
|
||||
function definition() {
|
||||
return {
|
||||
type: 'definition',
|
||||
identifier: '',
|
||||
label: null,
|
||||
title: null,
|
||||
url: ''
|
||||
}
|
||||
}
|
||||
|
||||
function emphasis() {
|
||||
return {type: 'emphasis', children: []}
|
||||
}
|
||||
|
||||
function heading() {
|
||||
return {type: 'heading', depth: undefined, children: []}
|
||||
}
|
||||
|
||||
function hardBreak() {
|
||||
return {type: 'break'}
|
||||
}
|
||||
|
||||
function html() {
|
||||
return {type: 'html', value: ''}
|
||||
}
|
||||
|
||||
function image() {
|
||||
return {type: 'image', title: null, url: '', alt: null}
|
||||
}
|
||||
|
||||
function link() {
|
||||
return {type: 'link', title: null, url: '', children: []}
|
||||
}
|
||||
|
||||
function list(token) {
|
||||
return {
|
||||
type: 'list',
|
||||
ordered: token.type === 'listOrdered',
|
||||
start: null,
|
||||
spread: token._spread,
|
||||
children: []
|
||||
}
|
||||
}
|
||||
|
||||
function listItem(token) {
|
||||
return {
|
||||
type: 'listItem',
|
||||
spread: token._spread,
|
||||
checked: null,
|
||||
children: []
|
||||
}
|
||||
}
|
||||
|
||||
function paragraph() {
|
||||
return {type: 'paragraph', children: []}
|
||||
}
|
||||
|
||||
function strong() {
|
||||
return {type: 'strong', children: []}
|
||||
}
|
||||
|
||||
function text() {
|
||||
return {type: 'text', value: ''}
|
||||
}
|
||||
|
||||
function thematicBreak() {
|
||||
return {type: 'thematicBreak'}
|
||||
}
|
||||
}
|
||||
|
||||
function configure(config, extensions) {
|
||||
var index = -1
|
||||
|
||||
while (++index < extensions.length) {
|
||||
extension(config, extensions[index])
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
function extension(config, extension) {
|
||||
var key
|
||||
var left
|
||||
|
||||
for (key in extension) {
|
||||
left = own.call(config, key) ? config[key] : (config[key] = {})
|
||||
|
||||
if (key === 'canContainEols' || key === 'transforms') {
|
||||
config[key] = [].concat(left, extension[key])
|
||||
} else {
|
||||
Object.assign(left, extension[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
22
node_modules/mdast-util-from-markdown/license
generated
vendored
Normal file
22
node_modules/mdast-util-from-markdown/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
29
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/index.js
generated
vendored
Normal file
29
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/index.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = toString
|
||||
|
||||
// Get the text content of a node.
|
||||
// Prefer the node’s plain-text fields, otherwise serialize its children,
|
||||
// and if the given value is an array, serialize the nodes in it.
|
||||
function toString(node) {
|
||||
return (
|
||||
(node &&
|
||||
(node.value ||
|
||||
node.alt ||
|
||||
node.title ||
|
||||
('children' in node && all(node.children)) ||
|
||||
('length' in node && all(node)))) ||
|
||||
''
|
||||
)
|
||||
}
|
||||
|
||||
function all(values) {
|
||||
var result = []
|
||||
var index = -1
|
||||
|
||||
while (++index < values.length) {
|
||||
result[index] = toString(values[index])
|
||||
}
|
||||
|
||||
return result.join('')
|
||||
}
|
||||
22
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/license
generated
vendored
Normal file
22
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
80
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/package.json
generated
vendored
Normal file
80
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/package.json
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"name": "mdast-util-to-string",
|
||||
"version": "2.0.0",
|
||||
"description": "mdast utility to get the plain text content of a node",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"mdast",
|
||||
"mdast-util",
|
||||
"util",
|
||||
"utility",
|
||||
"markdown",
|
||||
"node",
|
||||
"string",
|
||||
"serialize"
|
||||
],
|
||||
"repository": "syntax-tree/mdast-util-to-string",
|
||||
"bugs": "https://github.com/syntax-tree/mdast-util-to-string/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"index.js",
|
||||
"types/index.d.ts"
|
||||
],
|
||||
"types": "types/index.d.ts",
|
||||
"devDependencies": {
|
||||
"browserify": "^17.0.0",
|
||||
"dtslint": "^4.0.0",
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"tinyify": "^3.0.0",
|
||||
"xo": "^0.34.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"build-bundle": "browserify . -s mdastUtilToString -o mdast-util-to-string.js",
|
||||
"build-mangle": "browserify . -s mdastUtilToString -o mdast-util-to-string.min.js -p tinyify",
|
||||
"build": "npm run build-bundle && npm run build-mangle",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test.js",
|
||||
"test-types": "dtslint types",
|
||||
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"ignore": [
|
||||
"mdast-util-to-string.js",
|
||||
"types/test.ts"
|
||||
]
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
127
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/readme.md
generated
vendored
Normal file
127
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/readme.md
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
# mdast-util-to-string
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
**[mdast][]** utility to get the plain text content of a node.
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install mdast-util-to-string
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
var unified = require('unified')
|
||||
var parse = require('remark-parse')
|
||||
var toString = require('mdast-util-to-string')
|
||||
|
||||
var tree = unified()
|
||||
.use(parse)
|
||||
.parse('Some _emphasis_, **importance**, and `code`.')
|
||||
|
||||
console.log(toString(tree)) // => 'Some emphasis, importance, and code.'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `toString(node)`
|
||||
|
||||
Get the text content of a [node][] or list of nodes.
|
||||
|
||||
The algorithm checks `value` of `node`, then `alt`, and finally `title`.
|
||||
If no value is found, the algorithm checks the children of `node` and joins them
|
||||
(without spaces or newlines).
|
||||
|
||||
> This is not a markdown to plain-text library.
|
||||
> Use [`strip-markdown`][strip-markdown] for that.
|
||||
|
||||
## Security
|
||||
|
||||
Use of `mdast-util-to-string` does not involve **[hast][]**, user content, or
|
||||
change the tree, so there are no openings for [cross-site scripting (XSS)][xss]
|
||||
attacks.
|
||||
|
||||
## Related
|
||||
|
||||
* [`nlcst-to-string`](https://github.com/syntax-tree/nlcst-to-string)
|
||||
— Get text content in nlcst
|
||||
* [`hast-util-to-string`](https://github.com/wooorm/rehype-minify/tree/HEAD/packages/hast-util-to-string)
|
||||
— Get text content in hast
|
||||
* [`hast-util-to-text`](https://github.com/syntax-tree/hast-util-to-text)
|
||||
— Get text content in hast according to the `innerText` algorithm
|
||||
* [`hast-util-from-string`](https://github.com/wooorm/rehype-minify/tree/HEAD/packages/hast-util-from-string)
|
||||
— Set text content in hast
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
|
||||
started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organization, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/syntax-tree/mdast-util-to-string/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/mdast-util-to-string/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-to-string.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-to-string
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-to-string.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/mdast-util-to-string
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-to-string.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=mdast-util-to-string
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[chat]: https://github.com/syntax-tree/unist/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[mdast]: https://github.com/syntax-tree/mdast
|
||||
|
||||
[node]: https://github.com/syntax-tree/mdast#nodes
|
||||
|
||||
[strip-markdown]: https://github.com/remarkjs/strip-markdown
|
||||
|
||||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
|
||||
|
||||
[hast]: https://github.com/syntax-tree/hast
|
||||
8
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/types/index.d.ts
generated
vendored
Normal file
8
node_modules/mdast-util-from-markdown/node_modules/mdast-util-to-string/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// Minimum TypeScript Version: 3.0
|
||||
import {Node} from 'unist'
|
||||
|
||||
declare namespace mdastToString {}
|
||||
|
||||
declare function mdastToString(node: Node | Node[]): string
|
||||
|
||||
export = mdastToString
|
||||
109
node_modules/mdast-util-from-markdown/package.json
generated
vendored
Normal file
109
node_modules/mdast-util-from-markdown/package.json
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"name": "mdast-util-from-markdown",
|
||||
"version": "0.8.5",
|
||||
"description": "mdast utility to parse markdown",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"mdast",
|
||||
"mdast-util",
|
||||
"util",
|
||||
"utility",
|
||||
"markdown",
|
||||
"markup",
|
||||
"parse",
|
||||
"syntax",
|
||||
"tree",
|
||||
"ast"
|
||||
],
|
||||
"repository": "syntax-tree/mdast-util-from-markdown",
|
||||
"bugs": "https://github.com/syntax-tree/mdast-util-from-markdown/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"dist/",
|
||||
"lib/",
|
||||
"index.js",
|
||||
"types/index.d.ts"
|
||||
],
|
||||
"types": "types",
|
||||
"dependencies": {
|
||||
"@types/mdast": "^3.0.0",
|
||||
"mdast-util-to-string": "^2.0.0",
|
||||
"micromark": "~2.11.0",
|
||||
"parse-entities": "^2.0.0",
|
||||
"unist-util-stringify-position": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
"@babel/core": "^7.0.0",
|
||||
"babel-plugin-inline-constants": "^1.0.0",
|
||||
"browserify": "^17.0.0",
|
||||
"commonmark.json": "^0.29.0",
|
||||
"dtslint": "^4.0.0",
|
||||
"gzip-size-cli": "^4.0.0",
|
||||
"hast-util-to-html": "^7.0.0",
|
||||
"mdast-util-to-hast": "^10.0.0",
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"rehype-parse": "^7.0.0",
|
||||
"rehype-stringify": "^8.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"tinyify": "^3.0.0",
|
||||
"unified": "^9.0.0",
|
||||
"xo": "^0.37.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"generate-dist": "babel lib/ --out-dir dist/ --quiet --retain-lines; prettier dist/ --loglevel error --write",
|
||||
"generate-size": "browserify . -p tinyify -s mdast-util-from-markdown -o mdast-util-from-markdown.min.js; gzip-size mdast-util-from-markdown.min.js --raw",
|
||||
"generate": "npm run generate-dist && npm run generate-size",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test/index.js",
|
||||
"test-types": "dtslint types",
|
||||
"test": "npm run format && npm run generate && npm run test-coverage && npm run test-types"
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"rules": {
|
||||
"complexity": "off",
|
||||
"guard-for-in": "off",
|
||||
"unicorn/explicit-length-check": "off",
|
||||
"unicorn/no-array-callback-reference": "off",
|
||||
"unicorn/prefer-includes": "off",
|
||||
"unicorn/prefer-number-properties": "off",
|
||||
"unicorn/prefer-optional-catch-binding": "off"
|
||||
},
|
||||
"ignores": [
|
||||
"types/"
|
||||
]
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
206
node_modules/mdast-util-from-markdown/readme.md
generated
vendored
Normal file
206
node_modules/mdast-util-from-markdown/readme.md
generated
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
# mdast-util-from-markdown
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
**[mdast][]** utility to parse markdown.
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install mdast-util-from-markdown
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
Say we have the following markdown file, `example.md`:
|
||||
|
||||
```markdown
|
||||
## Hello, *World*!
|
||||
```
|
||||
|
||||
And our script, `example.js`, looks as follows:
|
||||
|
||||
```js
|
||||
var fs = require('fs')
|
||||
var fromMarkdown = require('mdast-util-from-markdown')
|
||||
|
||||
var doc = fs.readFileSync('example.md')
|
||||
|
||||
var tree = fromMarkdown(doc)
|
||||
|
||||
console.log(tree)
|
||||
```
|
||||
|
||||
Now, running `node example` yields (positional info removed for brevity):
|
||||
|
||||
```js
|
||||
{
|
||||
type: 'root',
|
||||
children: [
|
||||
{
|
||||
type: 'heading',
|
||||
depth: 2,
|
||||
children: [
|
||||
{type: 'text', value: 'Hello, '},
|
||||
{
|
||||
type: 'emphasis',
|
||||
children: [{type: 'text', value: 'World'}]
|
||||
},
|
||||
{type: 'text', value: '!'}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `fromMarkdown(doc[, encoding][, options])`
|
||||
|
||||
Parse markdown to a **[mdast][]** tree.
|
||||
|
||||
##### Parameters
|
||||
|
||||
###### `doc`
|
||||
|
||||
Value to parse (`string` or [`Buffer`][buffer]).
|
||||
|
||||
###### `encoding`
|
||||
|
||||
[Character encoding][encoding] to understand `doc` as when it’s a
|
||||
[`Buffer`][buffer] (`string`, default: `'utf8'`).
|
||||
|
||||
###### `options.extensions`
|
||||
|
||||
Array of syntax extensions (`Array.<MicromarkSyntaxExtension>`, default: `[]`).
|
||||
Passed to [`micromark` as `extensions`][micromark-extensions].
|
||||
|
||||
###### `options.mdastExtensions`
|
||||
|
||||
Array of mdast extensions (`Array.<MdastExtension>`, default: `[]`).
|
||||
|
||||
##### Returns
|
||||
|
||||
[`Root`][root].
|
||||
|
||||
## List of extensions
|
||||
|
||||
* [`syntax-tree/mdast-util-directive`](https://github.com/syntax-tree/mdast-util-directive)
|
||||
— parse directives
|
||||
* [`syntax-tree/mdast-util-footnote`](https://github.com/syntax-tree/mdast-util-footnote)
|
||||
— parse footnotes
|
||||
* [`syntax-tree/mdast-util-frontmatter`](https://github.com/syntax-tree/mdast-util-frontmatter)
|
||||
— parse frontmatter (YAML, TOML, more)
|
||||
* [`syntax-tree/mdast-util-gfm`](https://github.com/syntax-tree/mdast-util-gfm)
|
||||
— parse GFM
|
||||
* [`syntax-tree/mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal)
|
||||
— parse GFM autolink literals
|
||||
* [`syntax-tree/mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough)
|
||||
— parse GFM strikethrough
|
||||
* [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table)
|
||||
— parse GFM tables
|
||||
* [`syntax-tree/mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item)
|
||||
— parse GFM task list items
|
||||
* [`syntax-tree/mdast-util-math`](https://github.com/syntax-tree/mdast-util-math)
|
||||
— parse math
|
||||
* [`syntax-tree/mdast-util-mdx`](https://github.com/syntax-tree/mdast-util-mdx)
|
||||
— parse MDX or MDX.js
|
||||
* [`syntax-tree/mdast-util-mdx-expression`](https://github.com/syntax-tree/mdast-util-mdx-expression)
|
||||
— parse MDX or MDX.js expressions
|
||||
* [`syntax-tree/mdast-util-mdx-jsx`](https://github.com/syntax-tree/mdast-util-mdx-jsx)
|
||||
— parse MDX or MDX.js JSX
|
||||
* [`syntax-tree/mdast-util-mdxjs-esm`](https://github.com/syntax-tree/mdast-util-mdxjs-esm)
|
||||
— parse MDX.js ESM
|
||||
|
||||
## Security
|
||||
|
||||
As Markdown is sometimes used for HTML, and improper use of HTML can open you up
|
||||
to a [cross-site scripting (XSS)][xss] attack, use of `mdast-util-from-markdown`
|
||||
can also be unsafe.
|
||||
When going to HTML, use this utility in combination with
|
||||
[`hast-util-sanitize`][sanitize] to make the tree safe.
|
||||
|
||||
## Related
|
||||
|
||||
* [`micromark/micromark`](https://github.com/micromark/micromark)
|
||||
— the smallest commonmark-compliant markdown parser that exists
|
||||
* [`remarkjs/remark`](https://github.com/remarkjs/remark)
|
||||
— markdown processor powered by plugins
|
||||
* [`syntax-tree/mdast-util-to-markdown`](https://github.com/syntax-tree/mdast-util-to-markdown)
|
||||
— serialize mdast to markdown
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
|
||||
started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organization, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/syntax-tree/mdast-util-from-markdown/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/mdast-util-from-markdown/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-from-markdown.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-from-markdown
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-from-markdown.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/mdast-util-from-markdown
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-from-markdown.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=mdast-util-from-markdown
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[chat]: https://github.com/syntax-tree/unist/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[mdast]: https://github.com/syntax-tree/mdast
|
||||
|
||||
[root]: https://github.com/syntax-tree/mdast#root
|
||||
|
||||
[encoding]: https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
|
||||
|
||||
[buffer]: https://nodejs.org/api/buffer.html
|
||||
|
||||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
|
||||
|
||||
[sanitize]: https://github.com/syntax-tree/hast-util-sanitize
|
||||
|
||||
[micromark-extensions]: https://github.com/micromark/micromark#optionsextensions
|
||||
34
node_modules/mdast-util-from-markdown/types/index.d.ts
generated
vendored
Normal file
34
node_modules/mdast-util-from-markdown/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// Minimum TypeScript Version: 3.0
|
||||
import {
|
||||
Buffer,
|
||||
BufferEncoding,
|
||||
SyntaxExtension,
|
||||
Token
|
||||
} from 'micromark/dist/shared-types'
|
||||
import {Root} from 'mdast'
|
||||
import {Type} from 'micromark/dist/constant/types'
|
||||
|
||||
export = fromMarkdown
|
||||
|
||||
declare namespace fromMarkdown {
|
||||
interface MdastExtension {
|
||||
enter: Record<Type, (token: Token) => void>
|
||||
exit: Record<Type, (token: Token) => void>
|
||||
}
|
||||
|
||||
interface Options {
|
||||
extensions?: SyntaxExtension[]
|
||||
mdastExtensions?: MdastExtension[]
|
||||
}
|
||||
}
|
||||
|
||||
declare function fromMarkdown(
|
||||
value: string | Buffer,
|
||||
options?: fromMarkdown.Options
|
||||
): Root
|
||||
|
||||
declare function fromMarkdown(
|
||||
value: string | Buffer,
|
||||
encoding?: BufferEncoding,
|
||||
options?: fromMarkdown.Options
|
||||
): Root
|
||||
Reference in New Issue
Block a user