mdast-util-to-markdown
Advanced tools
Comparing version 1.5.0 to 2.0.0
@@ -18,3 +18,2 @@ import type {Info, State} from './lib/types.js' | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface ConstructNameMap { | ||
@@ -326,4 +325,1 @@ /** | ||
} from './lib/types.js' | ||
// Deprecated. | ||
export type SafeOptions = Info | ||
export type Context = State |
@@ -0,2 +1,3 @@ | ||
// Note: extra types exposed from `index.d.ts`. | ||
export {toMarkdown} from './lib/index.js' | ||
export {handle as defaultHandlers} from './lib/handle/index.js' |
/** | ||
* @typedef {import('./types.js').Options} Options | ||
* @typedef {import('./types.js').State} State | ||
*/ | ||
/** | ||
* @param {State} base | ||
@@ -7,0 +3,0 @@ * @param {Options} extension |
@@ -6,2 +6,4 @@ /** | ||
const own = {}.hasOwnProperty | ||
/** | ||
@@ -25,13 +27,30 @@ * @param {State} base | ||
for (key in extension) { | ||
if (key === 'extensions') { | ||
// Empty. | ||
} else if (key === 'unsafe' || key === 'join') { | ||
/* c8 ignore next 2 */ | ||
// @ts-expect-error: hush. | ||
base[key] = [...(base[key] || []), ...(extension[key] || [])] | ||
} else if (key === 'handlers') { | ||
base[key] = Object.assign(base[key], extension[key] || {}) | ||
} else { | ||
// @ts-expect-error: hush. | ||
base.options[key] = extension[key] | ||
if (own.call(extension, key)) { | ||
switch (key) { | ||
case 'extensions': { | ||
// Empty. | ||
break | ||
} | ||
/* c8 ignore next 4 */ | ||
case 'unsafe': { | ||
list(base[key], extension[key]) | ||
break | ||
} | ||
case 'join': { | ||
list(base[key], extension[key]) | ||
break | ||
} | ||
case 'handlers': { | ||
map(base[key], extension[key]) | ||
break | ||
} | ||
default: { | ||
// @ts-expect-error: matches. | ||
base.options[key] = extension[key] | ||
} | ||
} | ||
} | ||
@@ -42,1 +61,23 @@ } | ||
} | ||
/** | ||
* @template T | ||
* @param {Array<T>} left | ||
* @param {Array<T> | null | undefined} right | ||
*/ | ||
function list(left, right) { | ||
if (right) { | ||
left.push(...right) | ||
} | ||
} | ||
/** | ||
* @template T | ||
* @param {Record<string, T>} left | ||
* @param {Record<string, T> | null | undefined} right | ||
*/ | ||
function map(left, right) { | ||
if (right) { | ||
Object.assign(left, right) | ||
} | ||
} |
/** | ||
* @typedef {import('mdast').Blockquote} Blockquote | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').Map} Map | ||
* @typedef {import('../types.js').State} State | ||
*/ | ||
/** | ||
* @param {Blockquote} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -17,3 +17,3 @@ * @param {Info} info | ||
node: Blockquote, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -23,5 +23,5 @@ info: Info | ||
export type Blockquote = import('mdast').Blockquote | ||
export type Parent = import('../types.js').Parent | ||
export type State = import('../types.js').State | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type Map = import('../types.js').Map | ||
export type State = import('../types.js').State |
/** | ||
* @typedef {import('mdast').Blockquote} Blockquote | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').Map} Map | ||
* @typedef {import('../types.js').State} State | ||
*/ | ||
@@ -11,3 +11,3 @@ | ||
* @param {Blockquote} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -14,0 +14,0 @@ * @param {Info} info |
/** | ||
* @param {Break} _ | ||
* @param {Parent | undefined} _1 | ||
* @param {Parents | undefined} _1 | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
_: Break, | ||
_1: Parent | undefined, | ||
_1: Parents | undefined, | ||
state: State, | ||
@@ -16,4 +16,4 @@ info: Info | ||
export type Break = import('mdast').Break | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info |
/** | ||
* @typedef {import('mdast').Break} Break | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -12,3 +12,3 @@ | ||
* @param {Break} _ | ||
* @param {Parent | undefined} _1 | ||
* @param {Parents | undefined} _1 | ||
* @param {State} state | ||
@@ -15,0 +15,0 @@ * @param {Info} info |
/** | ||
* @param {Code} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: Code, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -16,5 +16,5 @@ info: Info | ||
export type Code = import('mdast').Code | ||
export type Parent = import('../types.js').Parent | ||
export type State = import('../types.js').State | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type Map = import('../types.js').Map | ||
export type State = import('../types.js').State |
/** | ||
* @typedef {import('mdast').Code} Code | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').Map} Map | ||
* @typedef {import('../types.js').State} State | ||
*/ | ||
@@ -15,3 +15,3 @@ | ||
* @param {Code} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -18,0 +18,0 @@ * @param {Info} info |
/** | ||
* @param {Definition} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: Definition, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -16,4 +16,4 @@ info: Info | ||
export type Definition = import('mdast').Definition | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info |
/** | ||
* @typedef {import('mdast').Definition} Definition | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -12,3 +12,3 @@ | ||
* @param {Definition} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -15,0 +15,0 @@ * @param {Info} info |
/** | ||
* @param {Emphasis} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: Emphasis, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -19,8 +19,8 @@ info: Info | ||
export type Emphasis = import('mdast').Emphasis | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info | ||
/** | ||
* @param {Emphasis} _ | ||
* @param {Parent | undefined} _1 | ||
* @param {Parents | undefined} _1 | ||
* @param {State} state | ||
@@ -31,5 +31,5 @@ * @returns {string} | ||
_: Emphasis, | ||
_1: Parent | undefined, | ||
_1: Parents | undefined, | ||
state: State | ||
): string | ||
export {} |
/** | ||
* @typedef {import('mdast').Emphasis} Emphasis | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -18,3 +18,3 @@ | ||
* @param {Emphasis} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -43,3 +43,3 @@ * @param {Info} info | ||
* @param {Emphasis} _ | ||
* @param {Parent | undefined} _1 | ||
* @param {Parents | undefined} _1 | ||
* @param {State} state | ||
@@ -46,0 +46,0 @@ * @returns {string} |
/** | ||
* @param {Heading} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: Heading, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -16,4 +16,4 @@ info: Info | ||
export type Heading = import('mdast').Heading | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info |
/** | ||
* @typedef {import('mdast').Heading} Heading | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -12,3 +12,3 @@ | ||
* @param {Heading} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -15,0 +15,0 @@ * @param {Info} info |
/** | ||
* @param {HTML} node | ||
* @param {Html} node | ||
* @returns {string} | ||
*/ | ||
export function html(node: HTML): string | ||
export function html(node: Html): string | ||
export namespace html { | ||
export {htmlPeek as peek} | ||
} | ||
export type HTML = import('mdast').HTML | ||
export type Html = import('mdast').Html | ||
/** | ||
@@ -11,0 +11,0 @@ * @returns {string} |
/** | ||
* @typedef {import('mdast').HTML} HTML | ||
* @typedef {import('mdast').Html} Html | ||
*/ | ||
@@ -8,3 +8,3 @@ | ||
/** | ||
* @param {HTML} node | ||
* @param {Html} node | ||
* @returns {string} | ||
@@ -11,0 +11,0 @@ */ |
/** | ||
* @param {ImageReference} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: ImageReference, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -19,5 +19,5 @@ info: Info | ||
export type ImageReference = import('mdast').ImageReference | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info | ||
/** | ||
@@ -24,0 +24,0 @@ * @returns {string} |
/** | ||
* @typedef {import('mdast').ImageReference} ImageReference | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -12,3 +12,3 @@ | ||
* @param {ImageReference} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -15,0 +15,0 @@ * @param {Info} info |
/** | ||
* @param {Image} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: Image, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -19,5 +19,5 @@ info: Info | ||
export type Image = import('mdast').Image | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info | ||
/** | ||
@@ -24,0 +24,0 @@ * @returns {string} |
/** | ||
* @typedef {import('mdast').Image} Image | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -14,3 +14,3 @@ | ||
* @param {Image} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -17,0 +17,0 @@ * @param {Info} info |
/** | ||
* @param {InlineCode} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -9,3 +9,3 @@ * @returns {string} | ||
node: InlineCode, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State | ||
@@ -17,3 +17,3 @@ ): string | ||
export type InlineCode = import('mdast').InlineCode | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type State = import('../types.js').State | ||
@@ -20,0 +20,0 @@ /** |
/** | ||
* @typedef {import('mdast').InlineCode} InlineCode | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').State} State | ||
@@ -13,3 +13,3 @@ */ | ||
* @param {InlineCode} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -16,0 +16,0 @@ * @returns {string} |
/** | ||
* @param {LinkReference} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: LinkReference, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -19,5 +19,5 @@ info: Info | ||
export type LinkReference = import('mdast').LinkReference | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info | ||
/** | ||
@@ -24,0 +24,0 @@ * @returns {string} |
/** | ||
* @typedef {import('mdast').LinkReference} LinkReference | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -12,3 +12,3 @@ | ||
* @param {LinkReference} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -15,0 +15,0 @@ * @param {Info} info |
/** | ||
* @param {Link} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: Link, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -19,9 +19,9 @@ info: Info | ||
export type Link = import('mdast').Link | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Exit = import('../types.js').Exit | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info | ||
export type Exit = import('../types.js').Exit | ||
/** | ||
* @param {Link} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -32,5 +32,5 @@ * @returns {string} | ||
node: Link, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State | ||
): string | ||
export {} |
/** | ||
* @typedef {import('mdast').Link} Link | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Exit} Exit | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').Exit} Exit | ||
*/ | ||
@@ -16,3 +16,3 @@ | ||
* @param {Link} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -111,3 +111,3 @@ * @param {Info} info | ||
* @param {Link} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -114,0 +114,0 @@ * @returns {string} |
/** | ||
* @param {ListItem} node | ||
* @param {Parent | undefined} parent | ||
* @param {Parents | undefined} parent | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: ListItem, | ||
parent: Parent | undefined, | ||
parent: Parents | undefined, | ||
state: State, | ||
@@ -16,5 +16,5 @@ info: Info | ||
export type ListItem = import('mdast').ListItem | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type Map = import('../types.js').Map | ||
export type Parent = import('../types.js').Parent | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info |
/** | ||
* @typedef {import('mdast').ListItem} ListItem | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').Map} Map | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -14,3 +14,3 @@ | ||
* @param {ListItem} node | ||
* @param {Parent | undefined} parent | ||
* @param {Parents | undefined} parent | ||
* @param {State} state | ||
@@ -17,0 +17,0 @@ * @param {Info} info |
/** | ||
* @param {List} node | ||
* @param {Parent | undefined} parent | ||
* @param {Parents | undefined} parent | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: List, | ||
parent: Parent | undefined, | ||
parent: Parents | undefined, | ||
state: State, | ||
@@ -16,4 +16,4 @@ info: Info | ||
export type List = import('mdast').List | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info |
/** | ||
* @typedef {import('mdast').List} List | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -11,3 +11,2 @@ | ||
import {checkBulletOrdered} from '../util/check-bullet-ordered.js' | ||
import {checkBulletOrderedOther} from '../util/check-bullet-ordered-other.js' | ||
import {checkRule} from '../util/check-rule.js' | ||
@@ -17,3 +16,3 @@ | ||
* @param {List} node | ||
* @param {Parent | undefined} parent | ||
* @param {Parents | undefined} parent | ||
* @param {State} state | ||
@@ -30,19 +29,9 @@ * @param {Info} info | ||
const bulletOther = node.ordered | ||
? checkBulletOrderedOther(state) | ||
? bullet === '.' | ||
? ')' | ||
: '.' | ||
: checkBulletOther(state) | ||
const bulletLastUsed = state.bulletLastUsed | ||
let useDifferentMarker = false | ||
let useDifferentMarker = | ||
parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false | ||
if ( | ||
parent && | ||
// Explicit `other` set. | ||
(node.ordered | ||
? state.options.bulletOrderedOther | ||
: state.options.bulletOther) && | ||
bulletLastUsed && | ||
bullet === bulletLastUsed | ||
) { | ||
useDifferentMarker = true | ||
} | ||
if (!node.ordered) { | ||
@@ -49,0 +38,0 @@ const firstListItem = node.children ? node.children[0] : undefined |
/** | ||
* @typedef {import('mdast').Paragraph} Paragraph | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
/** | ||
* @param {Paragraph} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -16,3 +16,3 @@ * @param {Info} info | ||
node: Paragraph, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -22,4 +22,4 @@ info: Info | ||
export type Paragraph = import('mdast').Paragraph | ||
export type Parent = import('../types.js').Parent | ||
export type Parents = import('mdast').Parents | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info |
/** | ||
* @typedef {import('mdast').Paragraph} Paragraph | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -10,3 +10,3 @@ | ||
* @param {Paragraph} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -13,0 +13,0 @@ * @param {Info} info |
/** | ||
* @param {Root} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,9 +10,9 @@ * @param {Info} info | ||
node: Root, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
info: Info | ||
): string | ||
export type Parents = import('mdast').Parents | ||
export type Root = import('mdast').Root | ||
export type Parent = import('../types.js').Parent | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info |
/** | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -12,3 +12,3 @@ | ||
* @param {Root} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -20,6 +20,7 @@ * @param {Info} info | ||
// Note: `html` nodes are ambiguous. | ||
const hasPhrasing = node.children.some((d) => phrasing(d)) | ||
const hasPhrasing = node.children.some(function (d) { | ||
return phrasing(d) | ||
}) | ||
const fn = hasPhrasing ? state.containerPhrasing : state.containerFlow | ||
// @ts-expect-error: `root`s are supposed to have one type of content | ||
return fn.call(state, node, info) | ||
} |
/** | ||
* @param {Strong} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -10,3 +10,3 @@ * @param {Info} info | ||
node: Strong, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
@@ -18,9 +18,9 @@ info: Info | ||
} | ||
export type Parents = import('mdast').Parents | ||
export type Strong = import('mdast').Strong | ||
export type Parent = import('../types.js').Parent | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info | ||
/** | ||
* @param {Strong} _ | ||
* @param {Parent | undefined} _1 | ||
* @param {Parents | undefined} _1 | ||
* @param {State} state | ||
@@ -31,5 +31,5 @@ * @returns {string} | ||
_: Strong, | ||
_1: Parent | undefined, | ||
_1: Parents | undefined, | ||
state: State | ||
): string | ||
export {} |
/** | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('mdast').Strong} Strong | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -18,3 +18,3 @@ | ||
* @param {Strong} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -43,3 +43,3 @@ * @param {Info} info | ||
* @param {Strong} _ | ||
* @param {Parent | undefined} _1 | ||
* @param {Parents | undefined} _1 | ||
* @param {State} state | ||
@@ -46,0 +46,0 @@ * @returns {string} |
/** | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('mdast').Text} Text | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
/** | ||
* @param {Text} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -16,9 +16,9 @@ * @param {Info} info | ||
node: Text, | ||
_: Parent | undefined, | ||
_: Parents | undefined, | ||
state: State, | ||
info: Info | ||
): string | ||
export type Parents = import('mdast').Parents | ||
export type Text = import('mdast').Text | ||
export type Parent = import('../types.js').Parent | ||
export type Info = import('../types.js').Info | ||
export type State = import('../types.js').State | ||
export type Info = import('../types.js').Info |
/** | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('mdast').Text} Text | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Info} Info | ||
*/ | ||
@@ -10,3 +10,3 @@ | ||
* @param {Text} node | ||
* @param {Parent | undefined} _ | ||
* @param {Parents | undefined} _ | ||
* @param {State} state | ||
@@ -13,0 +13,0 @@ * @param {Info} info |
/** | ||
* @param {ThematicBreak} _ | ||
* @param {Parent | undefined} _1 | ||
* @param {Parents | undefined} _1 | ||
* @param {State} state | ||
@@ -9,7 +9,7 @@ * @returns {string} | ||
_: ThematicBreak, | ||
_1: Parent | undefined, | ||
_1: Parents | undefined, | ||
state: State | ||
): string | ||
export type Parents = import('mdast').Parents | ||
export type ThematicBreak = import('mdast').ThematicBreak | ||
export type Parent = import('../types.js').Parent | ||
export type State = import('../types.js').State |
/** | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('mdast').ThematicBreak} ThematicBreak | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').State} State | ||
@@ -12,3 +12,3 @@ */ | ||
* @param {ThematicBreak} _ | ||
* @param {Parent | undefined} _1 | ||
* @param {Parents | undefined} _1 | ||
* @param {State} state | ||
@@ -15,0 +15,0 @@ * @returns {string} |
/** | ||
* Turn an mdast syntax tree into markdown. | ||
* | ||
* @param {Node} tree | ||
* @param {Nodes} tree | ||
* Tree to serialize. | ||
@@ -12,15 +12,14 @@ * @param {Options} [options] | ||
export function toMarkdown( | ||
tree: Node, | ||
tree: Nodes, | ||
options?: import('./types.js').Options | undefined | ||
): string | ||
export type Nodes = import('mdast').Nodes | ||
export type Enter = import('./types.js').Enter | ||
export type Info = import('./types.js').Info | ||
export type Join = import('./types.js').Join | ||
export type FlowContent = import('./types.js').FlowContent | ||
export type Node = import('./types.js').Node | ||
export type FlowParents = import('./types.js').FlowParents | ||
export type Options = import('./types.js').Options | ||
export type Parent = import('./types.js').Parent | ||
export type PhrasingContent = import('./types.js').PhrasingContent | ||
export type PhrasingParents = import('./types.js').PhrasingParents | ||
export type SafeConfig = import('./types.js').SafeConfig | ||
export type State = import('./types.js').State | ||
export type TrackFields = import('./types.js').TrackFields |
/** | ||
* @typedef {import('mdast').Nodes} Nodes | ||
* @typedef {import('./types.js').Enter} Enter | ||
* @typedef {import('./types.js').Info} Info | ||
* @typedef {import('./types.js').Join} Join | ||
* @typedef {import('./types.js').FlowContent} FlowContent | ||
* @typedef {import('./types.js').Node} Node | ||
* @typedef {import('./types.js').FlowParents} FlowParents | ||
* @typedef {import('./types.js').Options} Options | ||
* @typedef {import('./types.js').Parent} Parent | ||
* @typedef {import('./types.js').PhrasingContent} PhrasingContent | ||
* @typedef {import('./types.js').PhrasingParents} PhrasingParents | ||
* @typedef {import('./types.js').SafeConfig} SafeConfig | ||
@@ -30,3 +29,3 @@ * @typedef {import('./types.js').State} State | ||
* | ||
* @param {Node} tree | ||
* @param {Nodes} tree | ||
* Tree to serialize. | ||
@@ -49,17 +48,17 @@ * @param {Options} [options] | ||
stack: [], | ||
unsafe: [], | ||
join: [], | ||
// @ts-expect-error: we’ll fill it next. | ||
handlers: {}, | ||
unsafe: [...unsafe], | ||
join: [...join], | ||
// @ts-expect-error: GFM / frontmatter are typed in `mdast` but not defined | ||
// here. | ||
handlers: {...handlers}, | ||
options: {}, | ||
indexStack: [], | ||
// @ts-expect-error: we’ll add `handle` later. | ||
// @ts-expect-error: add `handle` in a second. | ||
handle: undefined | ||
} | ||
configure(state, {unsafe, join, handlers}) | ||
configure(state, options) | ||
if (state.options.tightDefinitions) { | ||
configure(state, {join: [joinDefinition]}) | ||
state.join.push(joinDefinition) | ||
} | ||
@@ -95,2 +94,5 @@ | ||
/** | ||
* @returns {undefined} | ||
*/ | ||
function exit() { | ||
@@ -111,7 +113,8 @@ state.stack.pop() | ||
/** | ||
* @param {unknown} node | ||
* @param {unknown} value | ||
* @returns {never} | ||
*/ | ||
function unknown(node) { | ||
// @ts-expect-error: fine. | ||
function unknown(value) { | ||
// Always a node. | ||
const node = /** @type {Nodes} */ (value) | ||
throw new Error('Cannot handle unknown node `' + node.type + '`') | ||
@@ -135,3 +138,3 @@ } | ||
* Info passed around about the current state. | ||
* @param {Parent & {children: Array<PhrasingContent>}} parent | ||
* @param {PhrasingParents} parent | ||
* Parent of flow nodes. | ||
@@ -155,3 +158,3 @@ * @param {Info} info | ||
* Info passed around about the current state. | ||
* @param {Parent & {children: Array<FlowContent>}} parent | ||
* @param {FlowParents} parent | ||
* Parent of flow nodes. | ||
@@ -158,0 +161,0 @@ * @param {TrackFields} info |
@@ -23,14 +23,2 @@ /** | ||
// Two lists with the same marker. | ||
if ( | ||
left.type === 'list' && | ||
left.type === right.type && | ||
Boolean(left.ordered) === Boolean(right.ordered) && | ||
!(left.ordered | ||
? state.options.bulletOrderedOther | ||
: state.options.bulletOther) | ||
) { | ||
return false | ||
} | ||
// Join children of a list or an item. | ||
@@ -37,0 +25,0 @@ // In which case, `parent` has a `spread` field. |
@@ -1,13 +0,55 @@ | ||
export type UnistParent = import('unist').Parent | ||
export type Point = import('unist').Point | ||
export type Association = import('mdast').Association | ||
export type Content = import('mdast').Content | ||
export type ListContent = import('mdast').ListContent | ||
export type Nodes = import('mdast').Nodes | ||
export type Parents = import('mdast').Parents | ||
export type PhrasingContent = import('mdast').PhrasingContent | ||
export type Root = import('mdast').Root | ||
export type TopLevelContent = import('mdast').TopLevelContent | ||
export type TableCell = import('mdast').TableCell | ||
export type TableRow = import('mdast').TableRow | ||
export type ConstructName = import('../index.js').ConstructName | ||
export type Node = Root | Content | ||
export type Parent = Extract<Node, UnistParent> | ||
export type FlowContent = TopLevelContent | ListContent | ||
export type FlowParents = Exclude< | ||
Parents, | ||
PhrasingContent | TableCell | TableRow | ||
> | ||
export type FlowChildren = | ||
| import('mdast').Blockquote | ||
| import('mdast').Code | ||
| import('mdast').Heading | ||
| import('mdast').Html | ||
| import('mdast').List | ||
| import('mdast').Paragraph | ||
| import('mdast').Table | ||
| import('mdast').ThematicBreak | ||
| import('mdast').Definition | ||
| import('mdast').FootnoteDefinition | ||
| import('mdast').Yaml | ||
| import('mdast').ListItem | ||
| import('mdast').Break | ||
| import('mdast').Delete | ||
| import('mdast').Emphasis | ||
| import('mdast').FootnoteReference | ||
| import('mdast').Image | ||
| import('mdast').ImageReference | ||
| import('mdast').InlineCode | ||
| import('mdast').Link | ||
| import('mdast').LinkReference | ||
| import('mdast').Strong | ||
| import('mdast').Text | ||
| import('mdast').TableCell | ||
| import('mdast').TableRow | ||
export type PhrasingParents = | ||
| import('mdast').Blockquote | ||
| import('mdast').Heading | ||
| import('mdast').List | ||
| import('mdast').Paragraph | ||
| import('mdast').Table | ||
| import('mdast').FootnoteDefinition | ||
| import('mdast').ListItem | ||
| import('mdast').Delete | ||
| import('mdast').Emphasis | ||
| import('mdast').Link | ||
| import('mdast').LinkReference | ||
| import('mdast').Strong | ||
| import('mdast').TableCell | ||
| import('mdast').TableRow | ||
| import('mdast').Root | ||
/** | ||
@@ -18,7 +60,7 @@ * Info on where we are in the document we are generating. | ||
/** | ||
* Current point. | ||
* Current point. | ||
*/ | ||
now: Point | ||
/** | ||
* Number of columns each line will be shifted by wrapping nodes. | ||
* Number of columns each line will be shifted by wrapping nodes. | ||
*/ | ||
@@ -33,7 +75,7 @@ lineShift: number | ||
/** | ||
* Characters before this (guaranteed to be one, can be more). | ||
* Characters before this (guaranteed to be one, can be more). | ||
*/ | ||
before: string | ||
/** | ||
* Characters after this (guaranteed to be one, can be more). | ||
* Characters after this (guaranteed to be one, can be more). | ||
*/ | ||
@@ -53,3 +95,3 @@ after: string | ||
*/ | ||
export type TrackShift = (value: number) => void | ||
export type TrackShift = (value: number) => undefined | ||
/** | ||
@@ -67,11 +109,11 @@ * Move past some generated markdown. | ||
/** | ||
* Get the current tracked info. | ||
* Get the current tracked info. | ||
*/ | ||
current: TrackCurrent | ||
/** | ||
* Define an increased line shift (the typical indent for lines). | ||
* Define an increased line shift (the typical indent for lines). | ||
*/ | ||
shift: TrackShift | ||
/** | ||
* Move past some generated markdown. | ||
* Move past some generated markdown. | ||
*/ | ||
@@ -119,8 +161,3 @@ move: TrackMove | ||
*/ | ||
export type ContainerPhrasing = ( | ||
parent: Parent & { | ||
children: Array<PhrasingContent> | ||
}, | ||
info: Info | ||
) => string | ||
export type ContainerPhrasing = (parent: PhrasingParents, info: Info) => string | ||
/** | ||
@@ -132,8 +169,3 @@ * Serialize the children of a parent that contains flow children. | ||
*/ | ||
export type ContainerFlow = ( | ||
parent: Parent & { | ||
children: Array<FlowContent> | ||
}, | ||
info: TrackFields | ||
) => string | ||
export type ContainerFlow = (parent: FlowParents, info: TrackFields) => string | ||
/** | ||
@@ -145,3 +177,3 @@ * Extra configuration for `safe` | ||
* Extra characters that *must* be encoded (as character references) instead | ||
* of escaped (character escapes). | ||
* of escaped (character escapes) (optional). | ||
* | ||
@@ -181,3 +213,3 @@ * Only ASCII punctuation will use character escapes, so you never need to | ||
*/ | ||
export type Exit = () => void | ||
export type Exit = () => undefined | ||
/** | ||
@@ -188,63 +220,63 @@ * Info passed around about the current state. | ||
/** | ||
* Stack of constructs we’re in. | ||
* Stack of constructs we’re in. | ||
*/ | ||
stack: Array<ConstructName> | ||
/** | ||
* Positions of child nodes in their parents. | ||
* Positions of child nodes in their parents. | ||
*/ | ||
indexStack: Array<number> | ||
/** | ||
* Pad serialized markdown. | ||
* Pad serialized markdown. | ||
*/ | ||
indentLines: IndentLines | ||
/** | ||
* Get an identifier from an association to match it to others. | ||
* Get an identifier from an association to match it to others. | ||
*/ | ||
associationId: AssociationId | ||
/** | ||
* Serialize the children of a parent that contains phrasing children. | ||
* Serialize the children of a parent that contains phrasing children. | ||
*/ | ||
containerPhrasing: ContainerPhrasing | ||
/** | ||
* Serialize the children of a parent that contains flow children. | ||
* Serialize the children of a parent that contains flow children. | ||
*/ | ||
containerFlow: ContainerFlow | ||
/** | ||
* Track positional info in the output. | ||
* Track positional info in the output. | ||
*/ | ||
createTracker: CreateTracker | ||
/** | ||
* Serialize the children of a parent that contains flow children. | ||
* Serialize the children of a parent that contains flow children. | ||
*/ | ||
safe: Safe | ||
/** | ||
* Enter a construct (returns a corresponding exit function). | ||
* Enter a construct (returns a corresponding exit function). | ||
*/ | ||
enter: Enter | ||
/** | ||
* Applied user configuration. | ||
* Applied user configuration. | ||
*/ | ||
options: Options | ||
/** | ||
* Applied unsafe patterns. | ||
* Applied unsafe patterns. | ||
*/ | ||
unsafe: Array<Unsafe> | ||
/** | ||
* Applied join handlers. | ||
* Applied join handlers. | ||
*/ | ||
join: Array<Join> | ||
/** | ||
* Call the configured handler for the given node. | ||
* Call the configured handler for the given node. | ||
*/ | ||
handle: Handle | ||
/** | ||
* Applied handlers. | ||
* Applied handlers. | ||
*/ | ||
handlers: Handlers | ||
/** | ||
* List marker currently in use. | ||
* List marker currently in use. | ||
*/ | ||
bulletCurrent: string | undefined | ||
/** | ||
* List marker previously in use. | ||
* List marker previously in use. | ||
*/ | ||
@@ -258,3 +290,3 @@ bulletLastUsed: string | undefined | ||
node: any, | ||
parent: Parent | undefined, | ||
parent: Parents | undefined, | ||
state: State, | ||
@@ -268,3 +300,3 @@ Info: Info | ||
*/ | ||
export type Handlers = Record<Node['type'], Handle> | ||
export type Handlers = Record<Nodes['type'], Handle> | ||
/** | ||
@@ -281,7 +313,7 @@ * How to join two blocks. | ||
export type Join = ( | ||
left: Node, | ||
right: Node, | ||
parent: Parent, | ||
left: FlowChildren, | ||
right: FlowChildren, | ||
parent: FlowParents, | ||
state: State | ||
) => boolean | null | undefined | void | number | ||
) => boolean | number | null | undefined | void | ||
/** | ||
@@ -292,28 +324,28 @@ * Schema that defines when a character cannot occur. | ||
/** | ||
* Single unsafe character. | ||
* Single unsafe character. | ||
*/ | ||
character: string | ||
/** | ||
* Constructs where this is bad. | ||
* Constructs where this is bad (optional). | ||
*/ | ||
inConstruct?: ConstructName | Array<ConstructName> | null | undefined | ||
inConstruct?: Array<ConstructName> | ConstructName | null | undefined | ||
/** | ||
* Constructs where this is fine again. | ||
* Constructs where this is fine again (optional). | ||
*/ | ||
notInConstruct?: ConstructName | Array<ConstructName> | null | undefined | ||
notInConstruct?: Array<ConstructName> | ConstructName | null | undefined | ||
/** | ||
* `character` is bad when this is before it (cannot be used together with | ||
* `atBreak`). | ||
* `atBreak`) (optional). | ||
*/ | ||
before?: string | null | undefined | ||
/** | ||
* `character` is bad when this is after it. | ||
* `character` is bad when this is after it (optional). | ||
*/ | ||
after?: string | null | undefined | ||
/** | ||
* `character` is bad at a break (cannot be used together with `before`). | ||
* `character` is bad at a break (cannot be used together with `before`) (optional). | ||
*/ | ||
atBreak?: boolean | null | undefined | ||
/** | ||
* The unsafe pattern (this whole object) compiled as a regex. | ||
* The unsafe pattern (this whole object) compiled as a regex (do not use). | ||
* | ||
@@ -329,63 +361,52 @@ * This is internal and must not be defined. | ||
/** | ||
* Marker to use for bullets of items in unordered lists. | ||
*/ | ||
bullet?: '-' | '*' | '+' | null | undefined | ||
/** | ||
* Marker to use in certain cases where the primary bullet doesn’t work. | ||
* Marker to use for bullets of items in unordered lists (default: `'*'`). | ||
* | ||
* There are three cases where the primary bullet cannot be used: | ||
* | ||
* * When three list items are on their own, the last one is empty, and | ||
* `bullet` is also a valid `rule`: `* - +`. | ||
* This would turn into a thematic break if serialized with three primary | ||
* bullets. | ||
* As this is an edge case unlikely to appear in normal markdown, the | ||
* last list item will be given a different bullet. | ||
* * When a thematic break is the first child of one of the list items, and | ||
* `bullet` is the same character as `rule`: `- ***`. | ||
* This would turn into a single thematic break if serialized with | ||
* primary bullets. | ||
* As this is an edge case unlikely to appear in normal markdown this | ||
* markup is always fixed, even if `bulletOther` is not passed | ||
* * When two unordered lists appear next to each other: `* a\n- b`. | ||
* CommonMark sees different bullets as different lists, but several | ||
* markdown parsers parse it as one list. | ||
* To solve for both, we instead inject an empty comment between the two | ||
* lists: `* a\n<!---->\n* b`, but if `bulletOther` is given explicitly, | ||
* it will be used instead | ||
* * when three or more list items are on their own, the last one is empty, | ||
* and `bullet` is also a valid `rule`: `* - +`; this would turn into a | ||
* thematic break if serialized with three primary bullets; `bulletOther` | ||
* is used for the last item | ||
* * when a thematic break is the first child of a list item and `bullet` is | ||
* the same character as `rule`: `- ***`; this would turn into a single | ||
* thematic break if serialized with primary bullets; `bulletOther` is used | ||
* for the item | ||
* * when two unordered lists appear next to each other: `* a\n- b`; | ||
* `bulletOther` is used for such lists | ||
*/ | ||
bulletOther?: '-' | '*' | '+' | null | undefined | ||
bullet?: '*' | '+' | '-' | null | undefined | ||
/** | ||
* Marker to use for bullets of items in ordered lists. | ||
* Marker to use in certain cases where the primary bullet doesn’t work | ||
* (default: `'-'` when `bullet` is `'*'`, `'*'` otherwise). | ||
* | ||
* Cannot be equal to `bullet`. | ||
*/ | ||
bulletOrdered?: '.' | ')' | null | undefined | ||
bulletOther?: '*' | '+' | '-' | null | undefined | ||
/** | ||
* Marker to use in certain cases where the primary bullet for ordered items | ||
* doesn’t work. | ||
* Marker to use for bullets of items in ordered lists (default: `'.'`). | ||
* | ||
* There is one case where the primary bullet for ordered items cannot be used: | ||
* There is one case where the primary bullet for ordered items cannot be | ||
* used: | ||
* | ||
* * When two ordered lists appear next to each other: `1. a\n2) b`. | ||
* CommonMark added support for `)` as a marker, but other markdown | ||
* parsers do not support it. | ||
* To solve for both, we instead inject an empty comment between the two | ||
* lists: `1. a\n<!---->\n1. b`, but if `bulletOrderedOther` is given | ||
* explicitly, it will be used instead | ||
* * when two ordered lists appear next to each other: `1. a\n2) b`; to | ||
* solve | ||
* that, `'.'` will be used when `bulletOrdered` is `')'`, and `'.'` | ||
* otherwise | ||
*/ | ||
bulletOrderedOther?: '.' | ')' | null | undefined | ||
bulletOrdered?: '.' | ')' | null | undefined | ||
/** | ||
* Whether to add the same number of number signs (`#`) at the end of an ATX | ||
* heading as the opening sequence. | ||
* heading as the opening sequence (default: `false`). | ||
*/ | ||
closeAtx?: boolean | null | undefined | ||
/** | ||
* Marker to use for emphasis. | ||
* Marker to use for emphasis (default: `'*'`). | ||
*/ | ||
emphasis?: '_' | '*' | null | undefined | ||
emphasis?: '*' | '_' | null | undefined | ||
/** | ||
* Marker to use for fenced code. | ||
* Marker to use for fenced code (default: ``'`'``). | ||
*/ | ||
fence?: '~' | '`' | null | undefined | ||
fence?: '`' | '~' | null | undefined | ||
/** | ||
* Whether to use fenced code always. | ||
* Whether to use fenced code always (default: `true`). | ||
* | ||
@@ -397,7 +418,7 @@ * The default is to use fenced code if there is a language defined, if the | ||
/** | ||
* Whether to increment the counter of ordered lists items. | ||
* Whether to increment the counter of ordered lists items (default: `true`). | ||
*/ | ||
incrementListMarker?: boolean | null | undefined | ||
/** | ||
* How to indent the content of list items. | ||
* How to indent the content of list items (default: `'one'`). | ||
* | ||
@@ -408,9 +429,9 @@ * Either with the size of the bullet plus one space (when `'one'`), a tab | ||
*/ | ||
listItemIndent?: 'tab' | 'one' | 'mixed' | null | undefined | ||
listItemIndent?: 'mixed' | 'one' | 'tab' | null | undefined | ||
/** | ||
* Marker to use for titles. | ||
* Marker to use for titles (default: `'"'`). | ||
*/ | ||
quote?: '"' | "'" | null | undefined | ||
/** | ||
* Whether to always use resource links. | ||
* Whether to always use resource links (default: `false`). | ||
* | ||
@@ -422,15 +443,16 @@ * The default is to use autolinks (`<https://example.com>`) when possible | ||
/** | ||
* Marker to use for thematic breaks. | ||
* Marker to use for thematic breaks (default: `'*'`). | ||
*/ | ||
rule?: '-' | '_' | '*' | null | undefined | ||
rule?: '*' | '-' | '_' | null | undefined | ||
/** | ||
* Number of markers to use for thematic breaks. | ||
* Number of markers to use for thematic breaks (default: `3`). | ||
*/ | ||
ruleRepetition?: number | null | undefined | ||
/** | ||
* Whether to add spaces between markers in thematic breaks. | ||
* Whether to add spaces between markers in thematic breaks (default: | ||
* `false`). | ||
*/ | ||
ruleSpaces?: boolean | null | undefined | ||
/** | ||
* Whether to use setext headings when possible. | ||
* Whether to use setext headings when possible (default: `false`). | ||
* | ||
@@ -444,7 +466,7 @@ * The default is to always use ATX headings (`# heading`) instead of setext | ||
/** | ||
* Marker to use for strong. | ||
* Marker to use for strong (default: `'*'`). | ||
*/ | ||
strong?: '_' | '*' | null | undefined | ||
strong?: '*' | '_' | null | undefined | ||
/** | ||
* Whether to join definitions without a blank line. | ||
* Whether to join definitions without a blank line (default: `false`). | ||
* | ||
@@ -464,3 +486,3 @@ * The default is to add blank lines between any flow (“block”) construct. | ||
/** | ||
* Handle particular nodes. | ||
* Handle particular nodes (optional). | ||
* | ||
@@ -471,11 +493,11 @@ * Each key is a node type, each value its corresponding handler. | ||
/** | ||
* How to join blocks. | ||
* How to join blocks (optional). | ||
*/ | ||
join?: Array<Join> | null | undefined | ||
/** | ||
* Schemas that define when characters cannot occur. | ||
* Schemas that define when characters cannot occur (optional). | ||
*/ | ||
unsafe?: Array<Unsafe> | null | undefined | ||
/** | ||
* List of extensions to include. | ||
* List of extensions to include (optional). | ||
* | ||
@@ -482,0 +504,0 @@ * Each `ToMarkdownExtension` is an object with the same interface as |
163
lib/types.js
/** | ||
* @typedef {import('unist').Parent} UnistParent | ||
* @typedef {import('unist').Point} Point | ||
* @typedef {import('mdast').Association} Association | ||
* @typedef {import('mdast').Content} Content | ||
* @typedef {import('mdast').ListContent} ListContent | ||
* @typedef {import('mdast').Nodes} Nodes | ||
* @typedef {import('mdast').Parents} Parents | ||
* @typedef {import('mdast').PhrasingContent} PhrasingContent | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('mdast').TopLevelContent} TopLevelContent | ||
* @typedef {import('mdast').TableCell} TableCell | ||
* @typedef {import('mdast').TableRow} TableRow | ||
* @typedef {import('../index.js').ConstructName} ConstructName | ||
@@ -14,6 +13,8 @@ */ | ||
/** | ||
* @typedef {Root | Content} Node | ||
* @typedef {Extract<Node, UnistParent>} Parent | ||
* @typedef {TopLevelContent | ListContent} FlowContent | ||
* | ||
* @typedef {Exclude<Parents, PhrasingContent | TableCell | TableRow>} FlowParents | ||
* @typedef {FlowParents extends {children: Array<infer T>} ? T : never} FlowChildren | ||
* @typedef {Parents extends {children: Array<infer T>} ? PhrasingContent extends T ? Parents : never : never} PhrasingParents | ||
*/ | ||
/** | ||
* @typedef TrackFields | ||
@@ -46,3 +47,3 @@ * Info on where we are in the document we are generating. | ||
* Relative increment in how much each line will be padded. | ||
* @returns {void} | ||
* @returns {undefined} | ||
* Nothing. | ||
@@ -125,3 +126,3 @@ * | ||
* These children will be joined flush together. | ||
* @param {Parent & {children: Array<PhrasingContent>}} parent | ||
* @param {PhrasingParents} parent | ||
* Parent of flow nodes. | ||
@@ -138,3 +139,3 @@ * @param {Info} info | ||
* What they are joined by exactly is defined by `Join` functions. | ||
* @param {Parent & {children: Array<FlowContent>}} parent | ||
* @param {FlowParents} parent | ||
* Parent of flow nodes. | ||
@@ -150,3 +151,3 @@ * @param {TrackFields} info | ||
* Extra characters that *must* be encoded (as character references) instead | ||
* of escaped (character escapes). | ||
* of escaped (character escapes) (optional). | ||
* | ||
@@ -189,3 +190,3 @@ * Only ASCII punctuation will use character escapes, so you never need to | ||
* Exit something. | ||
* @returns {void} | ||
* @returns {undefined} | ||
* Nothing. | ||
@@ -232,3 +233,3 @@ * | ||
* Expected mdast node. | ||
* @param {Parent | undefined} parent | ||
* @param {Parents | undefined} parent | ||
* Parent of `node`. | ||
@@ -242,3 +243,3 @@ * @param {State} state | ||
* | ||
* @typedef {Record<Node['type'], Handle>} Handlers | ||
* @typedef {Record<Nodes['type'], Handle>} Handlers | ||
* Handle particular nodes. | ||
@@ -257,11 +258,11 @@ * | ||
* they return defines how many blank lines to use between them. | ||
* @param {Node} left | ||
* @param {FlowChildren} left | ||
* First of two adjacent siblings. | ||
* @param {Node} right | ||
* @param {FlowChildren} right | ||
* Second of two adjacent siblings. | ||
* @param {Parent} parent | ||
* @param {FlowParents} parent | ||
* Parent of the two siblings. | ||
* @param {State} state | ||
* Info passed around about the current state. | ||
* @returns {boolean | null | undefined | void | number} | ||
* @returns {boolean | number | null | undefined | void} | ||
* How many blank lines to use between the siblings. | ||
@@ -290,15 +291,15 @@ * | ||
* Single unsafe character. | ||
* @property {ConstructName | Array<ConstructName> | null | undefined} [inConstruct] | ||
* Constructs where this is bad. | ||
* @property {ConstructName | Array<ConstructName> | null | undefined} [notInConstruct] | ||
* Constructs where this is fine again. | ||
* @property {Array<ConstructName> | ConstructName | null | undefined} [inConstruct] | ||
* Constructs where this is bad (optional). | ||
* @property {Array<ConstructName> | ConstructName | null | undefined} [notInConstruct] | ||
* Constructs where this is fine again (optional). | ||
* @property {string | null | undefined} [before] | ||
* `character` is bad when this is before it (cannot be used together with | ||
* `atBreak`). | ||
* `atBreak`) (optional). | ||
* @property {string | null | undefined} [after] | ||
* `character` is bad when this is after it. | ||
* `character` is bad when this is after it (optional). | ||
* @property {boolean | null | undefined} [atBreak] | ||
* `character` is bad at a break (cannot be used together with `before`). | ||
* `character` is bad at a break (cannot be used together with `before`) (optional). | ||
* @property {RegExp | null | undefined} [_compiled] | ||
* The unsafe pattern (this whole object) compiled as a regex. | ||
* The unsafe pattern (this whole object) compiled as a regex (do not use). | ||
* | ||
@@ -309,50 +310,41 @@ * This is internal and must not be defined. | ||
* Configuration (optional). | ||
* @property {'-' | '*' | '+' | null | undefined} [bullet='*'] | ||
* Marker to use for bullets of items in unordered lists. | ||
* @property {'-' | '*' | '+' | null | undefined} [bulletOther] | ||
* Marker to use in certain cases where the primary bullet doesn’t work. | ||
* @property {'*' | '+' | '-' | null | undefined} [bullet='*'] | ||
* Marker to use for bullets of items in unordered lists (default: `'*'`). | ||
* | ||
* There are three cases where the primary bullet cannot be used: | ||
* | ||
* * When three list items are on their own, the last one is empty, and | ||
* `bullet` is also a valid `rule`: `* - +`. | ||
* This would turn into a thematic break if serialized with three primary | ||
* bullets. | ||
* As this is an edge case unlikely to appear in normal markdown, the | ||
* last list item will be given a different bullet. | ||
* * When a thematic break is the first child of one of the list items, and | ||
* `bullet` is the same character as `rule`: `- ***`. | ||
* This would turn into a single thematic break if serialized with | ||
* primary bullets. | ||
* As this is an edge case unlikely to appear in normal markdown this | ||
* markup is always fixed, even if `bulletOther` is not passed | ||
* * When two unordered lists appear next to each other: `* a\n- b`. | ||
* CommonMark sees different bullets as different lists, but several | ||
* markdown parsers parse it as one list. | ||
* To solve for both, we instead inject an empty comment between the two | ||
* lists: `* a\n<!---->\n* b`, but if `bulletOther` is given explicitly, | ||
* it will be used instead | ||
* * when three or more list items are on their own, the last one is empty, | ||
* and `bullet` is also a valid `rule`: `* - +`; this would turn into a | ||
* thematic break if serialized with three primary bullets; `bulletOther` | ||
* is used for the last item | ||
* * when a thematic break is the first child of a list item and `bullet` is | ||
* the same character as `rule`: `- ***`; this would turn into a single | ||
* thematic break if serialized with primary bullets; `bulletOther` is used | ||
* for the item | ||
* * when two unordered lists appear next to each other: `* a\n- b`; | ||
* `bulletOther` is used for such lists | ||
* @property {'*' | '+' | '-' | null | undefined} [bulletOther] | ||
* Marker to use in certain cases where the primary bullet doesn’t work | ||
* (default: `'-'` when `bullet` is `'*'`, `'*'` otherwise). | ||
* | ||
* Cannot be equal to `bullet`. | ||
* @property {'.' | ')' | null | undefined} [bulletOrdered='.'] | ||
* Marker to use for bullets of items in ordered lists. | ||
* @property {'.' | ')' | null | undefined} [bulletOrderedOther] | ||
* Marker to use in certain cases where the primary bullet for ordered items | ||
* doesn’t work. | ||
* Marker to use for bullets of items in ordered lists (default: `'.'`). | ||
* | ||
* There is one case where the primary bullet for ordered items cannot be used: | ||
* There is one case where the primary bullet for ordered items cannot be | ||
* used: | ||
* | ||
* * When two ordered lists appear next to each other: `1. a\n2) b`. | ||
* CommonMark added support for `)` as a marker, but other markdown | ||
* parsers do not support it. | ||
* To solve for both, we instead inject an empty comment between the two | ||
* lists: `1. a\n<!---->\n1. b`, but if `bulletOrderedOther` is given | ||
* explicitly, it will be used instead | ||
* * when two ordered lists appear next to each other: `1. a\n2) b`; to | ||
* solve | ||
* that, `'.'` will be used when `bulletOrdered` is `')'`, and `'.'` | ||
* otherwise | ||
* @property {boolean | null | undefined} [closeAtx=false] | ||
* Whether to add the same number of number signs (`#`) at the end of an ATX | ||
* heading as the opening sequence. | ||
* @property {'_' | '*' | null | undefined} [emphasis='*'] | ||
* Marker to use for emphasis. | ||
* @property {'~' | '`' | null | undefined} [fence='`'] | ||
* Marker to use for fenced code. | ||
* @property {boolean | null | undefined} [fences=false] | ||
* Whether to use fenced code always. | ||
* heading as the opening sequence (default: `false`). | ||
* @property {'*' | '_' | null | undefined} [emphasis='*'] | ||
* Marker to use for emphasis (default: `'*'`). | ||
* @property {'`' | '~' | null | undefined} [fence='`'] | ||
* Marker to use for fenced code (default: ``'`'``). | ||
* @property {boolean | null | undefined} [fences=true] | ||
* Whether to use fenced code always (default: `true`). | ||
* | ||
@@ -362,5 +354,5 @@ * The default is to use fenced code if there is a language defined, if the | ||
* @property {boolean | null | undefined} [incrementListMarker=true] | ||
* Whether to increment the counter of ordered lists items. | ||
* @property {'tab' | 'one' | 'mixed' | null | undefined} [listItemIndent='tab'] | ||
* How to indent the content of list items. | ||
* Whether to increment the counter of ordered lists items (default: `true`). | ||
* @property {'mixed' | 'one' | 'tab' | null | undefined} [listItemIndent='one'] | ||
* How to indent the content of list items (default: `'one'`). | ||
* | ||
@@ -371,16 +363,17 @@ * Either with the size of the bullet plus one space (when `'one'`), a tab | ||
* @property {'"' | "'" | null | undefined} [quote='"'] | ||
* Marker to use for titles. | ||
* Marker to use for titles (default: `'"'`). | ||
* @property {boolean | null | undefined} [resourceLink=false] | ||
* Whether to always use resource links. | ||
* Whether to always use resource links (default: `false`). | ||
* | ||
* The default is to use autolinks (`<https://example.com>`) when possible | ||
* and resource links (`[text](url)`) otherwise. | ||
* @property {'-' | '_' | '*' | null | undefined} [rule='*'] | ||
* Marker to use for thematic breaks. | ||
* @property {'*' | '-' | '_' | null | undefined} [rule='*'] | ||
* Marker to use for thematic breaks (default: `'*'`). | ||
* @property {number | null | undefined} [ruleRepetition=3] | ||
* Number of markers to use for thematic breaks. | ||
* Number of markers to use for thematic breaks (default: `3`). | ||
* @property {boolean | null | undefined} [ruleSpaces=false] | ||
* Whether to add spaces between markers in thematic breaks. | ||
* Whether to add spaces between markers in thematic breaks (default: | ||
* `false`). | ||
* @property {boolean | null | undefined} [setext=false] | ||
* Whether to use setext headings when possible. | ||
* Whether to use setext headings when possible (default: `false`). | ||
* | ||
@@ -391,6 +384,6 @@ * The default is to always use ATX headings (`# heading`) instead of setext | ||
* of three or more. | ||
* @property {'_' | '*' | null | undefined} [strong='*'] | ||
* Marker to use for strong. | ||
* @property {'*' | '_' | null | undefined} [strong='*'] | ||
* Marker to use for strong (default: `'*'`). | ||
* @property {boolean | null | undefined} [tightDefinitions=false] | ||
* Whether to join definitions without a blank line. | ||
* Whether to join definitions without a blank line (default: `false`). | ||
* | ||
@@ -408,11 +401,11 @@ * The default is to add blank lines between any flow (“block”) construct. | ||
* @property {Partial<Handlers> | null | undefined} [handlers={}] | ||
* Handle particular nodes. | ||
* Handle particular nodes (optional). | ||
* | ||
* Each key is a node type, each value its corresponding handler. | ||
* @property {Array<Join> | null | undefined} [join=[]] | ||
* How to join blocks. | ||
* How to join blocks (optional). | ||
* @property {Array<Unsafe> | null | undefined} [unsafe=[]] | ||
* Schemas that define when characters cannot occur. | ||
* Schemas that define when characters cannot occur (optional). | ||
* @property {Array<Options> | null | undefined} [extensions=[]] | ||
* List of extensions to include. | ||
* List of extensions to include (optional). | ||
* | ||
@@ -419,0 +412,0 @@ * Each `ToMarkdownExtension` is an object with the same interface as |
/** @type {Array<Unsafe>} */ | ||
export const unsafe: Array<Unsafe> | ||
export type ConstructName = import('./types.js').ConstructName | ||
export type Unsafe = import('./types.js').Unsafe | ||
export type ConstructName = import('./types.js').ConstructName |
/** | ||
* @typedef {import('./types.js').ConstructName} ConstructName | ||
* @typedef {import('./types.js').Unsafe} Unsafe | ||
* @typedef {import('./types.js').ConstructName} ConstructName | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['bulletOrdered'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
@@ -8,3 +8,3 @@ /** | ||
): Exclude<Options['bullet'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['bullet'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['emphasis'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['fence'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['listItemIndent'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -11,10 +11,4 @@ | ||
export function checkListItemIndent(state) { | ||
const style = state.options.listItemIndent || 'tab' | ||
const style = state.options.listItemIndent || 'one' | ||
// To do: remove in a major. | ||
// @ts-expect-error: deprecated. | ||
if (style === 1 || style === '1') { | ||
return 'one' | ||
} | ||
if (style !== 'tab' && style !== 'one' && style !== 'mixed') { | ||
@@ -21,0 +15,0 @@ throw new Error( |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['quote'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['ruleRepetition'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['rule'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -12,3 +12,3 @@ /** | ||
): Exclude<Options['strong'], null | undefined> | ||
export type Options = import('../types.js').Options | ||
export type State = import('../types.js').State | ||
export type Options = import('../types.js').Options |
/** | ||
* @typedef {import('../types.js').Options} Options | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').Options} Options | ||
*/ | ||
@@ -5,0 +5,0 @@ |
/** | ||
* @typedef {import('../types.js').FlowContent} FlowContent | ||
* @typedef {import('../types.js').Node} Node | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').FlowParents} FlowParents | ||
* @typedef {import('../types.js').FlowChildren} FlowChildren | ||
* @typedef {import('../types.js').State} State | ||
@@ -9,3 +8,3 @@ * @typedef {import('../types.js').TrackFields} TrackFields | ||
/** | ||
* @param {Parent & {children: Array<FlowContent>}} parent | ||
* @param {FlowParents} parent | ||
* Parent of flow nodes. | ||
@@ -20,12 +19,9 @@ * @param {State} state | ||
export function containerFlow( | ||
parent: import('../types.js').Parent & { | ||
children: Array<FlowContent> | ||
}, | ||
parent: FlowParents, | ||
state: State, | ||
info: TrackFields | ||
): string | ||
export type FlowContent = import('../types.js').FlowContent | ||
export type Node = import('../types.js').Node | ||
export type Parent = import('../types.js').Parent | ||
export type FlowParents = import('../types.js').FlowParents | ||
export type FlowChildren = import('../types.js').FlowChildren | ||
export type State = import('../types.js').State | ||
export type TrackFields = import('../types.js').TrackFields |
/** | ||
* @typedef {import('../types.js').FlowContent} FlowContent | ||
* @typedef {import('../types.js').Node} Node | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').FlowParents} FlowParents | ||
* @typedef {import('../types.js').FlowChildren} FlowChildren | ||
* @typedef {import('../types.js').State} State | ||
@@ -10,3 +9,3 @@ * @typedef {import('../types.js').TrackFields} TrackFields | ||
/** | ||
* @param {Parent & {children: Array<FlowContent>}} parent | ||
* @param {FlowParents} parent | ||
* Parent of flow nodes. | ||
@@ -62,5 +61,5 @@ * @param {State} state | ||
/** | ||
* @param {Node} left | ||
* @param {Node} right | ||
* @param {Parent} parent | ||
* @param {FlowChildren} left | ||
* @param {FlowChildren} right | ||
* @param {FlowParents} parent | ||
* @param {State} state | ||
@@ -67,0 +66,0 @@ * @returns {string} |
/** | ||
* @typedef {import('../types.js').Handle} Handle | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').PhrasingContent} PhrasingContent | ||
* @typedef {import('../types.js').PhrasingParents} PhrasingParents | ||
* @typedef {import('../types.js').State} State | ||
@@ -13,3 +12,3 @@ */ | ||
* | ||
* @param {Parent & {children: Array<PhrasingContent>}} parent | ||
* @param {PhrasingParents} parent | ||
* Parent of flow nodes. | ||
@@ -24,5 +23,3 @@ * @param {State} state | ||
export function containerPhrasing( | ||
parent: import('../types.js').Parent & { | ||
children: Array<PhrasingContent> | ||
}, | ||
parent: PhrasingParents, | ||
state: State, | ||
@@ -33,4 +30,3 @@ info: Info | ||
export type Info = import('../types.js').Info | ||
export type Parent = import('../types.js').Parent | ||
export type PhrasingContent = import('../types.js').PhrasingContent | ||
export type PhrasingParents = import('../types.js').PhrasingParents | ||
export type State = import('../types.js').State |
/** | ||
* @typedef {import('../types.js').Handle} Handle | ||
* @typedef {import('../types.js').Info} Info | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').PhrasingContent} PhrasingContent | ||
* @typedef {import('../types.js').PhrasingParents} PhrasingParents | ||
* @typedef {import('../types.js').State} State | ||
@@ -14,3 +13,3 @@ */ | ||
* | ||
* @param {Parent & {children: Array<PhrasingContent>}} parent | ||
* @param {PhrasingParents} parent | ||
* Parent of flow nodes. | ||
@@ -17,0 +16,0 @@ * @param {State} state |
@@ -13,3 +13,3 @@ /** | ||
return Boolean( | ||
!state.options.fences && | ||
state.options.fences === false && | ||
node.value && | ||
@@ -16,0 +16,0 @@ // If there’s no info… |
@@ -6,3 +6,3 @@ /** | ||
import {visit, EXIT} from 'unist-util-visit' | ||
import {EXIT, visit} from 'unist-util-visit' | ||
import {toString} from 'mdast-util-to-string' | ||
@@ -20,3 +20,3 @@ | ||
// Note that this also | ||
visit(node, (node) => { | ||
visit(node, function (node) { | ||
if ( | ||
@@ -23,0 +23,0 @@ ('value' in node && /\r?\n|\r/.test(node.value)) || |
/** | ||
* @typedef {import('../types.js').ConstructName} ConstructName | ||
* @typedef {import('../types.js').Unsafe} Unsafe | ||
* @typedef {import('../types.js').ConstructName} ConstructName | ||
*/ | ||
@@ -14,3 +14,3 @@ /** | ||
): boolean | ||
export type ConstructName = import('../types.js').ConstructName | ||
export type Unsafe = import('../types.js').Unsafe | ||
export type ConstructName = import('../types.js').ConstructName |
/** | ||
* @typedef {import('../types.js').ConstructName} ConstructName | ||
* @typedef {import('../types.js').Unsafe} Unsafe | ||
* @typedef {import('../types.js').ConstructName} ConstructName | ||
*/ | ||
@@ -5,0 +5,0 @@ |
@@ -31,3 +31,3 @@ /** | ||
): string | ||
export type SafeConfig = import('../types.js').SafeConfig | ||
export type State = import('../types.js').State | ||
export type SafeConfig = import('../types.js').SafeConfig |
/** | ||
* @typedef {import('../types.js').SafeConfig} SafeConfig | ||
* @typedef {import('../types.js').State} State | ||
* @typedef {import('../types.js').SafeConfig} SafeConfig | ||
*/ | ||
@@ -5,0 +5,0 @@ |
{ | ||
"name": "mdast-util-to-markdown", | ||
"version": "1.5.0", | ||
"version": "2.0.0", | ||
"description": "mdast utility to serialize markdown", | ||
@@ -33,4 +33,3 @@ "license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
@@ -42,15 +41,15 @@ "lib/", | ||
"dependencies": { | ||
"@types/mdast": "^3.0.0", | ||
"@types/unist": "^2.0.0", | ||
"@types/mdast": "^4.0.0", | ||
"@types/unist": "^3.0.0", | ||
"longest-streak": "^3.0.0", | ||
"mdast-util-phrasing": "^3.0.0", | ||
"mdast-util-to-string": "^3.0.0", | ||
"micromark-util-decode-string": "^1.0.0", | ||
"unist-util-visit": "^4.0.0", | ||
"mdast-util-phrasing": "^4.0.0", | ||
"mdast-util-to-string": "^4.0.0", | ||
"micromark-util-decode-string": "^2.0.0", | ||
"unist-util-visit": "^5.0.0", | ||
"zwitch": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"c8": "^7.0.0", | ||
"mdast-util-from-markdown": "^1.0.0", | ||
"@types/node": "^20.0.0", | ||
"c8": "^8.0.0", | ||
"mdast-util-from-markdown": "^2.0.0", | ||
"prettier": "^2.0.0", | ||
@@ -60,5 +59,5 @@ "remark-cli": "^11.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"unist-util-remove-position": "^4.0.0", | ||
"xo": "^0.53.0" | ||
"typescript": "^5.0.0", | ||
"unist-util-remove-position": "^5.0.0", | ||
"xo": "^0.54.0" | ||
}, | ||
@@ -70,24 +69,16 @@ "scripts": { | ||
"test-api": "node --conditions development test/index.js", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"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 | ||
}, | ||
"xo": { | ||
"prettier": true, | ||
"rules": { | ||
"complexity": "off", | ||
"unicorn/prefer-code-point": "off", | ||
"unicorn/prefer-switch": "off" | ||
} | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -98,8 +89,25 @@ }, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true, | ||
"ignoreFiles": [ | ||
"lib/types.d.ts" | ||
] | ||
], | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"**/*.ts" | ||
], | ||
"rules": { | ||
"@typescript-eslint/consistent-type-definitions": "off" | ||
} | ||
} | ||
], | ||
"prettier": true, | ||
"rules": { | ||
"complexity": "off", | ||
"unicorn/prefer-code-point": "off" | ||
} | ||
} | ||
} |
182
readme.md
@@ -38,2 +38,3 @@ # mdast-util-to-markdown | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
@@ -69,3 +70,3 @@ * [Related](#related) | ||
This package is [ESM only][esm]. | ||
In Node.js (version 14.14+, or 16.0+), install with [npm][]: | ||
In Node.js (version 16+), install with [npm][]: | ||
@@ -79,3 +80,3 @@ ```sh | ||
```js | ||
import {toMarkdown} from 'https://esm.sh/mdast-util-to-markdown@1' | ||
import {toMarkdown} from 'https://esm.sh/mdast-util-to-markdown@2' | ||
``` | ||
@@ -87,3 +88,3 @@ | ||
<script type="module"> | ||
import {toMarkdown} from 'https://esm.sh/mdast-util-to-markdown@1?bundle' | ||
import {toMarkdown} from 'https://esm.sh/mdast-util-to-markdown@2?bundle' | ||
</script> | ||
@@ -140,3 +141,4 @@ ``` | ||
This package exports the identifiers `toMarkdown` and `defaultHandlers`. | ||
This package exports the identifiers [`defaultHandlers`][api-default-handlers] | ||
and [`toMarkdown`][api-to-markdown]. | ||
There is no default export. | ||
@@ -152,3 +154,3 @@ | ||
— tree to serialize | ||
* `options` ([`Options`][options], optional) | ||
* `options` ([`Options`][api-options], optional) | ||
— configuration | ||
@@ -162,3 +164,3 @@ | ||
Default (CommonMark) handlers ([`Handlers`][handlers]). | ||
Default (CommonMark) handlers ([`Handlers`][api-handlers]). | ||
@@ -212,5 +214,5 @@ ### `ConstructName` | ||
— parent of `node` | ||
* `state` ([`State`][state]) | ||
* `state` ([`State`][api-state]) | ||
— info passed around about the current state | ||
* `info` ([`Info`][info]) | ||
* `info` ([`Info`][api-info]) | ||
— info on the surrounding of the node that is serialized | ||
@@ -227,3 +229,3 @@ | ||
Each key is a node type (`Node['type']`), each value its corresponding handler | ||
([`Handle`][handle]). | ||
([`Handle`][api-handle]). | ||
@@ -270,3 +272,3 @@ ###### Type | ||
— parent of the two siblings | ||
* `state` ([`State`][state]) | ||
* `state` ([`State`][api-state]) | ||
— info passed around about the current state | ||
@@ -325,28 +327,22 @@ | ||
There are three cases where the primary bullet cannot be used: | ||
* when three or more list items are on their own, the last one is empty, and | ||
`bullet` is also a valid `rule`: `* - +`; this would turn into a thematic | ||
break if serialized with three primary bullets; `bulletOther` is used for | ||
the last item | ||
* when a thematic break is the first child of a list item and `bullet` is the | ||
same character as `rule`: `- ***`; this would turn into a single thematic | ||
break if serialized with primary bullets; `bulletOther` is used for the | ||
item | ||
* when two unordered lists appear next to each other: `* a\n- b`; | ||
`bulletOther` is used for such lists | ||
###### `options.bulletOther` | ||
Marker to use in certain cases where the primary bullet doesn’t work (`'*'`, | ||
`'+'`, or `'-'`, default: depends). | ||
`'+'`, or `'-'`, default: `'-'` when `bullet` is `'*'`, `'*'` otherwise). | ||
There are three cases where the primary bullet cannot be used: | ||
Cannot be equal to `bullet`. | ||
* When three list items are on their own, the last one is empty, and `bullet` | ||
is also a valid `rule`: `* - +`. | ||
This would turn into a thematic break if serialized with three primary | ||
bullets. | ||
As this is an edge case unlikely to appear in normal markdown, the last list | ||
item will be given a different bullet. | ||
* When a thematic break is the first child of one of the list items, and | ||
`bullet` is the same character as `rule`: `- ***`. | ||
This would turn into a single thematic break if serialized with primary | ||
bullets. | ||
As this is an edge case unlikely to appear in normal markdown this markup is | ||
always fixed, even if `bulletOther` is not passed | ||
* When two unordered lists appear next to each other: `* a\n- b`. | ||
CommonMark sees different bullets as different lists, but several markdown | ||
parsers parse it as one list. | ||
To solve for both, we instead inject an empty comment between the two lists: | ||
`* a\n<!---->\n* b`, but if `bulletOther` is given explicitly, it will be | ||
used instead | ||
###### `options.bulletOrdered` | ||
@@ -357,15 +353,6 @@ | ||
###### `options.bulletOrderedOther` | ||
Marker to use in certain cases where the primary bullet for ordered items | ||
doesn’t work (`'.'` or `')'`, default: none). | ||
There is one case where the primary bullet for ordered items cannot be used: | ||
* When two ordered lists appear next to each other: `1. a\n2) b`. | ||
CommonMark added support for `)` as a marker, but other markdown parsers | ||
do not support it. | ||
To solve for both, we instead inject an empty comment between the two lists: | ||
`1. a\n<!---->\n1. b`, but if `bulletOrderedOther` is given explicitly, it | ||
will be used instead | ||
* when two ordered lists appear next to each other: `1. a\n2) b`; to solve | ||
that, `'.'` will be used when `bulletOrdered` is `')'`, and `'.'` otherwise | ||
@@ -387,3 +374,3 @@ ###### `options.closeAtx` | ||
Whether to use fenced code always (`boolean`, default: `false`). | ||
Whether to use fenced code always (`boolean`, default: `true`). | ||
The default is to use fenced code if there is a language defined, if the code is | ||
@@ -399,4 +386,4 @@ empty, or if it starts or ends in blank lines. | ||
How to indent the content of list items (`'one'`, `'tab'`, or `'mixed'`, | ||
default: `'tab'`). | ||
How to indent the content of list items (`'mixed'`, `'one'`, or `'tab'`, | ||
default: `'one'`). | ||
Either with the size of the bullet plus one space (when `'one'`), a tab stop | ||
@@ -446,3 +433,3 @@ (`'tab'`), or depending on the item and its parent list (`'mixed'`, uses `'one'` | ||
The default is to add blank lines between any flow (“block”) construct. | ||
Turning this option on is a shortcut for a [`Join`][join] function like so: | ||
Turning this option on is a shortcut for a [`Join`][api-join] function like so: | ||
@@ -459,12 +446,12 @@ ```js | ||
Handle particular nodes ([`Handlers`][handlers], optional). | ||
Handle particular nodes ([`Handlers`][api-handlers], optional). | ||
###### `options.join` | ||
How to join blocks ([`Array<Join>`][join], optional). | ||
How to join blocks ([`Array<Join>`][api-join], optional). | ||
###### `options.unsafe` | ||
Schemas that define when characters cannot occur ([`Array<Unsafe>`][unsafe], | ||
optional). | ||
Schemas that define when characters cannot occur | ||
([`Array<Unsafe>`][api-unsafe], optional). | ||
@@ -498,3 +485,3 @@ ###### `options.extensions` | ||
* `stack` ([`Array<ConstructName>`][constructname]) | ||
* `stack` ([`Array<ConstructName>`][api-construct-name]) | ||
— stack of constructs we’re in | ||
@@ -506,25 +493,25 @@ * `indexStack` (`Array<number>`) | ||
[`Association`][association]) | ||
* `enter` (`(construct: ConstructName) => () => void`) | ||
* `enter` (`(construct: ConstructName) => () => undefined`) | ||
— enter a construct (returns a corresponding exit function) | ||
(see [`ConstructName`][constructname]) | ||
(see [`ConstructName`][api-construct-name]) | ||
* `indentLines` (`(value: string, map: Map) => string`) | ||
— pad serialized markdown (see [`Map`][map]) | ||
— pad serialized markdown (see [`Map`][api-map]) | ||
* `containerFlow` (`(parent: Node, info: Info) => string`) | ||
— serialize flow children (see [`Info`][info]) | ||
— serialize flow children (see [`Info`][api-info]) | ||
* `containerPhrasing` (`(parent: Node, info: Info) => string`) | ||
— serialize phrasing children (see [`Info`][info]) | ||
— serialize phrasing children (see [`Info`][api-info]) | ||
* `createTracker` (`(info: Info) => Tracker`) | ||
— track positional info in the output (see [`Info`][info], | ||
[`Tracker`][tracker]) | ||
— track positional info in the output (see [`Info`][api-info], | ||
[`Tracker`][api-tracker]) | ||
* `safe` (`(value: string, config: SafeConfig) => string`) | ||
— make a string safe for embedding (see [`SafeConfig`][safeconfig]) | ||
* `options` ([`Options`][options]) | ||
— make a string safe for embedding (see [`SafeConfig`][api-safe-config]) | ||
* `options` ([`Options`][api-options]) | ||
— applied user configuration | ||
* `unsafe` ([`Array<Unsafe>`][unsafe]) | ||
* `unsafe` ([`Array<Unsafe>`][api-unsafe]) | ||
— applied unsafe patterns | ||
* `join` ([`Array<Join>`][join]) | ||
* `join` ([`Array<Join>`][api-join]) | ||
— applied join handlers | ||
* `handle` ([`Handle`][handle]) | ||
* `handle` ([`Handle`][api-handle]) | ||
— call the configured handler for the given node | ||
* `handlers` ([`Handlers`][handlers]) | ||
* `handlers` ([`Handlers`][api-handlers]) | ||
— applied handlers | ||
@@ -547,3 +534,3 @@ * `bulletCurrent` (`string` or `undefined`) | ||
— get current tracked info | ||
* `shift` (`(value: number) => void`) | ||
* `shift` (`(value: number) => undefined`) | ||
— define a relative increased line shift (the typical indent for lines) | ||
@@ -561,7 +548,7 @@ * `move` (`(value: string) => string`) | ||
— single unsafe character | ||
* `inConstruct` ([`ConstructName`][constructname], `Array<ConstructName>`, | ||
optional) | ||
* `inConstruct` ([`Array<ConstructName>`][api-construct-name], | ||
`ConstructName`, optional) | ||
— constructs where this is bad | ||
* `notInConstruct` ([`ConstructName`][constructname], `Array<ConstructName>`, | ||
optional) | ||
* `notInConstruct` ([`Array<ConstructName>`][api-construct-name], | ||
`ConstructName`, optional) | ||
— constructs where this is fine again | ||
@@ -618,6 +605,25 @@ * `before` (`string`, optional) | ||
This package is fully typed with [TypeScript][]. | ||
It exports the additional types `ConstructName`, `ConstructNameMap`, `Handle`, | ||
`Handlers`, `Info` `Join`, `Map`, `Options`, `SafeConfig`, `State`, and | ||
`Unsafe`. | ||
It exports the additional types | ||
[`ConstructName`][api-construct-name], | ||
[`ConstructNameMap`][api-construct-name-map], | ||
[`Handle`][api-handle], | ||
[`Handlers`][api-handlers], | ||
[`Info`][api-info], | ||
[`Join`][api-join], | ||
[`Map`][api-map], | ||
[`Options`][api-options], | ||
[`SafeConfig`][api-safe-config], | ||
[`State`][api-State], and | ||
[`Unsafe`][api-Unsafe]. | ||
## Compatibility | ||
Projects maintained by the unified collective are compatible with maintained | ||
versions of Node.js. | ||
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-to-markdown@^2`, | ||
compatible with Node.js 16. | ||
## Security | ||
@@ -673,5 +679,5 @@ | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-to-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-to-markdown | ||
[size]: https://bundlephobia.com/result?p=mdast-util-to-markdown | ||
[size]: https://bundlejs.com/?q=mdast-util-to-markdown | ||
@@ -734,22 +740,28 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[constructname]: #constructname | ||
[api-construct-name]: #constructname | ||
[handle]: #handle | ||
[api-construct-name-map]: #constructnamemap | ||
[handlers]: #handlers | ||
[api-default-handlers]: #defaulthandlers | ||
[info]: #info | ||
[api-handle]: #handle | ||
[join]: #join | ||
[api-handlers]: #handlers | ||
[map]: #map | ||
[api-info]: #info | ||
[options]: #options | ||
[api-join]: #join | ||
[safeconfig]: #safeconfig | ||
[api-map]: #map | ||
[state]: #state | ||
[api-options]: #options | ||
[tracker]: #tracker | ||
[api-safe-config]: #safeconfig | ||
[unsafe]: #unsafe | ||
[api-state]: #state | ||
[api-to-markdown]: #tomarkdowntree-options | ||
[api-tracker]: #tracker | ||
[api-unsafe]: #unsafe |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
745
146251
97
4172
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/unist@3.0.3(transitive)
+ Addedmdast-util-phrasing@4.1.0(transitive)
+ Addedmdast-util-to-string@4.0.0(transitive)
+ Addedmicromark-util-character@2.1.0(transitive)
+ Addedmicromark-util-decode-numeric-character-reference@2.0.1(transitive)
+ Addedmicromark-util-decode-string@2.0.0(transitive)
+ Addedmicromark-util-symbol@2.0.0(transitive)
+ Addedmicromark-util-types@2.0.0(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-visit@5.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(transitive)
- Removed@types/mdast@3.0.15(transitive)
- Removed@types/unist@2.0.11(transitive)
- Removedmdast-util-phrasing@3.0.1(transitive)
- Removedmdast-util-to-string@3.2.0(transitive)
- Removedmicromark-util-character@1.2.0(transitive)
- Removedmicromark-util-decode-numeric-character-reference@1.1.0(transitive)
- Removedmicromark-util-decode-string@1.1.0(transitive)
- Removedmicromark-util-symbol@1.1.0(transitive)
- Removedmicromark-util-types@1.1.0(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
Updated@types/mdast@^4.0.0
Updated@types/unist@^3.0.0
Updatedmdast-util-phrasing@^4.0.0
Updatedmdast-util-to-string@^4.0.0
Updatedunist-util-visit@^5.0.0