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.0.4 to 1.1.0

1

dev/index.d.ts

@@ -10,1 +10,2 @@ export {fromMarkdown} from './lib/index.js'

export type CompileContext = import('./lib/index.js').CompileContext
export type OnError = import('./lib/index.js').OnError

@@ -10,4 +10,5 @@ /**

* @typedef {import('./lib/index.js').CompileContext} CompileContext
* @typedef {import('./lib/index.js').OnError} OnError
*/
export {fromMarkdown} from './lib/index.js'

@@ -45,3 +45,3 @@ /**

type: 'fragment'
children: PhrasingContent[]
children: Array<PhrasingContent>
}

@@ -79,2 +79,7 @@ export type _CompileDataFields = {

export type Extension = Partial<NormalizedExtension>
export type OnError = (
this: Omit<CompileContext, 'sliceSerialize'>,
left: Token | undefined,
right: Token
) => void
/**

@@ -85,3 +90,3 @@ * mdast compiler context

stack: Array<Node | Fragment>
tokenStack: Array<Token>
tokenStack: Array<[Token, OnError | undefined]>
/**

@@ -106,3 +111,8 @@ * Set data into the key-value store.

*/
enter: <N extends Node>(this: CompileContext, node: N, token: Token) => N
enter: <N extends Node>(
this: CompileContext,
node: N,
token: Token,
onError?: OnError | undefined
) => N
/**

@@ -109,0 +119,0 @@ * Exit a token.

80

dev/lib/index.js

@@ -34,3 +34,3 @@ /**

*
* @typedef {UnistParent & {type: 'fragment', children: PhrasingContent[]}} Fragment
* @typedef {UnistParent & {type: 'fragment', children: Array<PhrasingContent>}} Fragment
*/

@@ -54,10 +54,12 @@

* Token types mapping to handles
* @typedef {Record<string, Record<string, unknown>|Array.<unknown>> & {canContainEols: Array.<string>, transforms: Array.<Transform>, enter: Handles, exit: Handles}} NormalizedExtension
* @typedef {Record<string, Record<string, unknown>|Array<unknown>> & {canContainEols: Array<string>, transforms: Array<Transform>, enter: Handles, exit: Handles}} NormalizedExtension
* @typedef {Partial<NormalizedExtension>} Extension
* An mdast extension changes how markdown tokens are turned into mdast.
*
* @typedef {(this: Omit<CompileContext, 'sliceSerialize'>, left: Token|undefined, right: Token) => void} OnError
*
* @typedef CompileContext
* mdast compiler context
* @property {Array.<Node | Fragment>} stack
* @property {Array.<Token>} tokenStack
* @property {Array<Node | Fragment>} stack
* @property {Array<[Token, OnError|undefined]>} tokenStack
* @property {(key: string, value?: unknown) => void} setData

@@ -71,3 +73,3 @@ * Set data into the key-value store.

* Stop capturing and access the output data.
* @property {<N extends Node>(this: CompileContext, node: N, token: Token) => N} enter
* @property {<N extends Node>(this: CompileContext, node: N, token: Token, onError?: OnError) => N} enter
* Enter a token.

@@ -81,3 +83,3 @@ * @property {(this: CompileContext, token: Token) => Node} exit

*
* @typedef {{mdastExtensions?: Array.<Extension|Array.<Extension>>}} FromMarkdownOptions
* @typedef {{mdastExtensions?: Array<Extension|Array<Extension>>}} FromMarkdownOptions
* @typedef {ParseOptions & FromMarkdownOptions} Options

@@ -256,3 +258,3 @@ */

/**
* @param {Array.<Event>} events
* @param {Array<Event>} events
* @returns {Root}

@@ -267,3 +269,3 @@ */

const tokenStack = []
/** @type {Array.<number>} */
/** @type {Array<number>} */
const listStack = []

@@ -318,12 +320,5 @@ /** @type {Omit<CompileContext, 'sliceSerialize'>} */

if (tokenStack.length > 0) {
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'
)
const tail = tokenStack[tokenStack.length - 1]
const handler = tail[1] || defaultOnError
handler.call(context, undefined, tail[0])
}

@@ -352,3 +347,3 @@

/**
* @param {Array.<Event>} events
* @param {Array<Event>} events
* @param {number} start

@@ -551,5 +546,6 @@ * @param {number} length

* @param {Token} token
* @param {OnError} [errorHandler]
* @returns {N}
*/
function enter(node, token) {
function enter(node, token, errorHandler) {
const parent = this.stack[this.stack.length - 1]

@@ -561,3 +557,3 @@ assert(parent, 'expected `parent`')

this.stack.push(node)
this.tokenStack.push(token)
this.tokenStack.push([token, errorHandler])
// @ts-expect-error: `end` will be patched later.

@@ -600,14 +596,5 @@ node.position = {start: point(token.start)}

)
} 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'
)
} else if (open[0].type !== token.type) {
const handler = open[1] || defaultOnError
handler.call(this, token, open[0])
}

@@ -1109,3 +1096,3 @@

* @param {Extension} combined
* @param {Array.<Extension|Array.<Extension>>} extensions
* @param {Array<Extension|Array<Extension>>} extensions
* @returns {Extension}

@@ -1157,1 +1144,26 @@ */

}
/** @type {OnError} */
function defaultOnError(left, right) {
if (left) {
throw new Error(
'Cannot close `' +
left.type +
'` (' +
stringifyPosition({start: left.start, end: left.end}) +
'): a different token (`' +
right.type +
'`, ' +
stringifyPosition({start: right.start, end: right.end}) +
') is open'
)
} else {
throw new Error(
'Cannot close document, a token (`' +
right.type +
'`, ' +
stringifyPosition({start: right.start, end: right.end}) +
') is still open'
)
}
}

@@ -10,1 +10,2 @@ export {fromMarkdown} from './lib/index.js'

export type CompileContext = import('./lib/index.js').CompileContext
export type OnError = import('./lib/index.js').OnError

@@ -10,3 +10,4 @@ /**

* @typedef {import('./lib/index.js').CompileContext} CompileContext
* @typedef {import('./lib/index.js').OnError} OnError
*/
export {fromMarkdown} from './lib/index.js'

@@ -45,3 +45,3 @@ /**

type: 'fragment'
children: PhrasingContent[]
children: Array<PhrasingContent>
}

@@ -79,2 +79,7 @@ export type _CompileDataFields = {

export type Extension = Partial<NormalizedExtension>
export type OnError = (
this: Omit<CompileContext, 'sliceSerialize'>,
left: Token | undefined,
right: Token
) => void
/**

@@ -85,3 +90,3 @@ * mdast compiler context

stack: Array<Node | Fragment>
tokenStack: Array<Token>
tokenStack: Array<[Token, OnError | undefined]>
/**

@@ -106,3 +111,8 @@ * Set data into the key-value store.

*/
enter: <N extends Node>(this: CompileContext, node: N, token: Token) => N
enter: <N extends Node>(
this: CompileContext,
node: N,
token: Token,
onError?: OnError | undefined
) => N
/**

@@ -109,0 +119,0 @@ * Exit a token.

@@ -34,3 +34,3 @@ /**

*
* @typedef {UnistParent & {type: 'fragment', children: PhrasingContent[]}} Fragment
* @typedef {UnistParent & {type: 'fragment', children: Array<PhrasingContent>}} Fragment
*/

@@ -54,10 +54,12 @@

* Token types mapping to handles
* @typedef {Record<string, Record<string, unknown>|Array.<unknown>> & {canContainEols: Array.<string>, transforms: Array.<Transform>, enter: Handles, exit: Handles}} NormalizedExtension
* @typedef {Record<string, Record<string, unknown>|Array<unknown>> & {canContainEols: Array<string>, transforms: Array<Transform>, enter: Handles, exit: Handles}} NormalizedExtension
* @typedef {Partial<NormalizedExtension>} Extension
* An mdast extension changes how markdown tokens are turned into mdast.
*
* @typedef {(this: Omit<CompileContext, 'sliceSerialize'>, left: Token|undefined, right: Token) => void} OnError
*
* @typedef CompileContext
* mdast compiler context
* @property {Array.<Node | Fragment>} stack
* @property {Array.<Token>} tokenStack
* @property {Array<Node | Fragment>} stack
* @property {Array<[Token, OnError|undefined]>} tokenStack
* @property {(key: string, value?: unknown) => void} setData

@@ -71,3 +73,3 @@ * Set data into the key-value store.

* Stop capturing and access the output data.
* @property {<N extends Node>(this: CompileContext, node: N, token: Token) => N} enter
* @property {<N extends Node>(this: CompileContext, node: N, token: Token, onError?: OnError) => N} enter
* Enter a token.

@@ -81,3 +83,3 @@ * @property {(this: CompileContext, token: Token) => Node} exit

*
* @typedef {{mdastExtensions?: Array.<Extension|Array.<Extension>>}} FromMarkdownOptions
* @typedef {{mdastExtensions?: Array<Extension|Array<Extension>>}} FromMarkdownOptions
* @typedef {ParseOptions & FromMarkdownOptions} Options

@@ -247,3 +249,3 @@ */

/**
* @param {Array.<Event>} events
* @param {Array<Event>} events
* @returns {Root}

@@ -264,3 +266,3 @@ */

const tokenStack = []
/** @type {Array.<number>} */
/** @type {Array<number>} */

@@ -318,12 +320,5 @@ const listStack = []

if (tokenStack.length > 0) {
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'
)
const tail = tokenStack[tokenStack.length - 1]
const handler = tail[1] || defaultOnError
handler.call(context, undefined, tail[0])
} // Figure out `root` position.

@@ -360,3 +355,3 @@

/**
* @param {Array.<Event>} events
* @param {Array<Event>} events
* @param {number} start

@@ -566,6 +561,7 @@ * @param {number} length

* @param {Token} token
* @param {OnError} [errorHandler]
* @returns {N}
*/
function enter(node, token) {
function enter(node, token, errorHandler) {
const parent = this.stack[this.stack.length - 1]

@@ -575,3 +571,3 @@ // @ts-expect-error: Assume `Node` can exist as a child of `parent`.

this.stack.push(node)
this.tokenStack.push(token) // @ts-expect-error: `end` will be patched later.
this.tokenStack.push([token, errorHandler]) // @ts-expect-error: `end` will be patched later.

@@ -618,20 +614,5 @@ node.position = {

)
} 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'
)
} else if (open[0].type !== token.type) {
const handler = open[1] || defaultOnError
handler.call(this, token, open[0])
}

@@ -1179,3 +1160,3 @@

* @param {Extension} combined
* @param {Array.<Extension|Array.<Extension>>} extensions
* @param {Array<Extension|Array<Extension>>} extensions
* @returns {Extension}

@@ -1229,1 +1210,35 @@ */

}
/** @type {OnError} */
function defaultOnError(left, right) {
if (left) {
throw new Error(
'Cannot close `' +
left.type +
'` (' +
stringifyPosition({
start: left.start,
end: left.end
}) +
'): a different token (`' +
right.type +
'`, ' +
stringifyPosition({
start: right.start,
end: right.end
}) +
') is open'
)
} else {
throw new Error(
'Cannot close document, a token (`' +
right.type +
'`, ' +
stringifyPosition({
start: right.start,
end: right.end
}) +
') is still open'
)
}
}
{
"name": "mdast-util-from-markdown",
"version": "1.0.4",
"version": "1.1.0",
"description": "mdast utility to parse markdown",

@@ -78,3 +78,3 @@ "license": "MIT",

"unified": "^10.0.0",
"xo": "^0.45.0"
"xo": "^0.46.0"
},

@@ -81,0 +81,0 @@ "scripts": {

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

The export map supports the endorsed
[`development` condition](https://nodejs.org/api/packages.html#packages\_resolving\_user\_conditions).
[`development` condition](https://nodejs.org/api/packages.html#packages_resolving_user_conditions).
Run `node --conditions development module.js` to get instrumented dev code.

@@ -101,3 +101,3 @@ Without this condition, production code is loaded.

Array of syntax extensions (`Array.<MicromarkSyntaxExtension>`, default: `[]`).
Array of syntax extensions (`Array<MicromarkSyntaxExtension>`, default: `[]`).
Passed to [`micromark` as `extensions`][micromark-extensions].

@@ -107,3 +107,3 @@

Array of mdast extensions (`Array.<MdastExtension>`, default: `[]`).
Array of mdast extensions (`Array<MdastExtension>`, default: `[]`).

@@ -110,0 +110,0 @@ ##### Returns

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