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 2.0.0 to 2.0.1

dev/lib/index.d.ts.map

269

dev/lib/index.d.ts

@@ -1,55 +0,94 @@

export function fromMarkdown(
value: Value,
encoding?: Encoding | null | undefined,
options?: Options | null | undefined
): Root
export function fromMarkdown(
value: Value,
options?: Options | null | undefined
): Root
export type Break = import('mdast').Break
export type Blockquote = import('mdast').Blockquote
export type Code = import('mdast').Code
export type Definition = import('mdast').Definition
export type Emphasis = import('mdast').Emphasis
export type Heading = import('mdast').Heading
export type Html = import('mdast').Html
export type Image = import('mdast').Image
export type InlineCode = import('mdast').InlineCode
export type Link = import('mdast').Link
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
export type Strong = import('mdast').Strong
export type Text = import('mdast').Text
export type ThematicBreak = import('mdast').ThematicBreak
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
/**
* 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 | Options | null | undefined} [encoding]
* Character encoding for when `value` is `Buffer`.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {Root}
* mdast tree.
*/
export function fromMarkdown(value: Value, encoding?: Encoding | null | undefined, options?: Options | null | undefined): Root;
/**
* 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 | Options | null | undefined} [encoding]
* Character encoding for when `value` is `Buffer`.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {Root}
* mdast tree.
*/
export function fromMarkdown(value: Value, options?: Options | null | undefined): Root;
export type Break = import('mdast').Break;
export type Blockquote = import('mdast').Blockquote;
export type Code = import('mdast').Code;
export type Definition = import('mdast').Definition;
export type Emphasis = import('mdast').Emphasis;
export type Heading = import('mdast').Heading;
export type Html = import('mdast').Html;
export type Image = import('mdast').Image;
export type InlineCode = import('mdast').InlineCode;
export type Link = import('mdast').Link;
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;
export type Strong = import('mdast').Strong;
export type Text = import('mdast').Text;
export type ThematicBreak = import('mdast').ThematicBreak;
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 Fragment = Omit<Parent, 'children' | 'type'> & {
type: 'fragment'
children: Array<PhrasingContent>
}
type: 'fragment';
children: Array<PhrasingContent>;
};
/**
* Extra transform, to change the AST afterwards.
*/
export type Transform = (tree: Root) => Root | null | undefined | void
export type Transform = (tree: Root) => Root | null | undefined | void;
/**
* Handle a token.
*/
export type Handle = (this: CompileContext, token: Token) => undefined | void
export type Handle = (this: CompileContext, token: Token) => undefined | void;
/**
* Token types mapping to handles
*/
export type Handles = Record<string, Handle>
export type Handles = Record<string, Handle>;
/**

@@ -59,7 +98,3 @@ * Handle the case where the `right` token is open, but it is closed (by the

*/
export type OnEnterError = (
this: Omit<CompileContext, 'sliceSerialize'>,
left: Token | undefined,
right: Token
) => undefined
export type OnEnterError = (this: Omit<CompileContext, 'sliceSerialize'>, left: Token | undefined, right: Token) => undefined;
/**

@@ -69,7 +104,3 @@ * Handle the case where the `right` token is open but it is closed by

*/
export type OnExitError = (
this: Omit<CompileContext, 'sliceSerialize'>,
left: Token,
right: Token
) => undefined
export type OnExitError = (this: Omit<CompileContext, 'sliceSerialize'>, left: Token, right: Token) => undefined;
/**

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

*/
export type TokenTuple = [Token, OnEnterError | undefined]
export type TokenTuple = [Token, OnEnterError | undefined];
/**

@@ -87,23 +118,23 @@ * Configuration.

export type Config = {
/**
* Token types where line endings are used.
*/
canContainEols: Array<string>
/**
* Opening handles.
*/
enter: Handles
/**
* Closing handles.
*/
exit: Handles
/**
* Tree transforms.
*/
transforms: Array<Transform>
}
/**
* Token types where line endings are used.
*/
canContainEols: Array<string>;
/**
* Opening handles.
*/
enter: Handles;
/**
* Closing handles.
*/
exit: Handles;
/**
* Tree transforms.
*/
transforms: Array<Transform>;
};
/**
* Change how markdown tokens from micromark are turned into mdast.
*/
export type Extension = Partial<Config>
export type Extension = Partial<Config>;
/**

@@ -113,44 +144,39 @@ * mdast compiler context.

export type CompileContext = {
/**
* Stack of nodes.
*/
stack: Array<Fragment | Nodes>
/**
* Stack of tokens.
*/
tokenStack: Array<TokenTuple>
/**
* Capture some of the output data.
*/
buffer: (this: CompileContext) => undefined
/**
* Stop capturing and access the output data.
*/
resume: (this: CompileContext) => string
/**
* Enter a node.
*/
enter: (
this: CompileContext,
node: Nodes,
token: Token,
onError?: OnEnterError
) => undefined
/**
* Exit a node.
*/
exit: (this: CompileContext, token: Token, onError?: OnExitError) => undefined
/**
* Get the string value of a token.
*/
sliceSerialize: TokenizeContext['sliceSerialize']
/**
* Configuration.
*/
config: Config
/**
* Info passed around; key/value store.
*/
data: CompileData
}
/**
* Stack of nodes.
*/
stack: Array<Fragment | Nodes>;
/**
* Stack of tokens.
*/
tokenStack: Array<TokenTuple>;
/**
* Capture some of the output data.
*/
buffer: (this: CompileContext) => undefined;
/**
* Stop capturing and access the output data.
*/
resume: (this: CompileContext) => string;
/**
* Enter a node.
*/
enter: (this: CompileContext, node: Nodes, token: Token, onError?: OnEnterError) => undefined;
/**
* Exit a node.
*/
exit: (this: CompileContext, token: Token, onError?: OnExitError) => undefined;
/**
* Get the string value of a token.
*/
sliceSerialize: TokenizeContext['sliceSerialize'];
/**
* Configuration.
*/
config: Config;
/**
* Info passed around; key/value store.
*/
data: CompileData;
};
/**

@@ -160,10 +186,11 @@ * Configuration for how to build mdast.

export type FromMarkdownOptions = {
/**
* Extensions for this utility to change how tokens are turned into a tree.
*/
mdastExtensions?: Array<Extension | Array<Extension>> | null | undefined
}
/**
* Extensions for this utility to change how tokens are turned into a tree.
*/
mdastExtensions?: Array<Extension | Array<Extension>> | null | undefined;
};
/**
* Configuration.
*/
export type Options = ParseOptions & FromMarkdownOptions
export type Options = ParseOptions & FromMarkdownOptions;
//# sourceMappingURL=index.d.ts.map

@@ -179,3 +179,5 @@ /**

postprocess(
parse(options).document().write(preprocess()(value, encoding, true))
parse(options)
.document()
.write(preprocess()(value, encoding, true))
)

@@ -249,2 +251,3 @@ )

characterReferenceValue: onexitcharacterreferencevalue,
characterReference: onexitcharacterreference,
codeFenced: closer(onexitcodefenced),

@@ -1204,7 +1207,16 @@ codeFencedFence: onexitcodefencedfence,

const tail = this.stack[this.stack.length - 1]
assert(tail, 'expected `node`')
assert('value' in tail, 'expected `node.value`')
tail.value += value
}
/**
* @this {CompileContext}
* @type {Handle}
*/
function onexitcharacterreference(token) {
const tail = this.stack.pop()
assert(tail, 'expected `node`')
assert(tail.position, 'expected `node.position`')
assert('value' in tail, 'expected `node.value`')
tail.value += value
tail.position.end = point(token.end)

@@ -1211,0 +1223,0 @@ }

// Note: types exported from `index.d.ts`.
export {fromMarkdown} from './lib/index.js'
export { fromMarkdown } from './lib/index.js';

@@ -1,55 +0,94 @@

export function fromMarkdown(
value: Value,
encoding?: Encoding | null | undefined,
options?: Options | null | undefined
): Root
export function fromMarkdown(
value: Value,
options?: Options | null | undefined
): Root
export type Break = import('mdast').Break
export type Blockquote = import('mdast').Blockquote
export type Code = import('mdast').Code
export type Definition = import('mdast').Definition
export type Emphasis = import('mdast').Emphasis
export type Heading = import('mdast').Heading
export type Html = import('mdast').Html
export type Image = import('mdast').Image
export type InlineCode = import('mdast').InlineCode
export type Link = import('mdast').Link
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
export type Strong = import('mdast').Strong
export type Text = import('mdast').Text
export type ThematicBreak = import('mdast').ThematicBreak
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
/**
* 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 | Options | null | undefined} [encoding]
* Character encoding for when `value` is `Buffer`.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {Root}
* mdast tree.
*/
export function fromMarkdown(value: Value, encoding?: Encoding | null | undefined, options?: Options | null | undefined): Root;
/**
* 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 | Options | null | undefined} [encoding]
* Character encoding for when `value` is `Buffer`.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {Root}
* mdast tree.
*/
export function fromMarkdown(value: Value, options?: Options | null | undefined): Root;
export type Break = import('mdast').Break;
export type Blockquote = import('mdast').Blockquote;
export type Code = import('mdast').Code;
export type Definition = import('mdast').Definition;
export type Emphasis = import('mdast').Emphasis;
export type Heading = import('mdast').Heading;
export type Html = import('mdast').Html;
export type Image = import('mdast').Image;
export type InlineCode = import('mdast').InlineCode;
export type Link = import('mdast').Link;
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;
export type Strong = import('mdast').Strong;
export type Text = import('mdast').Text;
export type ThematicBreak = import('mdast').ThematicBreak;
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 Fragment = Omit<Parent, 'children' | 'type'> & {
type: 'fragment'
children: Array<PhrasingContent>
}
type: 'fragment';
children: Array<PhrasingContent>;
};
/**
* Extra transform, to change the AST afterwards.
*/
export type Transform = (tree: Root) => Root | null | undefined | void
export type Transform = (tree: Root) => Root | null | undefined | void;
/**
* Handle a token.
*/
export type Handle = (this: CompileContext, token: Token) => undefined | void
export type Handle = (this: CompileContext, token: Token) => undefined | void;
/**
* Token types mapping to handles
*/
export type Handles = Record<string, Handle>
export type Handles = Record<string, Handle>;
/**

@@ -59,7 +98,3 @@ * Handle the case where the `right` token is open, but it is closed (by the

*/
export type OnEnterError = (
this: Omit<CompileContext, 'sliceSerialize'>,
left: Token | undefined,
right: Token
) => undefined
export type OnEnterError = (this: Omit<CompileContext, 'sliceSerialize'>, left: Token | undefined, right: Token) => undefined;
/**

@@ -69,7 +104,3 @@ * Handle the case where the `right` token is open but it is closed by

*/
export type OnExitError = (
this: Omit<CompileContext, 'sliceSerialize'>,
left: Token,
right: Token
) => undefined
export type OnExitError = (this: Omit<CompileContext, 'sliceSerialize'>, left: Token, right: Token) => undefined;
/**

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

*/
export type TokenTuple = [Token, OnEnterError | undefined]
export type TokenTuple = [Token, OnEnterError | undefined];
/**

@@ -87,23 +118,23 @@ * Configuration.

export type Config = {
/**
* Token types where line endings are used.
*/
canContainEols: Array<string>
/**
* Opening handles.
*/
enter: Handles
/**
* Closing handles.
*/
exit: Handles
/**
* Tree transforms.
*/
transforms: Array<Transform>
}
/**
* Token types where line endings are used.
*/
canContainEols: Array<string>;
/**
* Opening handles.
*/
enter: Handles;
/**
* Closing handles.
*/
exit: Handles;
/**
* Tree transforms.
*/
transforms: Array<Transform>;
};
/**
* Change how markdown tokens from micromark are turned into mdast.
*/
export type Extension = Partial<Config>
export type Extension = Partial<Config>;
/**

@@ -113,44 +144,39 @@ * mdast compiler context.

export type CompileContext = {
/**
* Stack of nodes.
*/
stack: Array<Fragment | Nodes>
/**
* Stack of tokens.
*/
tokenStack: Array<TokenTuple>
/**
* Capture some of the output data.
*/
buffer: (this: CompileContext) => undefined
/**
* Stop capturing and access the output data.
*/
resume: (this: CompileContext) => string
/**
* Enter a node.
*/
enter: (
this: CompileContext,
node: Nodes,
token: Token,
onError?: OnEnterError
) => undefined
/**
* Exit a node.
*/
exit: (this: CompileContext, token: Token, onError?: OnExitError) => undefined
/**
* Get the string value of a token.
*/
sliceSerialize: TokenizeContext['sliceSerialize']
/**
* Configuration.
*/
config: Config
/**
* Info passed around; key/value store.
*/
data: CompileData
}
/**
* Stack of nodes.
*/
stack: Array<Fragment | Nodes>;
/**
* Stack of tokens.
*/
tokenStack: Array<TokenTuple>;
/**
* Capture some of the output data.
*/
buffer: (this: CompileContext) => undefined;
/**
* Stop capturing and access the output data.
*/
resume: (this: CompileContext) => string;
/**
* Enter a node.
*/
enter: (this: CompileContext, node: Nodes, token: Token, onError?: OnEnterError) => undefined;
/**
* Exit a node.
*/
exit: (this: CompileContext, token: Token, onError?: OnExitError) => undefined;
/**
* Get the string value of a token.
*/
sliceSerialize: TokenizeContext['sliceSerialize'];
/**
* Configuration.
*/
config: Config;
/**
* Info passed around; key/value store.
*/
data: CompileData;
};
/**

@@ -160,10 +186,11 @@ * Configuration for how to build mdast.

export type FromMarkdownOptions = {
/**
* Extensions for this utility to change how tokens are turned into a tree.
*/
mdastExtensions?: Array<Extension | Array<Extension>> | null | undefined
}
/**
* Extensions for this utility to change how tokens are turned into a tree.
*/
mdastExtensions?: Array<Extension | Array<Extension>> | null | undefined;
};
/**
* Configuration.
*/
export type Options = ParseOptions & FromMarkdownOptions
export type Options = ParseOptions & FromMarkdownOptions;
//# sourceMappingURL=index.d.ts.map

@@ -136,10 +136,10 @@ /**

import {toString} from 'mdast-util-to-string'
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 {decodeNamedCharacterReference} from 'decode-named-character-reference'
import {stringifyPosition} from 'unist-util-stringify-position'
const own = {}.hasOwnProperty
import { toString } from 'mdast-util-to-string';
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 { decodeNamedCharacterReference } from 'decode-named-character-reference';
import { stringifyPosition } from 'unist-util-stringify-position';
const own = {}.hasOwnProperty;

@@ -171,10 +171,6 @@ /**

if (typeof encoding !== 'string') {
options = encoding
encoding = undefined
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))));
}

@@ -246,2 +242,3 @@

characterReferenceValue: onexitcharacterreferencevalue,
characterReference: onexitcharacterreference,
codeFenced: closer(onexitcodefenced),

@@ -286,8 +283,8 @@ codeFencedFence: onexitcodefencedfence,

}
}
configure(config, (options || {}).mdastExtensions || [])
};
configure(config, (options || {}).mdastExtensions || []);
/** @type {CompileData} */
const data = {}
return compile
const data = {};
return compile;

@@ -307,3 +304,3 @@ /**

children: []
}
};
/** @type {Omit<CompileContext, 'sliceSerialize'>} */

@@ -319,34 +316,25 @@ const context = {

data
}
};
/** @type {Array<number>} */
const listStack = []
let index = -1
const listStack = [];
let index = -1;
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][1].type === "listOrdered" || events[index][1].type === "listUnordered") {
if (events[index][0] === 'enter') {
listStack.push(index)
listStack.push(index);
} else {
const tail = listStack.pop()
index = prepareList(events, tail, index)
const tail = listStack.pop();
index = prepareList(events, tail, index);
}
}
}
index = -1
index = -1;
while (++index < events.length) {
const handler = config[events[index][0]]
const handler = config[events[index][0]];
if (own.call(handler, events[index][1].type)) {
handler[events[index][1].type].call(
Object.assign(
{
sliceSerialize: events[index][2].sliceSerialize
},
context
),
events[index][1]
)
handler[events[index][1].type].call(Object.assign({
sliceSerialize: events[index][2].sliceSerialize
}, context), events[index][1]);
}

@@ -357,5 +345,5 @@ }

if (context.tokenStack.length > 0) {
const tail = context.tokenStack[context.tokenStack.length - 1]
const handler = tail[1] || defaultOnError
handler.call(context, undefined, tail[0])
const tail = context.tokenStack[context.tokenStack.length - 1];
const handler = tail[1] || defaultOnError;
handler.call(context, undefined, tail[0]);
}

@@ -365,28 +353,20 @@

tree.position = {
start: point(
events.length > 0
? events[0][1].start
: {
line: 1,
column: 1,
offset: 0
}
),
end: point(
events.length > 0
? events[events.length - 2][1].end
: {
line: 1,
column: 1,
offset: 0
}
)
}
start: point(events.length > 0 ? events[0][1].start : {
line: 1,
column: 1,
offset: 0
}),
end: point(events.length > 0 ? events[events.length - 2][1].end : {
line: 1,
column: 1,
offset: 0
})
};
// Call transforms.
index = -1
index = -1;
while (++index < config.transforms.length) {
tree = config.transforms[index](tree) || tree
tree = config.transforms[index](tree) || tree;
}
return tree
return tree;
}

@@ -401,110 +381,86 @@

function prepareList(events, start, length) {
let index = start - 1
let containerBalance = -1
let listSpread = false
let index = start - 1;
let containerBalance = -1;
let listSpread = false;
/** @type {Token | undefined} */
let listItem
let listItem;
/** @type {number | undefined} */
let lineIndex
let lineIndex;
/** @type {number | undefined} */
let firstBlankLineIndex
let firstBlankLineIndex;
/** @type {boolean | undefined} */
let atMarker
let atMarker;
while (++index <= length) {
const event = events[index]
const event = events[index];
switch (event[1].type) {
case 'listUnordered':
case 'listOrdered':
case 'blockQuote': {
if (event[0] === 'enter') {
containerBalance++
} else {
containerBalance--
case "listUnordered":
case "listOrdered":
case "blockQuote":
{
if (event[0] === 'enter') {
containerBalance++;
} else {
containerBalance--;
}
atMarker = undefined;
break;
}
atMarker = undefined
break
}
case '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;
}
atMarker = undefined
break;
}
break
}
case 'linePrefix':
case 'listItemValue':
case 'listItemMarker':
case 'listItemPrefix':
case 'listItemPrefixWhitespace': {
// Empty.
case "linePrefix":
case "listItemValue":
case "listItemMarker":
case "listItemPrefix":
case "listItemPrefixWhitespace":
{
// Empty.
break
}
default: {
atMarker = undefined
}
break;
}
default:
{
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 (!containerBalance && event[0] === 'enter' && event[1].type === "listItemPrefix" || containerBalance === -1 && event[0] === 'exit' && (event[1].type === "listUnordered" || event[1].type === "listOrdered")) {
if (listItem) {
let tailIndex = index
lineIndex = undefined
let tailIndex = index;
lineIndex = undefined;
while (tailIndex--) {
const tailEvent = events[tailIndex]
if (
tailEvent[1].type === 'lineEnding' ||
tailEvent[1].type === 'lineEndingBlank'
) {
if (tailEvent[0] === 'exit') continue
const 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
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'
) {
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
break;
}
}
if (
firstBlankLineIndex &&
(!lineIndex || firstBlankLineIndex < lineIndex)
) {
listItem._spread = true
if (firstBlankLineIndex && (!lineIndex || firstBlankLineIndex < lineIndex)) {
listItem._spread = true;
}
// Fix position.
listItem.end = Object.assign(
{},
lineIndex ? events[lineIndex][1].start : event[1].end
)
events.splice(lineIndex || index, 0, ['exit', listItem, event[2]])
index++
length++
listItem.end = Object.assign({}, 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') {
if (event[1].type === "listItemPrefix") {
/** @type {Token} */

@@ -517,14 +473,14 @@ const item = {

end: undefined
}
listItem = item
events.splice(index, 0, ['enter', item, event[2]])
index++
length++
firstBlankLineIndex = undefined
atMarker = true
};
listItem = item;
events.splice(index, 0, ['enter', item, event[2]]);
index++;
length++;
firstBlankLineIndex = undefined;
atMarker = true;
}
}
}
events[start][1]._spread = listSpread
return length
events[start][1]._spread = listSpread;
return length;
}

@@ -543,3 +499,3 @@

function opener(create, and) {
return open
return open;

@@ -552,4 +508,4 @@ /**

function open(token) {
enter.call(this, create(token), token)
if (and) and.call(this, token)
enter.call(this, create(token), token);
if (and) and.call(this, token);
}

@@ -566,3 +522,3 @@ }

children: []
})
});
}

@@ -583,8 +539,8 @@

function enter(node, token, errorHandler) {
const parent = this.stack[this.stack.length - 1]
const parent = this.stack[this.stack.length - 1];
/** @type {Array<Nodes>} */
const siblings = parent.children
siblings.push(node)
this.stack.push(node)
this.tokenStack.push([token, errorHandler])
const siblings = parent.children;
siblings.push(node);
this.stack.push(node);
this.tokenStack.push([token, errorHandler]);
node.position = {

@@ -594,3 +550,3 @@ start: point(token.start),

end: undefined
}
};
}

@@ -607,3 +563,3 @@

function closer(and) {
return close
return close;

@@ -616,4 +572,4 @@ /**

function close(token) {
if (and) and.call(this, token)
exit.call(this, token)
if (and) and.call(this, token);
exit.call(this, token);
}

@@ -633,24 +589,18 @@ }

function exit(token, onExitError) {
const node = this.stack.pop()
const open = this.tokenStack.pop()
const node = this.stack.pop();
const open = this.tokenStack.pop();
if (!open) {
throw new Error(
'Cannot close `' +
token.type +
'` (' +
stringifyPosition({
start: token.start,
end: token.end
}) +
'): it’s not open'
)
throw new Error('Cannot close `' + token.type + '` (' + stringifyPosition({
start: token.start,
end: token.end
}) + '): it’s not open');
} else if (open[0].type !== token.type) {
if (onExitError) {
onExitError.call(this, token, open[0])
onExitError.call(this, token, open[0]);
} else {
const handler = open[1] || defaultOnError
handler.call(this, token, open[0])
const handler = open[1] || defaultOnError;
handler.call(this, token, open[0]);
}
}
node.position.end = point(token.end)
node.position.end = point(token.end);
}

@@ -663,3 +613,3 @@

function resume() {
return toString(this.stack.pop())
return toString(this.stack.pop());
}

@@ -676,3 +626,3 @@

function onenterlistordered() {
this.data.expectingFirstListItemValue = true
this.data.expectingFirstListItemValue = true;
}

@@ -686,5 +636,5 @@

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

@@ -698,5 +648,5 @@ }

function onexitcodefencedfenceinfo() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.lang = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.lang = data;
}

@@ -709,5 +659,5 @@

function onexitcodefencedfencemeta() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.meta = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.meta = data;
}

@@ -721,5 +671,5 @@

// Exit if this is the closing fence.
if (this.data.flowCodeInside) return
this.buffer()
this.data.flowCodeInside = true
if (this.data.flowCodeInside) return;
this.buffer();
this.data.flowCodeInside = true;
}

@@ -732,6 +682,6 @@

function onexitcodefenced() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
this.data.flowCodeInside = undefined
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '');
this.data.flowCodeInside = undefined;
}

@@ -744,5 +694,5 @@

function onexitcodeindented() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.value = data.replace(/(\r?\n|\r)$/g, '')
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.value = data.replace(/(\r?\n|\r)$/g, '');
}

@@ -755,8 +705,6 @@

function onexitdefinitionlabelstring(token) {
const label = this.resume()
const node = this.stack[this.stack.length - 1]
node.label = label
node.identifier = normalizeIdentifier(
this.sliceSerialize(token)
).toLowerCase()
const label = this.resume();
const node = this.stack[this.stack.length - 1];
node.label = label;
node.identifier = normalizeIdentifier(this.sliceSerialize(token)).toLowerCase();
}

@@ -769,5 +717,5 @@

function onexitdefinitiontitlestring() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.title = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.title = data;
}

@@ -780,5 +728,5 @@

function onexitdefinitiondestinationstring() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.url = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.url = data;
}

@@ -791,6 +739,6 @@

function onexitatxheadingsequence(token) {
const node = this.stack[this.stack.length - 1]
const node = this.stack[this.stack.length - 1];
if (!node.depth) {
const depth = this.sliceSerialize(token).length
node.depth = depth
const depth = this.sliceSerialize(token).length;
node.depth = depth;
}

@@ -804,3 +752,3 @@ }

function onexitsetextheadingtext() {
this.data.setextHeadingSlurpLineEnding = true
this.data.setextHeadingSlurpLineEnding = true;
}

@@ -813,4 +761,4 @@

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

@@ -823,3 +771,3 @@

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

@@ -833,9 +781,9 @@

function onenterdata(token) {
const node = this.stack[this.stack.length - 1]
const node = this.stack[this.stack.length - 1];
/** @type {Array<Nodes>} */
const siblings = node.children
let tail = siblings[siblings.length - 1]
const siblings = node.children;
let tail = siblings[siblings.length - 1];
if (!tail || tail.type !== 'text') {
// Add a new text node.
tail = text()
tail = text();
tail.position = {

@@ -845,6 +793,6 @@ start: point(token.start),

end: undefined
}
siblings.push(tail)
};
siblings.push(tail);
}
this.stack.push(tail)
this.stack.push(tail);
}

@@ -858,5 +806,5 @@

function onexitdata(token) {
const tail = this.stack.pop()
tail.value += this.sliceSerialize(token)
tail.position.end = point(token.end)
const tail = this.stack.pop();
tail.value += this.sliceSerialize(token);
tail.position.end = point(token.end);
}

@@ -870,16 +818,13 @@

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

@@ -894,3 +839,3 @@ }

function onexithardbreak() {
this.data.atHardBreak = true
this.data.atHardBreak = true;
}

@@ -904,5 +849,5 @@

function onexithtmlflow() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.value = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.value = data;
}

@@ -916,5 +861,5 @@

function onexithtmltext() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.value = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.value = data;
}

@@ -928,5 +873,5 @@

function onexitcodetext() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.value = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.value = data;
}

@@ -940,22 +885,23 @@

function onexitlink() {
const node = this.stack[this.stack.length - 1]
const node = this.stack[this.stack.length - 1];
// Note: there are also `identifier` and `label` fields on this link node!
// These are used / cleaned here.
// To do: clean.
if (this.data.inReference) {
/** @type {ReferenceType} */
const referenceType = this.data.referenceType || 'shortcut'
node.type += 'Reference'
const referenceType = this.data.referenceType || 'shortcut';
node.type += 'Reference';
// @ts-expect-error: mutate.
node.referenceType = referenceType
node.referenceType = referenceType;
// @ts-expect-error: mutate.
delete node.url
delete node.title
delete node.url;
delete node.title;
} else {
// @ts-expect-error: mutate.
delete node.identifier
delete node.identifier;
// @ts-expect-error: mutate.
delete node.label
delete node.label;
}
this.data.referenceType = undefined
this.data.referenceType = undefined;
}

@@ -969,22 +915,23 @@

function onexitimage() {
const node = this.stack[this.stack.length - 1]
const node = this.stack[this.stack.length - 1];
// Note: there are also `identifier` and `label` fields on this link node!
// These are used / cleaned here.
// To do: clean.
if (this.data.inReference) {
/** @type {ReferenceType} */
const referenceType = this.data.referenceType || 'shortcut'
node.type += 'Reference'
const referenceType = this.data.referenceType || 'shortcut';
node.type += 'Reference';
// @ts-expect-error: mutate.
node.referenceType = referenceType
node.referenceType = referenceType;
// @ts-expect-error: mutate.
delete node.url
delete node.title
delete node.url;
delete node.title;
} else {
// @ts-expect-error: mutate.
delete node.identifier
delete node.identifier;
// @ts-expect-error: mutate.
delete node.label
delete node.label;
}
this.data.referenceType = undefined
this.data.referenceType = undefined;
}

@@ -998,9 +945,9 @@

function onexitlabeltext(token) {
const string = this.sliceSerialize(token)
const ancestor = this.stack[this.stack.length - 2]
const string = this.sliceSerialize(token);
const ancestor = this.stack[this.stack.length - 2];
// @ts-expect-error: stash this on the node, as it might become a reference
// later.
ancestor.label = decodeString(string)
ancestor.label = decodeString(string);
// @ts-expect-error: same as above.
ancestor.identifier = normalizeIdentifier(string).toLowerCase()
ancestor.identifier = normalizeIdentifier(string).toLowerCase();
}

@@ -1014,13 +961,13 @@

function onexitlabel() {
const fragment = this.stack[this.stack.length - 1]
const value = this.resume()
const node = this.stack[this.stack.length - 1]
const fragment = this.stack[this.stack.length - 1];
const value = this.resume();
const node = this.stack[this.stack.length - 1];
// Assume a reference.
this.data.inReference = true
this.data.inReference = true;
if (node.type === 'link') {
/** @type {Array<PhrasingContent>} */
const children = fragment.children
node.children = children
const children = fragment.children;
node.children = children;
} else {
node.alt = value
node.alt = value;
}

@@ -1035,5 +982,5 @@ }

function onexitresourcedestinationstring() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.url = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.url = data;
}

@@ -1047,5 +994,5 @@

function onexitresourcetitlestring() {
const data = this.resume()
const node = this.stack[this.stack.length - 1]
node.title = data
const data = this.resume();
const node = this.stack[this.stack.length - 1];
node.title = data;
}

@@ -1059,3 +1006,3 @@

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

@@ -1069,3 +1016,3 @@

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

@@ -1079,12 +1026,10 @@

function onexitreferencestring(token) {
const label = this.resume()
const node = this.stack[this.stack.length - 1]
const label = this.resume();
const node = this.stack[this.stack.length - 1];
// @ts-expect-error: stash this on the node, as it might become a reference
// later.
node.label = label
node.label = label;
// @ts-expect-error: same as above.
node.identifier = normalizeIdentifier(
this.sliceSerialize(token)
).toLowerCase()
this.data.referenceType = 'full'
node.identifier = normalizeIdentifier(this.sliceSerialize(token)).toLowerCase();
this.data.referenceType = 'full';
}

@@ -1098,3 +1043,3 @@

function onexitcharacterreferencemarker(token) {
this.data.characterReferenceType = token.type
this.data.characterReferenceType = token.type;
}

@@ -1107,19 +1052,15 @@

function onexitcharacterreferencevalue(token) {
const data = this.sliceSerialize(token)
const type = this.data.characterReferenceType
const data = this.sliceSerialize(token);
const type = this.data.characterReferenceType;
/** @type {string} */
let value
let value;
if (type) {
value = decodeNumericCharacterReference(
data,
type === 'characterReferenceMarkerNumeric' ? 10 : 16
)
this.data.characterReferenceType = undefined
value = decodeNumericCharacterReference(data, type === "characterReferenceMarkerNumeric" ? 10 : 16);
this.data.characterReferenceType = undefined;
} else {
const result = decodeNamedCharacterReference(data)
value = result
const result = decodeNamedCharacterReference(data);
value = result;
}
const tail = this.stack.pop()
tail.value += value
tail.position.end = point(token.end)
const tail = this.stack[this.stack.length - 1];
tail.value += value;
}

@@ -1131,6 +1072,15 @@

*/
function onexitcharacterreference(token) {
const tail = this.stack.pop();
tail.position.end = point(token.end);
}
/**
* @this {CompileContext}
* @type {Handle}
*/
function onexitautolinkprotocol(token) {
onexitdata.call(this, token)
const node = this.stack[this.stack.length - 1]
node.url = this.sliceSerialize(token)
onexitdata.call(this, token);
const node = this.stack[this.stack.length - 1];
node.url = this.sliceSerialize(token);
}

@@ -1143,5 +1093,5 @@

function onexitautolinkemail(token) {
onexitdata.call(this, token)
const node = this.stack[this.stack.length - 1]
node.url = 'mailto:' + this.sliceSerialize(token)
onexitdata.call(this, token);
const node = this.stack[this.stack.length - 1];
node.url = 'mailto:' + this.sliceSerialize(token);
}

@@ -1158,3 +1108,3 @@

children: []
}
};
}

@@ -1169,3 +1119,3 @@

value: ''
}
};
}

@@ -1178,3 +1128,3 @@

value: ''
}
};
}

@@ -1190,3 +1140,3 @@

url: ''
}
};
}

@@ -1199,3 +1149,3 @@

children: []
}
};
}

@@ -1210,3 +1160,3 @@

children: []
}
};
}

@@ -1218,3 +1168,3 @@

type: 'break'
}
};
}

@@ -1227,3 +1177,3 @@

value: ''
}
};
}

@@ -1238,3 +1188,3 @@

alt: null
}
};
}

@@ -1249,3 +1199,3 @@

children: []
}
};
}

@@ -1264,3 +1214,3 @@

children: []
}
};
}

@@ -1278,3 +1228,3 @@

children: []
}
};
}

@@ -1287,3 +1237,3 @@

children: []
}
};
}

@@ -1296,3 +1246,3 @@

children: []
}
};
}

@@ -1305,3 +1255,3 @@

value: ''
}
};
}

@@ -1313,3 +1263,3 @@

type: 'thematicBreak'
}
};
}

@@ -1331,3 +1281,3 @@ }

offset: d.offset
}
};
}

@@ -1341,9 +1291,9 @@

function configure(combined, extensions) {
let index = -1
let index = -1;
while (++index < extensions.length) {
const value = extensions[index]
const value = extensions[index];
if (Array.isArray(value)) {
configure(combined, value)
configure(combined, value);
} else {
extension(combined, value)
extension(combined, value);
}

@@ -1360,28 +1310,31 @@ }

/** @type {keyof Extension} */
let key
let key;
for (key in extension) {
if (own.call(extension, key)) {
switch (key) {
case 'canContainEols': {
const right = extension[key]
if (right) {
combined[key].push(...right)
case 'canContainEols':
{
const right = extension[key];
if (right) {
combined[key].push(...right);
}
break;
}
break
}
case 'transforms': {
const right = extension[key]
if (right) {
combined[key].push(...right)
case 'transforms':
{
const right = extension[key];
if (right) {
combined[key].push(...right);
}
break;
}
break
}
case 'enter':
case 'exit': {
const right = extension[key]
if (right) {
Object.assign(combined[key], right)
case 'exit':
{
const right = extension[key];
if (right) {
Object.assign(combined[key], right);
}
break;
}
break
}
// No default

@@ -1396,31 +1349,15 @@ }

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'
)
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'
)
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": "2.0.0",
"version": "2.0.1",
"description": "mdast utility to parse markdown",

@@ -57,17 +57,17 @@ "license": "MIT",

"@types/node": "^20.0.0",
"c8": "^8.0.0",
"commonmark.json": "^0.30.0",
"esbuild": "^0.18.0",
"c8": "^9.0.0",
"commonmark.json": "^0.31.0",
"esbuild": "^0.21.0",
"gzip-size-cli": "^5.0.0",
"hast-util-from-html": "^1.0.0",
"hast-util-to-html": "^8.0.0",
"mdast-util-to-hast": "^12.0.0",
"hast-util-from-html": "^2.0.0",
"hast-util-to-html": "^9.0.0",
"mdast-util-to-hast": "^13.0.0",
"micromark-build": "^2.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"prettier": "^3.0.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^10.0.0",
"terser": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.54.0"
"xo": "^0.58.0"
},

@@ -77,3 +77,3 @@ "scripts": {

"build": "tsc --build --clean && tsc --build && type-coverage && micromark-build && esbuild . --bundle --minify | terser | gzip-size --raw",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api-dev": "node --conditions development test/index.js",

@@ -122,5 +122,7 @@ "test-api-prod": "node --conditions production test/index.js",

"complexity": "off",
"max-depth": "off"
"max-depth": "off",
"unicorn/prefer-at": "off",
"unicorn/prefer-string-replace-all": "off"
}
}
}

@@ -15,28 +15,28 @@ # mdast-util-from-markdown

* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`fromMarkdown(value[, encoding][, options])`](#frommarkdownvalue-encoding-options)
* [`CompileContext`](#compilecontext)
* [`CompileData`](#compiledata)
* [`Encoding`](#encoding)
* [`Extension`](#extension)
* [`Handle`](#handle)
* [`OnEnterError`](#onentererror)
* [`OnExitError`](#onexiterror)
* [`Options`](#options)
* [`Token`](#token)
* [`Transform`](#transform)
* [`Value`](#value)
* [List of extensions](#list-of-extensions)
* [Syntax](#syntax)
* [Syntax tree](#syntax-tree)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`fromMarkdown(value[, encoding][, options])`](#frommarkdownvalue-encoding-options)
* [`CompileContext`](#compilecontext)
* [`CompileData`](#compiledata)
* [`Encoding`](#encoding)
* [`Extension`](#extension)
* [`Handle`](#handle)
* [`OnEnterError`](#onentererror)
* [`OnExitError`](#onexiterror)
* [`Options`](#options)
* [`Token`](#token)
* [`Transform`](#transform)
* [`Value`](#value)
* [List of extensions](#list-of-extensions)
* [Syntax](#syntax)
* [Syntax tree](#syntax-tree)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)

@@ -146,14 +146,14 @@ ## What is this?

* `(value: Value, encoding: Encoding, options?: Options) => Root`
* `(value: Value, options?: Options) => Root`
* `(value: Value, encoding: Encoding, options?: Options) => Root`
* `(value: Value, options?: Options) => Root`
###### Parameters
* `value` ([`Value`][api-value])
— markdown to parse
* `encoding` ([`Encoding`][api-encoding], default: `'utf8'`)
— [character encoding][encoding] for when `value` is
[`Uint8Array`][uint8-array]
* `options` ([`Options`][api-options], optional)
— configuration
* `value` ([`Value`][api-value])
— markdown to parse
* `encoding` ([`Encoding`][api-encoding], default: `'utf8'`)
— [character encoding][encoding] for when `value` is
[`Uint8Array`][uint8-array]
* `options` ([`Options`][api-options], optional)
— configuration

@@ -170,20 +170,20 @@ ###### Returns

* `stack` ([`Array<Node>`][node])
— stack of nodes
* `tokenStack` (`Array<[Token, OnEnterError | undefined]>`)
— stack of tokens
* `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) => undefined`)
— enter a node
* `exit` (`(token: Token, onError?: OnExitError) => undefined`)
— exit a node
* `sliceSerialize` (`(token: Token, expandTabs?: boolean) => string`)
— get the string value of a token
* `config` (`Required<Extension>`)
— configuration
* `stack` ([`Array<Node>`][node])
— stack of nodes
* `tokenStack` (`Array<[Token, OnEnterError | undefined]>`)
— stack of tokens
* `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) => undefined`)
— enter a node
* `exit` (`(token: Token, onError?: OnExitError) => undefined`)
— exit a node
* `sliceSerialize` (`(token: Token, expandTabs?: boolean) => string`)
— get the string value of a token
* `config` (`Required<Extension>`)
— configuration

@@ -231,10 +231,10 @@ ### `CompileData`

* `canContainEols` (`Array<string>`, optional)
— token types where line endings are used
* `enter` ([`Record<string, Handle>`][api-handle], optional)
— opening handles
* `exit` ([`Record<string, Handle>`][api-handle], optional)
— closing handles
* `transforms` ([`Array<Transform>`][api-transform], optional)
— tree transforms
* `canContainEols` (`Array<string>`, optional)
— token types where line endings are used
* `enter` ([`Record<string, Handle>`][api-handle], optional)
— opening handles
* `exit` ([`Record<string, Handle>`][api-handle], optional)
— closing handles
* `transforms` ([`Array<Transform>`][api-transform], optional)
— tree transforms

@@ -247,6 +247,6 @@ ### `Handle`

* `this` ([`CompileContext`][api-compile-context])
— context
* `token` ([`Token`][api-token])
— current token
* `this` ([`CompileContext`][api-compile-context])
— context
* `token` ([`Token`][api-token])
— current token

@@ -264,8 +264,8 @@ ###### Returns

* `this` ([`CompileContext`][api-compile-context])
— context
* `left` ([`Token`][api-token] or `undefined`)
— left token
* `right` ([`Token`][api-token])
— right token
* `this` ([`CompileContext`][api-compile-context])
— context
* `left` ([`Token`][api-token] or `undefined`)
— left token
* `right` ([`Token`][api-token])
— right token

@@ -283,8 +283,8 @@ ###### Returns

* `this` ([`CompileContext`][api-compile-context])
— context
* `left` ([`Token`][api-token])
— left token
* `right` ([`Token`][api-token])
— right token
* `this` ([`CompileContext`][api-compile-context])
— context
* `left` ([`Token`][api-token])
— left token
* `right` ([`Token`][api-token])
— right token

@@ -301,7 +301,7 @@ ###### Returns

* `extensions` ([`Array<MicromarkExtension>`][micromark-extension], optional)
— micromark extensions to change how markdown is parsed
* `mdastExtensions` ([`Array<Extension | Array<Extension>>`][api-extension],
optional)
— extensions for this utility to change how tokens are turned into a tree
* `extensions` ([`Array<MicromarkExtension>`][micromark-extension], optional)
— micromark extensions to change how markdown is parsed
* `mdastExtensions` ([`Array<Extension | Array<Extension>>`][api-extension],
optional)
— extensions for this utility to change how tokens are turned into a tree

@@ -324,4 +324,4 @@ ### `Token`

* `tree` ([`Root`][root])
— tree to transform
* `tree` ([`Root`][root])
— tree to transform

@@ -346,28 +346,28 @@ ###### Returns

* [`syntax-tree/mdast-util-directive`](https://github.com/syntax-tree/mdast-util-directive)
— directives
* [`syntax-tree/mdast-util-frontmatter`](https://github.com/syntax-tree/mdast-util-frontmatter)
— frontmatter (YAML, TOML, more)
* [`syntax-tree/mdast-util-gfm`](https://github.com/syntax-tree/mdast-util-gfm)
— GFM
* [`syntax-tree/mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal)
— GFM autolink literals
* [`syntax-tree/mdast-util-gfm-footnote`](https://github.com/syntax-tree/mdast-util-gfm-footnote)
— GFM footnotes
* [`syntax-tree/mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough)
— GFM strikethrough
* [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table)
— GFM tables
* [`syntax-tree/mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item)
— GFM task list items
* [`syntax-tree/mdast-util-math`](https://github.com/syntax-tree/mdast-util-math)
— math
* [`syntax-tree/mdast-util-mdx`](https://github.com/syntax-tree/mdast-util-mdx)
— MDX
* [`syntax-tree/mdast-util-mdx-expression`](https://github.com/syntax-tree/mdast-util-mdx-expression)
— MDX expressions
* [`syntax-tree/mdast-util-mdx-jsx`](https://github.com/syntax-tree/mdast-util-mdx-jsx)
— MDX JSX
* [`syntax-tree/mdast-util-mdxjs-esm`](https://github.com/syntax-tree/mdast-util-mdxjs-esm)
— MDX ESM
* [`syntax-tree/mdast-util-directive`](https://github.com/syntax-tree/mdast-util-directive)
— directives
* [`syntax-tree/mdast-util-frontmatter`](https://github.com/syntax-tree/mdast-util-frontmatter)
— frontmatter (YAML, TOML, more)
* [`syntax-tree/mdast-util-gfm`](https://github.com/syntax-tree/mdast-util-gfm)
— GFM
* [`syntax-tree/mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal)
— GFM autolink literals
* [`syntax-tree/mdast-util-gfm-footnote`](https://github.com/syntax-tree/mdast-util-gfm-footnote)
— GFM footnotes
* [`syntax-tree/mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough)
— GFM strikethrough
* [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table)
— GFM tables
* [`syntax-tree/mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item)
— GFM task list items
* [`syntax-tree/mdast-util-math`](https://github.com/syntax-tree/mdast-util-math)
— math
* [`syntax-tree/mdast-util-mdx`](https://github.com/syntax-tree/mdast-util-mdx)
— MDX
* [`syntax-tree/mdast-util-mdx-expression`](https://github.com/syntax-tree/mdast-util-mdx-expression)
— MDX expressions
* [`syntax-tree/mdast-util-mdx-jsx`](https://github.com/syntax-tree/mdast-util-mdx-jsx)
— MDX JSX
* [`syntax-tree/mdast-util-mdxjs-esm`](https://github.com/syntax-tree/mdast-util-mdxjs-esm)
— MDX ESM

@@ -420,8 +420,8 @@ ## Syntax

* [`syntax-tree/mdast-util-to-markdown`](https://github.com/syntax-tree/mdast-util-to-markdown)
— serialize mdast as markdown
* [`micromark/micromark`](https://github.com/micromark/micromark)
— parse markdown
* [`remarkjs/remark`](https://github.com/remarkjs/remark)
— process markdown
* [`syntax-tree/mdast-util-to-markdown`](https://github.com/syntax-tree/mdast-util-to-markdown)
— serialize mdast as markdown
* [`micromark/micromark`](https://github.com/micromark/micromark)
— parse markdown
* [`remarkjs/remark`](https://github.com/remarkjs/remark)
— process markdown

@@ -428,0 +428,0 @@ ## Contribute

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