Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdast-util-from-markdown

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-from-markdown - npm Package Compare versions

Comparing version 1.3.1 to 2.0.0

13

dev/index.d.ts

@@ -1,3 +0,1 @@

import type {OnEnterError} from './lib/index.js'
export type {

@@ -16,7 +14,3 @@ CompileContext,

/**
* Deprecated: use `OnEnterError`.
*/
// To do: next major: remove.
export type OnError = OnEnterError
export {fromMarkdown} from './lib/index.js'

@@ -38,3 +32,2 @@ /**

*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface CompileData {

@@ -81,3 +74,2 @@ /**

declare module 'micromark-util-types' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface TokenTypeMap {

@@ -87,3 +79,2 @@ listItem: 'listItem'

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Token {

@@ -93,3 +84,1 @@ _spread?: boolean

}
export {fromMarkdown} from './lib/index.js'

93

dev/lib/index.d.ts

@@ -1,28 +0,10 @@

/**
* @param value
* Markdown to parse.
* @param encoding
* Character encoding for when `value` is `Buffer`.
* @param options
* Configuration.
* @returns
* mdast tree.
*/
export const fromMarkdown: ((
export function fromMarkdown(
value: Value,
encoding: Encoding,
encoding?: Encoding | null | undefined,
options?: Options | null | undefined
) => Root) &
((value: Value, options?: Options | null | undefined) => Root)
export type Encoding = import('micromark-util-types').Encoding
export type Event = import('micromark-util-types').Event
export type ParseOptions = import('micromark-util-types').ParseOptions
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Value = import('micromark-util-types').Value
export type UnistParent = import('unist').Parent
export type Point = import('unist').Point
export type PhrasingContent = import('mdast').PhrasingContent
export type StaticPhrasingContent = import('mdast').StaticPhrasingContent
export type Content = import('mdast').Content
): Root
export function fromMarkdown(
value: Value,
options?: Options | null | undefined
): Root
export type Break = import('mdast').Break

@@ -34,11 +16,13 @@ export type Blockquote = import('mdast').Blockquote

export type Heading = import('mdast').Heading
export type HTML = import('mdast').HTML
export type Html = import('mdast').Html
export type Image = import('mdast').Image
export type ImageReference = import('mdast').ImageReference
export type InlineCode = import('mdast').InlineCode
export type Link = import('mdast').Link
export type LinkReference = import('mdast').LinkReference
export type List = import('mdast').List
export type ListItem = import('mdast').ListItem
export type Nodes = import('mdast').Nodes
export type Paragraph = import('mdast').Paragraph
export type Parent = import('mdast').Parent
export type PhrasingContent = import('mdast').PhrasingContent
export type ReferenceType = import('mdast').ReferenceType
export type Root = import('mdast').Root

@@ -48,7 +32,11 @@ export type Strong = import('mdast').Strong

export type ThematicBreak = import('mdast').ThematicBreak
export type ReferenceType = import('mdast').ReferenceType
export type Encoding = import('micromark-util-types').Encoding
export type Event = import('micromark-util-types').Event
export type ParseOptions = import('micromark-util-types').ParseOptions
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Value = import('micromark-util-types').Value
export type Point = import('unist').Point
export type CompileData = import('../index.js').CompileData
export type Node = Root | Content
export type Parent = Extract<Node, UnistParent>
export type Fragment = Omit<UnistParent, 'type' | 'children'> & {
export type Fragment = Omit<Parent, 'children' | 'type'> & {
type: 'fragment'

@@ -60,7 +48,7 @@ children: Array<PhrasingContent>

*/
export type Transform = (tree: Root) => Root | undefined | null | void
export type Transform = (tree: Root) => Root | null | undefined | void
/**
* Handle a token.
*/
export type Handle = (this: CompileContext, token: Token) => void
export type Handle = (this: CompileContext, token: Token) => undefined | void
/**

@@ -78,3 +66,3 @@ * Token types mapping to handles

right: Token
) => void
) => undefined
/**

@@ -88,3 +76,3 @@ * Handle the case where the `right` token is open but it is closed by

right: Token
) => void
) => undefined
/**

@@ -129,3 +117,3 @@ * Open token on the stack, with an optional error handler for when

*/
stack: Array<Node | Fragment>
stack: Array<Fragment | Nodes>
/**

@@ -136,18 +124,5 @@ * Stack of tokens.

/**
* Get data from the key/value store.
*/
getData: <Key extends keyof import('../index.js').CompileData>(
key: Key
) => import('../index.js').CompileData[Key]
/**
* Set data into the key/value store.
*/
setData: <Key_1 extends keyof import('../index.js').CompileData>(
key: Key_1,
value?: import('../index.js').CompileData[Key_1] | undefined
) => void
/**
* Capture some of the output data.
*/
buffer: (this: CompileContext) => void
buffer: (this: CompileContext) => undefined
/**

@@ -158,14 +133,14 @@ * Stop capturing and access the output data.

/**
* Enter a token.
* Enter a node.
*/
enter: <Kind extends Node>(
enter: (
this: CompileContext,
node: Kind,
node: Nodes,
token: Token,
onError?: OnEnterError
) => Kind
) => undefined
/**
* Exit a token.
* Exit a node.
*/
exit: (this: CompileContext, token: Token, onError?: OnExitError) => Node
exit: (this: CompileContext, token: Token, onError?: OnExitError) => undefined
/**

@@ -179,2 +154,6 @@ * Get the string value of a token.

config: Config
/**
* Info passed around; key/value store.
*/
data: CompileData
}

@@ -181,0 +160,0 @@ /**

/**
* @typedef {import('micromark-util-types').Encoding} Encoding
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').ParseOptions} ParseOptions
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Value} Value
*
* @typedef {import('unist').Parent} UnistParent
* @typedef {import('unist').Point} Point
*
* @typedef {import('mdast').PhrasingContent} PhrasingContent
* @typedef {import('mdast').StaticPhrasingContent} StaticPhrasingContent
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Break} Break

@@ -21,11 +8,13 @@ * @typedef {import('mdast').Blockquote} Blockquote

* @typedef {import('mdast').Heading} Heading
* @typedef {import('mdast').HTML} HTML
* @typedef {import('mdast').Html} Html
* @typedef {import('mdast').Image} Image
* @typedef {import('mdast').ImageReference} ImageReference
* @typedef {import('mdast').InlineCode} InlineCode
* @typedef {import('mdast').Link} Link
* @typedef {import('mdast').LinkReference} LinkReference
* @typedef {import('mdast').List} List
* @typedef {import('mdast').ListItem} ListItem
* @typedef {import('mdast').Nodes} Nodes
* @typedef {import('mdast').Paragraph} Paragraph
* @typedef {import('mdast').Parent} Parent
* @typedef {import('mdast').PhrasingContent} PhrasingContent
* @typedef {import('mdast').ReferenceType} ReferenceType
* @typedef {import('mdast').Root} Root

@@ -35,3 +24,12 @@ * @typedef {import('mdast').Strong} Strong

* @typedef {import('mdast').ThematicBreak} ThematicBreak
* @typedef {import('mdast').ReferenceType} ReferenceType
*
* @typedef {import('micromark-util-types').Encoding} Encoding
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').ParseOptions} ParseOptions
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Value} Value
*
* @typedef {import('unist').Point} Point
*
* @typedef {import('../index.js').CompileData} CompileData

@@ -41,6 +39,3 @@ */

/**
* @typedef {Root | Content} Node
* @typedef {Extract<Node, UnistParent>} Parent
*
* @typedef {Omit<UnistParent, 'type' | 'children'> & {type: 'fragment', children: Array<PhrasingContent>}} Fragment
* @typedef {Omit<Parent, 'children' | 'type'> & {type: 'fragment', children: Array<PhrasingContent>}} Fragment
*/

@@ -53,3 +48,3 @@

* Tree to transform.
* @returns {Root | undefined | null | void}
* @returns {Root | null | undefined | void}
* New tree or nothing (in which case the current tree is used).

@@ -63,3 +58,3 @@ *

* Current token.
* @returns {void}
* @returns {undefined | void}
* Nothing.

@@ -79,3 +74,3 @@ *

* Right token.
* @returns {void}
* @returns {undefined}
* Nothing.

@@ -92,3 +87,3 @@ *

* Right token.
* @returns {void}
* @returns {undefined}
* Nothing.

@@ -120,18 +115,14 @@ *

* mdast compiler context.
* @property {Array<Node | Fragment>} stack
* @property {Array<Fragment | Nodes>} stack
* Stack of nodes.
* @property {Array<TokenTuple>} tokenStack
* Stack of tokens.
* @property {<Key extends keyof CompileData>(key: Key) => CompileData[Key]} getData
* Get data from the key/value store.
* @property {<Key extends keyof CompileData>(key: Key, value?: CompileData[Key]) => void} setData
* Set data into the key/value store.
* @property {(this: CompileContext) => void} buffer
* @property {(this: CompileContext) => undefined} buffer
* Capture some of the output data.
* @property {(this: CompileContext) => string} resume
* Stop capturing and access the output data.
* @property {<Kind extends Node>(this: CompileContext, node: Kind, token: Token, onError?: OnEnterError) => Kind} enter
* Enter a token.
* @property {(this: CompileContext, token: Token, onError?: OnExitError) => Node} exit
* Exit a token.
* @property {(this: CompileContext, node: Nodes, token: Token, onError?: OnEnterError) => undefined} enter
* Enter a node.
* @property {(this: CompileContext, token: Token, onError?: OnExitError) => undefined} exit
* Exit a node.
* @property {TokenizeContext['sliceSerialize']} sliceSerialize

@@ -141,2 +132,4 @@ * Get the string value of a token.

* Configuration.
* @property {CompileData} data
* Info passed around; key/value store.
*

@@ -152,17 +145,9 @@ * @typedef FromMarkdownOptions

// To do: micromark: create a registry of tokens?
// To do: next major: don’t return given `Node` from `enter`.
// To do: next major: remove setter/getter.
import {ok as assert} from 'uvu/assert'
import {ok as assert} from 'devlop'
import {toString} from 'mdast-util-to-string'
import {parse} from 'micromark/lib/parse.js'
import {preprocess} from 'micromark/lib/preprocess.js'
import {postprocess} from 'micromark/lib/postprocess.js'
import {parse, postprocess, preprocess} from 'micromark'
import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference'
import {decodeString} from 'micromark-util-decode-string'
import {normalizeIdentifier} from 'micromark-util-normalize-identifier'
import {codes} from 'micromark-util-symbol/codes.js'
import {constants} from 'micromark-util-symbol/constants.js'
import {types} from 'micromark-util-symbol/types.js'
import {codes, constants, types} from 'micromark-util-symbol'
import {decodeNamedCharacterReference} from 'decode-named-character-reference'

@@ -174,38 +159,36 @@ import {stringifyPosition} from 'unist-util-stringify-position'

/**
* @param value
* Turn markdown into a syntax tree.
*
* @overload
* @param {Value} value
* @param {Encoding | null | undefined} [encoding]
* @param {Options | null | undefined} [options]
* @returns {Root}
*
* @overload
* @param {Value} value
* @param {Options | null | undefined} [options]
* @returns {Root}
*
* @param {Value} value
* Markdown to parse.
* @param encoding
* @param {Encoding | Options | null | undefined} [encoding]
* Character encoding for when `value` is `Buffer`.
* @param options
* @param {Options | null | undefined} [options]
* Configuration.
* @returns
* @returns {Root}
* mdast tree.
*/
export const fromMarkdown =
/**
* @type {(
* ((value: Value, encoding: Encoding, options?: Options | null | undefined) => Root) &
* ((value: Value, options?: Options | null | undefined) => Root)
* )}
*/
(
/**
* @param {Value} value
* @param {Encoding | Options | null | undefined} [encoding]
* @param {Options | null | undefined} [options]
* @returns {Root}
*/
function (value, encoding, options) {
if (typeof encoding !== 'string') {
options = encoding
encoding = undefined
}
export function fromMarkdown(value, encoding, options) {
if (typeof encoding !== 'string') {
options = encoding
encoding = undefined
}
return compiler(options)(
postprocess(
parse(options).document().write(preprocess()(value, encoding, true))
)
)
}
return compiler(options)(
postprocess(
parse(options).document().write(preprocess()(value, encoding, true))
)
)
}

@@ -344,4 +327,3 @@ /**

resume,
setData,
getData
data
}

@@ -435,37 +417,47 @@ /** @type {Array<number>} */

if (
event[1].type === types.listUnordered ||
event[1].type === types.listOrdered ||
event[1].type === types.blockQuote
) {
if (event[0] === 'enter') {
containerBalance++
} else {
containerBalance--
switch (event[1].type) {
case types.listUnordered:
case types.listOrdered:
case types.blockQuote: {
if (event[0] === 'enter') {
containerBalance++
} else {
containerBalance--
}
atMarker = undefined
break
}
atMarker = undefined
} else if (event[1].type === types.lineEndingBlank) {
if (event[0] === 'enter') {
if (
listItem &&
!atMarker &&
!containerBalance &&
!firstBlankLineIndex
) {
firstBlankLineIndex = index
case types.lineEndingBlank: {
if (event[0] === 'enter') {
if (
listItem &&
!atMarker &&
!containerBalance &&
!firstBlankLineIndex
) {
firstBlankLineIndex = index
}
atMarker = undefined
}
break
}
case types.linePrefix:
case types.listItemValue:
case types.listItemMarker:
case types.listItemPrefix:
case types.listItemPrefixWhitespace: {
// Empty.
break
}
default: {
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
}

@@ -535,3 +527,4 @@

if (event[1].type === types.listItemPrefix) {
listItem = {
/** @type {Token} */
const item = {
type: 'listItem',

@@ -543,4 +536,4 @@ _spread: false,

}
// @ts-expect-error: `listItem` is most definitely defined, TS...
events.splice(index, 0, ['enter', listItem, event[2]])
listItem = item
events.splice(index, 0, ['enter', item, event[2]])
index++

@@ -559,37 +552,7 @@ length++

/**
* Set data.
*
* @template {keyof CompileData} Key
* Field type.
* @param {Key} key
* Key of field.
* @param {CompileData[Key]} [value]
* New value.
* @returns {void}
* Nothing.
*/
function setData(key, value) {
data[key] = value
}
/**
* Get data.
*
* @template {keyof CompileData} Key
* Field type.
* @param {Key} key
* Key of field.
* @returns {CompileData[Key]}
* Value.
*/
function getData(key) {
return data[key]
}
/**
* Create an opener handle.
*
* @param {(token: Token) => Node} create
* @param {(token: Token) => Nodes} create
* Create a node.
* @param {Handle} [and]
* @param {Handle | undefined} [and]
* Optional function to also run.

@@ -605,3 +568,3 @@ * @returns {Handle}

* @param {Token} token
* @returns {void}
* @returns {undefined}
*/

@@ -616,3 +579,3 @@ function open(token) {

* @this {CompileContext}
* @returns {void}
* @returns {undefined}
*/

@@ -624,7 +587,5 @@ function buffer() {

/**
* @template {Node} Kind
* Node type.
* @this {CompileContext}
* Context.
* @param {Kind} node
* @param {Nodes} node
* Node to enter.

@@ -635,4 +596,4 @@ * @param {Token} token

* Handle the case where this token is open, but it is closed by something else.
* @returns {Kind}
* The given node.
* @returns {undefined}
* Nothing.
*/

@@ -643,9 +604,12 @@ function enter(node, token, errorHandler) {

assert('children' in parent, 'expected `parent`')
// @ts-expect-error: Assume `Node` can exist as a child of `parent`.
parent.children.push(node)
/** @type {Array<Nodes>} */
const siblings = parent.children
siblings.push(node)
this.stack.push(node)
this.tokenStack.push([token, errorHandler])
// @ts-expect-error: `end` will be patched later.
node.position = {start: point(token.start)}
return node
node.position = {
start: point(token.start),
// @ts-expect-error: `end` will be patched later.
end: undefined
}
}

@@ -656,3 +620,3 @@

*
* @param {Handle} [and]
* @param {Handle | undefined} [and]
* Optional function to also run.

@@ -668,3 +632,3 @@ * @returns {Handle}

* @param {Token} token
* @returns {void}
* @returns {undefined}
*/

@@ -684,4 +648,4 @@ function close(token) {

* Handle the case where another token is open.
* @returns {Node}
* The closed node.
* @returns {undefined}
* Nothing.
*/

@@ -713,3 +677,2 @@ function exit(token, onExitError) {

node.position.end = point(token.end)
return node
}

@@ -734,3 +697,3 @@

function onenterlistordered() {
setData('expectingFirstListItemValue', true)
this.data.expectingFirstListItemValue = true
}

@@ -743,3 +706,3 @@

function onenterlistitemvalue(token) {
if (getData('expectingFirstListItemValue')) {
if (this.data.expectingFirstListItemValue) {
const ancestor = this.stack[this.stack.length - 2]

@@ -752,3 +715,3 @@ assert(ancestor, 'expected nodes on stack')

)
setData('expectingFirstListItemValue')
this.data.expectingFirstListItemValue = undefined
}

@@ -787,5 +750,5 @@ }

// Exit if this is the closing fence.
if (getData('flowCodeInside')) return
if (this.data.flowCodeInside) return
this.buffer()
setData('flowCodeInside', true)
this.data.flowCodeInside = true
}

@@ -804,3 +767,3 @@

node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
setData('flowCodeInside')
this.data.flowCodeInside = undefined
}

@@ -894,3 +857,3 @@

function onexitsetextheadingtext() {
setData('setextHeadingSlurpLineEnding', true)
this.data.setextHeadingSlurpLineEnding = true
}

@@ -908,3 +871,3 @@

node.depth =
this.sliceSerialize(token).charCodeAt(0) === codes.equalsTo ? 1 : 2
this.sliceSerialize(token).codePointAt(0) === codes.equalsTo ? 1 : 2
}

@@ -917,3 +880,3 @@

function onexitsetextheading() {
setData('setextHeadingSlurpLineEnding')
this.data.setextHeadingSlurpLineEnding = undefined
}

@@ -930,4 +893,6 @@

assert('children' in node, 'expected parent on stack')
/** @type {Array<Nodes>} */
const siblings = node.children
let tail = node.children[node.children.length - 1]
let tail = siblings[siblings.length - 1]

@@ -937,6 +902,8 @@ if (!tail || tail.type !== 'text') {

tail = text()
// @ts-expect-error: we’ll add `end` later.
tail.position = {start: point(token.start)}
// @ts-expect-error: Assume `parent` accepts `text`.
node.children.push(tail)
tail.position = {
start: point(token.start),
// @ts-expect-error: we’ll add `end` later.
end: undefined
}
siblings.push(tail)
}

@@ -971,3 +938,3 @@

// If we’re at a hard break, include the line ending in there.
if (getData('atHardBreak')) {
if (this.data.atHardBreak) {
assert('children' in context, 'expected `parent`')

@@ -977,3 +944,3 @@ const tail = context.children[context.children.length - 1]

tail.position.end = point(token.end)
setData('atHardBreak')
this.data.atHardBreak = undefined
return

@@ -983,3 +950,3 @@ }

if (
!getData('setextHeadingSlurpLineEnding') &&
!this.data.setextHeadingSlurpLineEnding &&
config.canContainEols.includes(context.type)

@@ -998,3 +965,3 @@ ) {

function onexithardbreak() {
setData('atHardBreak', true)
this.data.atHardBreak = true
}

@@ -1058,5 +1025,5 @@

// To do: clean.
if (getData('inReference')) {
if (this.data.inReference) {
/** @type {ReferenceType} */
const referenceType = getData('referenceType') || 'shortcut'
const referenceType = this.data.referenceType || 'shortcut'

@@ -1076,3 +1043,3 @@ node.type += 'Reference'

setData('referenceType')
this.data.referenceType = undefined
}

@@ -1094,5 +1061,5 @@

// To do: clean.
if (getData('inReference')) {
if (this.data.inReference) {
/** @type {ReferenceType} */
const referenceType = getData('referenceType') || 'shortcut'
const referenceType = this.data.referenceType || 'shortcut'

@@ -1112,3 +1079,3 @@ node.type += 'Reference'

setData('referenceType')
this.data.referenceType = undefined
}

@@ -1155,7 +1122,6 @@

// Assume a reference.
setData('inReference', true)
this.data.inReference = true
if (node.type === 'link') {
/** @type {Array<StaticPhrasingContent>} */
// @ts-expect-error: Assume static phrasing content.
/** @type {Array<PhrasingContent>} */
const children = fragment.children

@@ -1207,3 +1173,3 @@

function onexitresource() {
setData('inReference')
this.data.inReference = undefined
}

@@ -1217,3 +1183,3 @@

function onenterreference() {
setData('referenceType', 'collapsed')
this.data.referenceType = 'collapsed'
}

@@ -1242,3 +1208,3 @@

).toLowerCase()
setData('referenceType', 'full')
this.data.referenceType = 'full'
}

@@ -1256,3 +1222,3 @@

)
setData('characterReferenceType', token.type)
this.data.characterReferenceType = token.type
}

@@ -1266,3 +1232,3 @@

const data = this.sliceSerialize(token)
const type = getData('characterReferenceType')
const type = this.data.characterReferenceType
/** @type {string} */

@@ -1278,3 +1244,3 @@ let value

)
setData('characterReferenceType')
this.data.characterReferenceType = undefined
} else {

@@ -1357,4 +1323,8 @@ const result = decodeNamedCharacterReference(data)

function heading() {
// @ts-expect-error `depth` will be set later.
return {type: 'heading', depth: undefined, children: []}
return {
type: 'heading',
// @ts-expect-error `depth` will be set later.
depth: 0,
children: []
}
}

@@ -1367,3 +1337,3 @@

/** @returns {HTML} */
/** @returns {Html} */
function html() {

@@ -1445,4 +1415,4 @@ return {type: 'html', value: ''}

* @param {Config} combined
* @param {Array<Extension | Array<Extension>>} extensions
* @returns {void}
* @param {Array<Array<Extension> | Extension>} extensions
* @returns {undefined}
*/

@@ -1466,3 +1436,3 @@ function configure(combined, extensions) {

* @param {Extension} extension
* @returns {void}
* @returns {undefined}
*/

@@ -1475,17 +1445,31 @@ function extension(combined, extension) {

if (own.call(extension, key)) {
if (key === 'canContainEols') {
const right = extension[key]
if (right) {
combined[key].push(...right)
switch (key) {
case 'canContainEols': {
const right = extension[key]
if (right) {
combined[key].push(...right)
}
break
}
} else if (key === 'transforms') {
const right = extension[key]
if (right) {
combined[key].push(...right)
case 'transforms': {
const right = extension[key]
if (right) {
combined[key].push(...right)
}
break
}
} else if (key === 'enter' || key === 'exit') {
const right = extension[key]
if (right) {
Object.assign(combined[key], right)
case 'enter':
case 'exit': {
const right = extension[key]
if (right) {
Object.assign(combined[key], right)
}
break
}
// No default
}

@@ -1492,0 +1476,0 @@ }

@@ -1,3 +0,1 @@

import type {OnEnterError} from './lib/index.js'
export type {

@@ -16,7 +14,3 @@ CompileContext,

/**
* Deprecated: use `OnEnterError`.
*/
// To do: next major: remove.
export type OnError = OnEnterError
export {fromMarkdown} from './lib/index.js'

@@ -38,3 +32,2 @@ /**

*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface CompileData {

@@ -81,3 +74,2 @@ /**

declare module 'micromark-util-types' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface TokenTypeMap {

@@ -87,3 +79,2 @@ listItem: 'listItem'

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Token {

@@ -93,3 +84,1 @@ _spread?: boolean

}
export {fromMarkdown} from './lib/index.js'

@@ -1,28 +0,10 @@

/**
* @param value
* Markdown to parse.
* @param encoding
* Character encoding for when `value` is `Buffer`.
* @param options
* Configuration.
* @returns
* mdast tree.
*/
export const fromMarkdown: ((
export function fromMarkdown(
value: Value,
encoding: Encoding,
encoding?: Encoding | null | undefined,
options?: Options | null | undefined
) => Root) &
((value: Value, options?: Options | null | undefined) => Root)
export type Encoding = import('micromark-util-types').Encoding
export type Event = import('micromark-util-types').Event
export type ParseOptions = import('micromark-util-types').ParseOptions
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Value = import('micromark-util-types').Value
export type UnistParent = import('unist').Parent
export type Point = import('unist').Point
export type PhrasingContent = import('mdast').PhrasingContent
export type StaticPhrasingContent = import('mdast').StaticPhrasingContent
export type Content = import('mdast').Content
): Root
export function fromMarkdown(
value: Value,
options?: Options | null | undefined
): Root
export type Break = import('mdast').Break

@@ -34,11 +16,13 @@ export type Blockquote = import('mdast').Blockquote

export type Heading = import('mdast').Heading
export type HTML = import('mdast').HTML
export type Html = import('mdast').Html
export type Image = import('mdast').Image
export type ImageReference = import('mdast').ImageReference
export type InlineCode = import('mdast').InlineCode
export type Link = import('mdast').Link
export type LinkReference = import('mdast').LinkReference
export type List = import('mdast').List
export type ListItem = import('mdast').ListItem
export type Nodes = import('mdast').Nodes
export type Paragraph = import('mdast').Paragraph
export type Parent = import('mdast').Parent
export type PhrasingContent = import('mdast').PhrasingContent
export type ReferenceType = import('mdast').ReferenceType
export type Root = import('mdast').Root

@@ -48,7 +32,11 @@ export type Strong = import('mdast').Strong

export type ThematicBreak = import('mdast').ThematicBreak
export type ReferenceType = import('mdast').ReferenceType
export type Encoding = import('micromark-util-types').Encoding
export type Event = import('micromark-util-types').Event
export type ParseOptions = import('micromark-util-types').ParseOptions
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Value = import('micromark-util-types').Value
export type Point = import('unist').Point
export type CompileData = import('../index.js').CompileData
export type Node = Root | Content
export type Parent = Extract<Node, UnistParent>
export type Fragment = Omit<UnistParent, 'type' | 'children'> & {
export type Fragment = Omit<Parent, 'children' | 'type'> & {
type: 'fragment'

@@ -60,7 +48,7 @@ children: Array<PhrasingContent>

*/
export type Transform = (tree: Root) => Root | undefined | null | void
export type Transform = (tree: Root) => Root | null | undefined | void
/**
* Handle a token.
*/
export type Handle = (this: CompileContext, token: Token) => void
export type Handle = (this: CompileContext, token: Token) => undefined | void
/**

@@ -78,3 +66,3 @@ * Token types mapping to handles

right: Token
) => void
) => undefined
/**

@@ -88,3 +76,3 @@ * Handle the case where the `right` token is open but it is closed by

right: Token
) => void
) => undefined
/**

@@ -129,3 +117,3 @@ * Open token on the stack, with an optional error handler for when

*/
stack: Array<Node | Fragment>
stack: Array<Fragment | Nodes>
/**

@@ -136,18 +124,5 @@ * Stack of tokens.

/**
* Get data from the key/value store.
*/
getData: <Key extends keyof import('../index.js').CompileData>(
key: Key
) => import('../index.js').CompileData[Key]
/**
* Set data into the key/value store.
*/
setData: <Key_1 extends keyof import('../index.js').CompileData>(
key: Key_1,
value?: import('../index.js').CompileData[Key_1] | undefined
) => void
/**
* Capture some of the output data.
*/
buffer: (this: CompileContext) => void
buffer: (this: CompileContext) => undefined
/**

@@ -158,14 +133,14 @@ * Stop capturing and access the output data.

/**
* Enter a token.
* Enter a node.
*/
enter: <Kind extends Node>(
enter: (
this: CompileContext,
node: Kind,
node: Nodes,
token: Token,
onError?: OnEnterError
) => Kind
) => undefined
/**
* Exit a token.
* Exit a node.
*/
exit: (this: CompileContext, token: Token, onError?: OnExitError) => Node
exit: (this: CompileContext, token: Token, onError?: OnExitError) => undefined
/**

@@ -179,2 +154,6 @@ * Get the string value of a token.

config: Config
/**
* Info passed around; key/value store.
*/
data: CompileData
}

@@ -181,0 +160,0 @@ /**

/**
* @typedef {import('micromark-util-types').Encoding} Encoding
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').ParseOptions} ParseOptions
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Value} Value
*
* @typedef {import('unist').Parent} UnistParent
* @typedef {import('unist').Point} Point
*
* @typedef {import('mdast').PhrasingContent} PhrasingContent
* @typedef {import('mdast').StaticPhrasingContent} StaticPhrasingContent
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Break} Break

@@ -21,11 +8,13 @@ * @typedef {import('mdast').Blockquote} Blockquote

* @typedef {import('mdast').Heading} Heading
* @typedef {import('mdast').HTML} HTML
* @typedef {import('mdast').Html} Html
* @typedef {import('mdast').Image} Image
* @typedef {import('mdast').ImageReference} ImageReference
* @typedef {import('mdast').InlineCode} InlineCode
* @typedef {import('mdast').Link} Link
* @typedef {import('mdast').LinkReference} LinkReference
* @typedef {import('mdast').List} List
* @typedef {import('mdast').ListItem} ListItem
* @typedef {import('mdast').Nodes} Nodes
* @typedef {import('mdast').Paragraph} Paragraph
* @typedef {import('mdast').Parent} Parent
* @typedef {import('mdast').PhrasingContent} PhrasingContent
* @typedef {import('mdast').ReferenceType} ReferenceType
* @typedef {import('mdast').Root} Root

@@ -35,3 +24,12 @@ * @typedef {import('mdast').Strong} Strong

* @typedef {import('mdast').ThematicBreak} ThematicBreak
* @typedef {import('mdast').ReferenceType} ReferenceType
*
* @typedef {import('micromark-util-types').Encoding} Encoding
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').ParseOptions} ParseOptions
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Value} Value
*
* @typedef {import('unist').Point} Point
*
* @typedef {import('../index.js').CompileData} CompileData

@@ -41,6 +39,3 @@ */

/**
* @typedef {Root | Content} Node
* @typedef {Extract<Node, UnistParent>} Parent
*
* @typedef {Omit<UnistParent, 'type' | 'children'> & {type: 'fragment', children: Array<PhrasingContent>}} Fragment
* @typedef {Omit<Parent, 'children' | 'type'> & {type: 'fragment', children: Array<PhrasingContent>}} Fragment
*/

@@ -53,3 +48,3 @@

* Tree to transform.
* @returns {Root | undefined | null | void}
* @returns {Root | null | undefined | void}
* New tree or nothing (in which case the current tree is used).

@@ -63,3 +58,3 @@ *

* Current token.
* @returns {void}
* @returns {undefined | void}
* Nothing.

@@ -79,3 +74,3 @@ *

* Right token.
* @returns {void}
* @returns {undefined}
* Nothing.

@@ -92,3 +87,3 @@ *

* Right token.
* @returns {void}
* @returns {undefined}
* Nothing.

@@ -120,18 +115,14 @@ *

* mdast compiler context.
* @property {Array<Node | Fragment>} stack
* @property {Array<Fragment | Nodes>} stack
* Stack of nodes.
* @property {Array<TokenTuple>} tokenStack
* Stack of tokens.
* @property {<Key extends keyof CompileData>(key: Key) => CompileData[Key]} getData
* Get data from the key/value store.
* @property {<Key extends keyof CompileData>(key: Key, value?: CompileData[Key]) => void} setData
* Set data into the key/value store.
* @property {(this: CompileContext) => void} buffer
* @property {(this: CompileContext) => undefined} buffer
* Capture some of the output data.
* @property {(this: CompileContext) => string} resume
* Stop capturing and access the output data.
* @property {<Kind extends Node>(this: CompileContext, node: Kind, token: Token, onError?: OnEnterError) => Kind} enter
* Enter a token.
* @property {(this: CompileContext, token: Token, onError?: OnExitError) => Node} exit
* Exit a token.
* @property {(this: CompileContext, node: Nodes, token: Token, onError?: OnEnterError) => undefined} enter
* Enter a node.
* @property {(this: CompileContext, token: Token, onError?: OnExitError) => undefined} exit
* Exit a node.
* @property {TokenizeContext['sliceSerialize']} sliceSerialize

@@ -141,2 +132,4 @@ * Get the string value of a token.

* Configuration.
* @property {CompileData} data
* Info passed around; key/value store.
*

@@ -152,10 +145,4 @@ * @typedef FromMarkdownOptions

// To do: micromark: create a registry of tokens?
// To do: next major: don’t return given `Node` from `enter`.
// To do: next major: remove setter/getter.
import {toString} from 'mdast-util-to-string'
import {parse} from 'micromark/lib/parse.js'
import {preprocess} from 'micromark/lib/preprocess.js'
import {postprocess} from 'micromark/lib/postprocess.js'
import {parse, postprocess, preprocess} from 'micromark'
import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference'

@@ -169,36 +156,35 @@ import {decodeString} from 'micromark-util-decode-string'

/**
* @param value
* Turn markdown into a syntax tree.
*
* @overload
* @param {Value} value
* @param {Encoding | null | undefined} [encoding]
* @param {Options | null | undefined} [options]
* @returns {Root}
*
* @overload
* @param {Value} value
* @param {Options | null | undefined} [options]
* @returns {Root}
*
* @param {Value} value
* Markdown to parse.
* @param encoding
* @param {Encoding | Options | null | undefined} [encoding]
* Character encoding for when `value` is `Buffer`.
* @param options
* @param {Options | null | undefined} [options]
* Configuration.
* @returns
* @returns {Root}
* mdast tree.
*/
export const fromMarkdown =
/**
* @type {(
* ((value: Value, encoding: Encoding, options?: Options | null | undefined) => Root) &
* ((value: Value, options?: Options | null | undefined) => Root)
* )}
*/
/**
* @param {Value} value
* @param {Encoding | Options | null | undefined} [encoding]
* @param {Options | null | undefined} [options]
* @returns {Root}
*/
function (value, encoding, options) {
if (typeof encoding !== 'string') {
options = encoding
encoding = undefined
}
return compiler(options)(
postprocess(
parse(options).document().write(preprocess()(value, encoding, true))
)
export function fromMarkdown(value, encoding, options) {
if (typeof encoding !== 'string') {
options = encoding
encoding = undefined
}
return compiler(options)(
postprocess(
parse(options).document().write(preprocess()(value, encoding, true))
)
}
)
}

@@ -338,4 +324,3 @@ /**

resume,
setData,
getData
data
}

@@ -433,35 +418,40 @@ /** @type {Array<number>} */

const event = events[index]
if (
event[1].type === 'listUnordered' ||
event[1].type === 'listOrdered' ||
event[1].type === 'blockQuote'
) {
if (event[0] === 'enter') {
containerBalance++
} else {
containerBalance--
switch (event[1].type) {
case 'listUnordered':
case 'listOrdered':
case 'blockQuote': {
if (event[0] === 'enter') {
containerBalance++
} else {
containerBalance--
}
atMarker = undefined
break
}
atMarker = undefined
} else if (event[1].type === 'lineEndingBlank') {
if (event[0] === 'enter') {
if (
listItem &&
!atMarker &&
!containerBalance &&
!firstBlankLineIndex
) {
firstBlankLineIndex = index
case 'lineEndingBlank': {
if (event[0] === 'enter') {
if (
listItem &&
!atMarker &&
!containerBalance &&
!firstBlankLineIndex
) {
firstBlankLineIndex = index
}
atMarker = undefined
}
break
}
case 'linePrefix':
case 'listItemValue':
case 'listItemMarker':
case 'listItemPrefix':
case 'listItemPrefixWhitespace': {
// Empty.
break
}
default: {
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
}

@@ -524,3 +514,4 @@ if (

if (event[1].type === 'listItemPrefix') {
listItem = {
/** @type {Token} */
const item = {
type: 'listItem',

@@ -532,4 +523,4 @@ _spread: false,

}
// @ts-expect-error: `listItem` is most definitely defined, TS...
events.splice(index, 0, ['enter', listItem, event[2]])
listItem = item
events.splice(index, 0, ['enter', item, event[2]])
index++

@@ -547,37 +538,7 @@ length++

/**
* Set data.
*
* @template {keyof CompileData} Key
* Field type.
* @param {Key} key
* Key of field.
* @param {CompileData[Key]} [value]
* New value.
* @returns {void}
* Nothing.
*/
function setData(key, value) {
data[key] = value
}
/**
* Get data.
*
* @template {keyof CompileData} Key
* Field type.
* @param {Key} key
* Key of field.
* @returns {CompileData[Key]}
* Value.
*/
function getData(key) {
return data[key]
}
/**
* Create an opener handle.
*
* @param {(token: Token) => Node} create
* @param {(token: Token) => Nodes} create
* Create a node.
* @param {Handle} [and]
* @param {Handle | undefined} [and]
* Optional function to also run.

@@ -593,3 +554,3 @@ * @returns {Handle}

* @param {Token} token
* @returns {void}
* @returns {undefined}
*/

@@ -604,3 +565,3 @@ function open(token) {

* @this {CompileContext}
* @returns {void}
* @returns {undefined}
*/

@@ -615,7 +576,5 @@ function buffer() {

/**
* @template {Node} Kind
* Node type.
* @this {CompileContext}
* Context.
* @param {Kind} node
* @param {Nodes} node
* Node to enter.

@@ -626,16 +585,17 @@ * @param {Token} token

* Handle the case where this token is open, but it is closed by something else.
* @returns {Kind}
* The given node.
* @returns {undefined}
* Nothing.
*/
function enter(node, token, errorHandler) {
const parent = this.stack[this.stack.length - 1]
// @ts-expect-error: Assume `Node` can exist as a child of `parent`.
parent.children.push(node)
/** @type {Array<Nodes>} */
const siblings = parent.children
siblings.push(node)
this.stack.push(node)
this.tokenStack.push([token, errorHandler])
// @ts-expect-error: `end` will be patched later.
node.position = {
start: point(token.start)
start: point(token.start),
// @ts-expect-error: `end` will be patched later.
end: undefined
}
return node
}

@@ -646,3 +606,3 @@

*
* @param {Handle} [and]
* @param {Handle | undefined} [and]
* Optional function to also run.

@@ -658,3 +618,3 @@ * @returns {Handle}

* @param {Token} token
* @returns {void}
* @returns {undefined}
*/

@@ -674,4 +634,4 @@ function close(token) {

* Handle the case where another token is open.
* @returns {Node}
* The closed node.
* @returns {undefined}
* Nothing.
*/

@@ -701,3 +661,2 @@ function exit(token, onExitError) {

node.position.end = point(token.end)
return node
}

@@ -722,3 +681,3 @@

function onenterlistordered() {
setData('expectingFirstListItemValue', true)
this.data.expectingFirstListItemValue = true
}

@@ -731,6 +690,6 @@

function onenterlistitemvalue(token) {
if (getData('expectingFirstListItemValue')) {
if (this.data.expectingFirstListItemValue) {
const ancestor = this.stack[this.stack.length - 2]
ancestor.start = Number.parseInt(this.sliceSerialize(token), 10)
setData('expectingFirstListItemValue')
this.data.expectingFirstListItemValue = undefined
}

@@ -765,5 +724,5 @@ }

// Exit if this is the closing fence.
if (getData('flowCodeInside')) return
if (this.data.flowCodeInside) return
this.buffer()
setData('flowCodeInside', true)
this.data.flowCodeInside = true
}

@@ -779,3 +738,3 @@

node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
setData('flowCodeInside')
this.data.flowCodeInside = undefined
}

@@ -843,3 +802,3 @@

function onexitsetextheadingtext() {
setData('setextHeadingSlurpLineEnding', true)
this.data.setextHeadingSlurpLineEnding = true
}

@@ -853,3 +812,3 @@

const node = this.stack[this.stack.length - 1]
node.depth = this.sliceSerialize(token).charCodeAt(0) === 61 ? 1 : 2
node.depth = this.sliceSerialize(token).codePointAt(0) === 61 ? 1 : 2
}

@@ -862,3 +821,3 @@

function onexitsetextheading() {
setData('setextHeadingSlurpLineEnding')
this.data.setextHeadingSlurpLineEnding = undefined
}

@@ -873,12 +832,14 @@

const node = this.stack[this.stack.length - 1]
let tail = node.children[node.children.length - 1]
/** @type {Array<Nodes>} */
const siblings = node.children
let tail = siblings[siblings.length - 1]
if (!tail || tail.type !== 'text') {
// Add a new text node.
tail = text()
// @ts-expect-error: we’ll add `end` later.
tail.position = {
start: point(token.start)
start: point(token.start),
// @ts-expect-error: we’ll add `end` later.
end: undefined
}
// @ts-expect-error: Assume `parent` accepts `text`.
node.children.push(tail)
siblings.push(tail)
}

@@ -907,10 +868,10 @@ this.stack.push(tail)

// If we’re at a hard break, include the line ending in there.
if (getData('atHardBreak')) {
if (this.data.atHardBreak) {
const tail = context.children[context.children.length - 1]
tail.position.end = point(token.end)
setData('atHardBreak')
this.data.atHardBreak = undefined
return
}
if (
!getData('setextHeadingSlurpLineEnding') &&
!this.data.setextHeadingSlurpLineEnding &&
config.canContainEols.includes(context.type)

@@ -929,3 +890,3 @@ ) {

function onexithardbreak() {
setData('atHardBreak', true)
this.data.atHardBreak = true
}

@@ -976,5 +937,5 @@

// To do: clean.
if (getData('inReference')) {
if (this.data.inReference) {
/** @type {ReferenceType} */
const referenceType = getData('referenceType') || 'shortcut'
const referenceType = this.data.referenceType || 'shortcut'
node.type += 'Reference'

@@ -992,3 +953,3 @@ // @ts-expect-error: mutate.

}
setData('referenceType')
this.data.referenceType = undefined
}

@@ -1006,5 +967,5 @@

// To do: clean.
if (getData('inReference')) {
if (this.data.inReference) {
/** @type {ReferenceType} */
const referenceType = getData('referenceType') || 'shortcut'
const referenceType = this.data.referenceType || 'shortcut'
node.type += 'Reference'

@@ -1022,3 +983,3 @@ // @ts-expect-error: mutate.

}
setData('referenceType')
this.data.referenceType = undefined
}

@@ -1051,6 +1012,5 @@

// Assume a reference.
setData('inReference', true)
this.data.inReference = true
if (node.type === 'link') {
/** @type {Array<StaticPhrasingContent>} */
// @ts-expect-error: Assume static phrasing content.
/** @type {Array<PhrasingContent>} */
const children = fragment.children

@@ -1091,3 +1051,3 @@ node.children = children

function onexitresource() {
setData('inReference')
this.data.inReference = undefined
}

@@ -1101,3 +1061,3 @@

function onenterreference() {
setData('referenceType', 'collapsed')
this.data.referenceType = 'collapsed'
}

@@ -1120,3 +1080,3 @@

).toLowerCase()
setData('referenceType', 'full')
this.data.referenceType = 'full'
}

@@ -1130,3 +1090,3 @@

function onexitcharacterreferencemarker(token) {
setData('characterReferenceType', token.type)
this.data.characterReferenceType = token.type
}

@@ -1140,3 +1100,3 @@

const data = this.sliceSerialize(token)
const type = getData('characterReferenceType')
const type = this.data.characterReferenceType
/** @type {string} */

@@ -1149,3 +1109,3 @@ let value

)
setData('characterReferenceType')
this.data.characterReferenceType = undefined
} else {

@@ -1231,6 +1191,6 @@ const result = decodeNamedCharacterReference(data)

function heading() {
// @ts-expect-error `depth` will be set later.
return {
type: 'heading',
depth: undefined,
// @ts-expect-error `depth` will be set later.
depth: 0,
children: []

@@ -1247,3 +1207,3 @@ }

/** @returns {HTML} */
/** @returns {Html} */
function html() {

@@ -1353,4 +1313,4 @@ return {

* @param {Config} combined
* @param {Array<Extension | Array<Extension>>} extensions
* @returns {void}
* @param {Array<Array<Extension> | Extension>} extensions
* @returns {undefined}
*/

@@ -1372,3 +1332,3 @@ function configure(combined, extensions) {

* @param {Extension} extension
* @returns {void}
* @returns {undefined}
*/

@@ -1380,17 +1340,26 @@ function extension(combined, extension) {

if (own.call(extension, key)) {
if (key === 'canContainEols') {
const right = extension[key]
if (right) {
combined[key].push(...right)
switch (key) {
case 'canContainEols': {
const right = extension[key]
if (right) {
combined[key].push(...right)
}
break
}
} else if (key === 'transforms') {
const right = extension[key]
if (right) {
combined[key].push(...right)
case 'transforms': {
const right = extension[key]
if (right) {
combined[key].push(...right)
}
break
}
} else if (key === 'enter' || key === 'exit') {
const right = extension[key]
if (right) {
Object.assign(combined[key], right)
case 'enter':
case 'exit': {
const right = extension[key]
if (right) {
Object.assign(combined[key], right)
}
break
}
// No default
}

@@ -1397,0 +1366,0 @@ }

{
"name": "mdast-util-from-markdown",
"version": "1.3.1",
"version": "2.0.0",
"description": "mdast utility to parse markdown",

@@ -31,4 +31,6 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"files": [

@@ -40,25 +42,21 @@ "dev/",

],
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"dependencies": {
"@types/mdast": "^3.0.0",
"@types/unist": "^2.0.0",
"@types/mdast": "^4.0.0",
"@types/unist": "^3.0.0",
"decode-named-character-reference": "^1.0.0",
"mdast-util-to-string": "^3.1.0",
"micromark": "^3.0.0",
"micromark-util-decode-numeric-character-reference": "^1.0.0",
"micromark-util-decode-string": "^1.0.0",
"micromark-util-normalize-identifier": "^1.0.0",
"micromark-util-symbol": "^1.0.0",
"micromark-util-types": "^1.0.0",
"unist-util-stringify-position": "^3.0.0",
"uvu": "^0.5.0"
"devlop": "^1.0.0",
"mdast-util-to-string": "^4.0.0",
"micromark": "^4.0.0",
"micromark-util-decode-numeric-character-reference": "^2.0.0",
"micromark-util-decode-string": "^2.0.0",
"micromark-util-normalize-identifier": "^2.0.0",
"micromark-util-symbol": "^2.0.0",
"micromark-util-types": "^2.0.0",
"unist-util-stringify-position": "^4.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"c8": "^7.0.0",
"c8": "^8.0.0",
"commonmark.json": "^0.30.0",
"esbuild": "^0.17.0",
"esbuild": "^0.18.0",
"gzip-size-cli": "^5.0.0",

@@ -68,3 +66,3 @@ "hast-util-from-html": "^1.0.0",

"mdast-util-to-hast": "^12.0.0",
"micromark-build": "^1.0.0",
"micromark-build": "^2.0.0",
"prettier": "^2.0.0",

@@ -82,25 +80,36 @@ "remark-cli": "^11.0.0",

"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-api-dev": "node --conditions development test/index.js",
"test-api-prod": "node --conditions production test/index.js",
"test-api": "npm run test-api-dev && npm run test-api-prod",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"complexity": "off",
"n/file-extension-in-import": "off",
"unicorn/prefer-code-point": "off",
"unicorn/prefer-switch": "off",
"unicorn/prefer-node-protocol": "off"
},
"overrides": [
{
"files": "**/*.ts",
"rules": {
"@typescript-eslint/consistent-type-definitions": "off"
}
},
{
"files": "test/**/*.js",

@@ -111,15 +120,9 @@ "rules": {

}
]
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
],
"prettier": true,
"rules": {
"complexity": "off",
"max-depth": "off"
}
}
}

@@ -71,3 +71,3 @@ # mdast-util-from-markdown

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

@@ -81,3 +81,3 @@ ```sh

```js
import {fromMarkdown} from 'https://esm.sh/mdast-util-from-markdown@1'
import {fromMarkdown} from 'https://esm.sh/mdast-util-from-markdown@2'
```

@@ -89,3 +89,3 @@

<script type="module">
import {fromMarkdown} from 'https://esm.sh/mdast-util-from-markdown@1?bundle'
import {fromMarkdown} from 'https://esm.sh/mdast-util-from-markdown@2?bundle'
</script>

@@ -135,3 +135,3 @@ ```

This package exports the identifier [`fromMarkdown`][api-frommarkdown].
This package exports the identifier [`fromMarkdown`][api-from-markdown].
There is no default export.

@@ -157,4 +157,4 @@

* `encoding` ([`Encoding`][api-encoding], default: `'utf8'`)
— [character encoding][character-encoding] for when `value` is
[`Buffer`][buffer]
— [character encoding][encoding] for when `value` is
[`Uint8Array`][uint8-array]
* `options` ([`Options`][api-options], optional)

@@ -177,14 +177,12 @@ — configuration

— stack of tokens
* `getData` (`(key: string) => unknown`)
— get data from the key/value store (see [`CompileData`][api-compiledata])
* `setData` (`(key: string, value?: unknown) => void`)
— set data into the key/value store (see [`CompileData`][api-compiledata])
* `buffer` (`() => void`)
* `data` ([`CompileData`][api-compile-data])
— info passed around; key/value store
* `buffer` (`() => undefined`)
— capture some of the output data
* `resume` (`() => string`)
— stop capturing and access the output data
* `enter` (`(node: Node, token: Token, onError?: OnEnterError) => Node`)
— enter a token
* `exit` (`(token: Token, onError?: OnExitError) => Node`)
— exit a token
* `enter` (`(node: Node, token: Token, onError?: OnEnterError) => undefined`)
— enter a node
* `exit` (`(token: Token, onError?: OnExitError) => undefined`)
— exit a node
* `sliceSerialize` (`(token: Token, expandTabs?: boolean) => string`)

@@ -219,8 +217,6 @@ — get the string value of a token

Encodings supported by the [`Buffer`][buffer] class (TypeScript type).
Encodings supported by the [`Uint8Array`][uint8-array] class (TypeScript type).
<!-- To do: link to micromark type, when documented. -->
See [`micromark`][micromark-api] for more info.
See [`micromark`](https://github.com/micromark/micromark#api) for more info.
###### Type

@@ -254,3 +250,3 @@

* `this` ([`CompileContext`][api-compilecontext])
* `this` ([`CompileContext`][api-compile-context])
— context

@@ -262,3 +258,3 @@ * `token` ([`Token`][api-token])

Nothing (`void`).
Nothing (`undefined`).

@@ -272,3 +268,3 @@ ### `OnEnterError`

* `this` ([`CompileContext`][api-compilecontext])
* `this` ([`CompileContext`][api-compile-context])
— context

@@ -282,3 +278,3 @@ * `left` ([`Token`][api-token] or `undefined`)

Nothing (`void`).
Nothing (`undefined`).

@@ -292,3 +288,3 @@ ### `OnExitError`

* `this` ([`CompileContext`][api-compilecontext])
* `this` ([`CompileContext`][api-compile-context])
— context

@@ -302,3 +298,3 @@ * `left` ([`Token`][api-token])

Nothing (`void`).
Nothing (`undefined`).

@@ -321,6 +317,2 @@ ### `Options`

<!-- To do: link to micromark type, when documented. -->
See [`micromark`](https://github.com/micromark/micromark#api) for more info.
###### Type

@@ -349,10 +341,8 @@

<!-- To do: link to micromark type, when documented. -->
See [`micromark`][micromark-api] for more info.
See [`micromark`](https://github.com/micromark/micromark#api) for more info.
###### Type
```ts
type Value = string | Uint8Array
type Value = Uint8Array | string
```

@@ -394,3 +384,3 @@

If you’re interested in extending markdown,
[more information is available in micromark’s readme][micromark-extend].
[more information is available in micromark’s readme][micromark-extension].

@@ -404,9 +394,9 @@ ## Syntax tree

This package is fully typed with [TypeScript][].
It exports the additional types [`CompileContext`][api-compilecontext],
[`CompileData`][api-compiledata],
It exports the additional types [`CompileContext`][api-compile-context],
[`CompileData`][api-compile-data],
[`Encoding`][api-encoding],
[`Extension`][api-extension],
[`Handle`][api-handle],
[`OnEnterError`][api-onentererror],
[`OnExitError`][api-onexiterror],
[`OnEnterError`][api-on-enter-error],
[`OnExitError`][api-on-exit-error],
[`Options`][api-options],

@@ -419,7 +409,10 @@ [`Token`][api-token],

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`mdast-util-from-markdown@^2`, compatible with Node.js 16.
## Security

@@ -470,5 +463,5 @@

[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-from-markdown.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-from-markdown
[size]: https://bundlephobia.com/result?p=mdast-util-from-markdown
[size]: https://bundlejs.com/?q=mdast-util-from-markdown

@@ -521,5 +514,5 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[character-encoding]: https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
[uint8-array]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
[buffer]: https://nodejs.org/api/buffer.html
[encoding]: https://nodejs.org/api/util.html#whatwg-supported-encodings

@@ -532,5 +525,5 @@ [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

[micromark-extension]: https://github.com/micromark/micromark#optionsextensions
[micromark-api]: https://github.com/micromark/micromark/tree/main/packages/micromark#micromarkvalue-encoding-options
[micromark-extend]: https://github.com/micromark/micromark#extensions
[micromark-extension]: https://github.com/micromark/micromark#extensions

@@ -543,7 +536,7 @@ [remark]: https://github.com/remarkjs/remark

[api-frommarkdown]: #frommarkdownvalue-encoding-options
[api-from-markdown]: #frommarkdownvalue-encoding-options
[api-compilecontext]: #compilecontext
[api-compile-context]: #compilecontext
[api-compiledata]: #compiledata
[api-compile-data]: #compiledata

@@ -556,5 +549,5 @@ [api-encoding]: #encoding

[api-onentererror]: #onentererror
[api-on-enter-error]: #onentererror
[api-onexiterror]: #onexiterror
[api-on-exit-error]: #onexiterror

@@ -561,0 +554,0 @@ [api-options]: #options

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc