mdast-util-to-markdown
Advanced tools
Comparing version 1.2.6 to 1.3.0
@@ -1,9 +0,9 @@ | ||
export {toMarkdown} from './lib/index.js' | ||
export type SafeOptions = import('./lib/types.js').SafeOptions | ||
export type Context = import('./lib/types.js').Context | ||
export type Handle = import('./lib/types.js').Handle | ||
export type Handlers = import('./lib/types.js').Handlers | ||
export type Join = import('./lib/types.js').Join | ||
export type Unsafe = import('./lib/types.js').Unsafe | ||
export type Options = import('./lib/types.js').Options | ||
export type Map = import('./lib/util/indent-lines.js').Map | ||
export { toMarkdown } from "./lib/index.js"; | ||
export type SafeOptions = import('./lib/types.js').SafeOptions; | ||
export type Context = import('./lib/types.js').Context; | ||
export type Handle = import('./lib/types.js').Handle; | ||
export type Handlers = import('./lib/types.js').Handlers; | ||
export type Join = import('./lib/types.js').Join; | ||
export type Unsafe = import('./lib/types.js').Unsafe; | ||
export type Options = import('./lib/types.js').Options; | ||
export type Map = import('./lib/util/indent-lines.js').Map; |
@@ -10,4 +10,4 @@ /** | ||
*/ | ||
export function configure(base: Context, extension: Options): Context | ||
export type Options = import('./types.js').Options | ||
export type Context = import('./types.js').Context | ||
export function configure(base: Context, extension: Options): Context; | ||
export type Options = import('./types.js').Options; | ||
export type Context = import('./types.js').Context; |
@@ -5,9 +5,5 @@ /** | ||
*/ | ||
export function blockquote( | ||
node: Blockquote, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type Blockquote = import('mdast').Blockquote | ||
export type Handle = import('../types.js').Handle | ||
export type Map = import('../util/indent-lines.js').Map | ||
export function blockquote(node: Blockquote, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type Blockquote = import('mdast').Blockquote; | ||
export type Handle = import('../types.js').Handle; | ||
export type Map = import('../util/indent-lines.js').Map; |
@@ -9,2 +9,3 @@ /** | ||
import {indentLines} from '../util/indent-lines.js' | ||
import {track} from '../util/track.js' | ||
@@ -15,5 +16,11 @@ /** | ||
*/ | ||
export function blockquote(node, _, context) { | ||
export function blockquote(node, _, context, safeOptions) { | ||
const exit = context.enter('blockquote') | ||
const value = indentLines(containerFlow(node, context), map) | ||
const tracker = track(safeOptions) | ||
tracker.move('> ') | ||
tracker.shift(2) | ||
const value = indentLines( | ||
containerFlow(node, context, tracker.current()), | ||
map | ||
) | ||
exit() | ||
@@ -20,0 +27,0 @@ return value |
@@ -5,9 +5,4 @@ /** | ||
*/ | ||
export function hardBreak( | ||
_: Break, | ||
_1: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context, | ||
safe: import('../types.js').SafeOptions | ||
): string | ||
export type Handle = import('../types.js').Handle | ||
export type Break = import('mdast').Break | ||
export function hardBreak(_: Break, _1: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safe: import("../types.js").SafeOptions): string; | ||
export type Handle = import('../types.js').Handle; | ||
export type Break = import('mdast').Break; |
@@ -5,10 +5,6 @@ /** | ||
*/ | ||
export function code( | ||
node: Code, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type Code = import('mdast').Code | ||
export type Handle = import('../types.js').Handle | ||
export type Exit = import('../types.js').Exit | ||
export type Map = import('../util/indent-lines.js').Map | ||
export function code(node: Code, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type Code = import('mdast').Code; | ||
export type Handle = import('../types.js').Handle; | ||
export type Exit = import('../types.js').Exit; | ||
export type Map = import('../util/indent-lines.js').Map; |
@@ -13,2 +13,3 @@ /** | ||
import {safe} from '../util/safe.js' | ||
import {track} from '../util/track.js' | ||
@@ -19,52 +20,53 @@ /** | ||
*/ | ||
export function code(node, _, context) { | ||
export function code(node, _, context, safeOptions) { | ||
const marker = checkFence(context) | ||
const raw = node.value || '' | ||
const suffix = marker === '`' ? 'GraveAccent' : 'Tilde' | ||
/** @type {string} */ | ||
let value | ||
/** @type {Exit} */ | ||
let exit | ||
if (formatCodeAsIndented(node, context)) { | ||
exit = context.enter('codeIndented') | ||
value = indentLines(raw, map) | ||
} else { | ||
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3)) | ||
/** @type {Exit} */ | ||
let subexit | ||
exit = context.enter('codeFenced') | ||
value = sequence | ||
const exit = context.enter('codeIndented') | ||
const value = indentLines(raw, map) | ||
exit() | ||
return value | ||
} | ||
if (node.lang) { | ||
subexit = context.enter('codeFencedLang' + suffix) | ||
value += safe(context, node.lang, { | ||
before: '`', | ||
const tracker = track(safeOptions) | ||
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3)) | ||
const exit = context.enter('codeFenced') | ||
let value = tracker.move(sequence) | ||
if (node.lang) { | ||
const subexit = context.enter('codeFencedLang' + suffix) | ||
value += tracker.move( | ||
safe(context, node.lang, { | ||
before: value, | ||
after: ' ', | ||
encode: ['`'] | ||
encode: ['`'], | ||
...tracker.current() | ||
}) | ||
subexit() | ||
} | ||
) | ||
subexit() | ||
} | ||
if (node.lang && node.meta) { | ||
subexit = context.enter('codeFencedMeta' + suffix) | ||
value += | ||
' ' + | ||
safe(context, node.meta, { | ||
before: ' ', | ||
after: '\n', | ||
encode: ['`'] | ||
}) | ||
subexit() | ||
} | ||
if (node.lang && node.meta) { | ||
const subexit = context.enter('codeFencedMeta' + suffix) | ||
value += tracker.move(' ') | ||
value += tracker.move( | ||
safe(context, node.meta, { | ||
before: value, | ||
after: '\n', | ||
encode: ['`'], | ||
...tracker.current() | ||
}) | ||
) | ||
subexit() | ||
} | ||
value += '\n' | ||
value += tracker.move('\n') | ||
if (raw) { | ||
value += raw + '\n' | ||
} | ||
value += sequence | ||
if (raw) { | ||
value += tracker.move(raw + '\n') | ||
} | ||
value += tracker.move(sequence) | ||
exit() | ||
@@ -71,0 +73,0 @@ return value |
@@ -5,8 +5,4 @@ /** | ||
*/ | ||
export function definition( | ||
node: Definition, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type Definition = import('mdast').Definition | ||
export type Handle = import('../types.js').Handle | ||
export function definition(node: Definition, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type Definition = import('mdast').Definition; | ||
export type Handle = import('../types.js').Handle; |
@@ -9,2 +9,3 @@ /** | ||
import {safe} from '../util/safe.js' | ||
import {track} from '../util/track.js' | ||
@@ -15,9 +16,17 @@ /** | ||
*/ | ||
export function definition(node, _, context) { | ||
const marker = checkQuote(context) | ||
const suffix = marker === '"' ? 'Quote' : 'Apostrophe' | ||
export function definition(node, _, context, safeOptions) { | ||
const quote = checkQuote(context) | ||
const suffix = quote === '"' ? 'Quote' : 'Apostrophe' | ||
const exit = context.enter('definition') | ||
let subexit = context.enter('label') | ||
let value = | ||
'[' + safe(context, association(node), {before: '[', after: ']'}) + ']: ' | ||
const tracker = track(safeOptions) | ||
let value = tracker.move('[') | ||
value += tracker.move( | ||
safe(context, association(node), { | ||
before: value, | ||
after: ']', | ||
...tracker.current() | ||
}) | ||
) | ||
value += tracker.move(']: ') | ||
@@ -33,7 +42,17 @@ subexit() | ||
subexit = context.enter('destinationLiteral') | ||
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>' | ||
value += tracker.move('<') | ||
value += tracker.move( | ||
safe(context, node.url, {before: value, after: '>', ...tracker.current()}) | ||
) | ||
value += tracker.move('>') | ||
} else { | ||
// No whitespace, raw is prettier. | ||
subexit = context.enter('destinationRaw') | ||
value += safe(context, node.url, {before: ' ', after: ' '}) | ||
value += tracker.move( | ||
safe(context, node.url, { | ||
before: value, | ||
after: node.title ? ' ' : '\n', | ||
...tracker.current() | ||
}) | ||
) | ||
} | ||
@@ -45,7 +64,11 @@ | ||
subexit = context.enter('title' + suffix) | ||
value += | ||
' ' + | ||
marker + | ||
safe(context, node.title, {before: marker, after: marker}) + | ||
marker | ||
value += tracker.move(' ' + quote) | ||
value += tracker.move( | ||
safe(context, node.title, { | ||
before: value, | ||
after: quote, | ||
...tracker.current() | ||
}) | ||
) | ||
value += tracker.move(quote) | ||
subexit() | ||
@@ -52,0 +75,0 @@ } |
@@ -5,12 +5,8 @@ /** | ||
*/ | ||
export function emphasis( | ||
node: Emphasis, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export function emphasis(node: Emphasis, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export namespace emphasis { | ||
export {emphasisPeek as peek} | ||
export { emphasisPeek as peek }; | ||
} | ||
export type Emphasis = import('mdast').Emphasis | ||
export type Handle = import('../types.js').Handle | ||
export type Emphasis = import('mdast').Emphasis; | ||
export type Handle = import('../types.js').Handle; | ||
/** | ||
@@ -20,7 +16,3 @@ * @type {Handle} | ||
*/ | ||
declare function emphasisPeek( | ||
_: Emphasis, | ||
_1: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export {} | ||
declare function emphasisPeek(_: Emphasis, _1: import("../types.js").Parent | null | undefined, context: import("../types.js").Context): string; | ||
export {}; |
@@ -8,2 +8,3 @@ /** | ||
import {containerPhrasing} from '../util/container-phrasing.js' | ||
import {track} from '../util/track.js' | ||
@@ -20,11 +21,17 @@ emphasis.peek = emphasisPeek | ||
*/ | ||
export function emphasis(node, _, context) { | ||
export function emphasis(node, _, context, safeOptions) { | ||
const marker = checkEmphasis(context) | ||
const exit = context.enter('emphasis') | ||
const value = containerPhrasing(node, context, { | ||
before: marker, | ||
after: marker | ||
}) | ||
const tracker = track(safeOptions) | ||
let value = tracker.move(marker) | ||
value += tracker.move( | ||
containerPhrasing(node, context, { | ||
before: value, | ||
after: marker, | ||
...tracker.current() | ||
}) | ||
) | ||
value += tracker.move(marker) | ||
exit() | ||
return marker + value + marker | ||
return value | ||
} | ||
@@ -31,0 +38,0 @@ |
@@ -5,9 +5,5 @@ /** | ||
*/ | ||
export function heading( | ||
node: Heading, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type Heading = import('mdast').Heading | ||
export type Handle = import('../types.js').Handle | ||
export type Exit = import('../types.js').Exit | ||
export function heading(node: Heading, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type Heading = import('mdast').Heading; | ||
export type Handle = import('../types.js').Handle; | ||
export type Exit = import('../types.js').Exit; |
@@ -9,2 +9,3 @@ /** | ||
import {containerPhrasing} from '../util/container-phrasing.js' | ||
import {track} from '../util/track.js' | ||
@@ -15,4 +16,5 @@ /** | ||
*/ | ||
export function heading(node, _, context) { | ||
export function heading(node, _, context, safeOptions) { | ||
const rank = Math.max(Math.min(6, node.depth || 1), 1) | ||
const tracker = track(safeOptions) | ||
@@ -22,3 +24,7 @@ if (formatHeadingAsSetext(node, context)) { | ||
const subexit = context.enter('phrasing') | ||
const value = containerPhrasing(node, context, {before: '\n', after: '\n'}) | ||
const value = containerPhrasing(node, context, { | ||
...tracker.current(), | ||
before: '\n', | ||
after: '\n' | ||
}) | ||
subexit() | ||
@@ -43,5 +49,17 @@ exit() | ||
const subexit = context.enter('phrasing') | ||
let value = containerPhrasing(node, context, {before: '# ', after: '\n'}) | ||
// Note: for proper tracking, we should reset the output positions when there | ||
// is no content returned, because then the space is not output. | ||
// Practically, in that case, there is no content, so it doesn’t matter that | ||
// we’ve tracked one too many characters. | ||
tracker.move(sequence + ' ') | ||
let value = containerPhrasing(node, context, { | ||
before: '# ', | ||
after: '\n', | ||
...tracker.current() | ||
}) | ||
if (/^[\t ]/.test(value)) { | ||
// To do: what effect has the character reference on tracking? | ||
value = | ||
@@ -48,0 +66,0 @@ '&#x' + |
@@ -5,12 +5,12 @@ /** | ||
*/ | ||
export function html(node: HTML): string | ||
export function html(node: HTML): string; | ||
export namespace html { | ||
export {htmlPeek as peek} | ||
export { htmlPeek as peek }; | ||
} | ||
export type HTML = import('mdast').HTML | ||
export type Handle = import('../types.js').Handle | ||
export type HTML = import('mdast').HTML; | ||
export type Handle = import('../types.js').Handle; | ||
/** | ||
* @type {Handle} | ||
*/ | ||
declare function htmlPeek(): string | ||
export {} | ||
declare function htmlPeek(): string; | ||
export {}; |
@@ -5,16 +5,12 @@ /** | ||
*/ | ||
export function imageReference( | ||
node: ImageReference, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export function imageReference(node: ImageReference, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export namespace imageReference { | ||
export {imageReferencePeek as peek} | ||
export { imageReferencePeek as peek }; | ||
} | ||
export type ImageReference = import('mdast').ImageReference | ||
export type Handle = import('../types.js').Handle | ||
export type ImageReference = import('mdast').ImageReference; | ||
export type Handle = import('../types.js').Handle; | ||
/** | ||
* @type {Handle} | ||
*/ | ||
declare function imageReferencePeek(): string | ||
export {} | ||
declare function imageReferencePeek(): string; | ||
export {}; |
@@ -8,2 +8,3 @@ /** | ||
import {safe} from '../util/safe.js' | ||
import {track} from '../util/track.js' | ||
@@ -16,8 +17,14 @@ imageReference.peek = imageReferencePeek | ||
*/ | ||
export function imageReference(node, _, context) { | ||
export function imageReference(node, _, context, safeOptions) { | ||
const type = node.referenceType | ||
const exit = context.enter('imageReference') | ||
let subexit = context.enter('label') | ||
const alt = safe(context, node.alt, {before: '[', after: ']'}) | ||
let value = '![' + alt + ']' | ||
const tracker = track(safeOptions) | ||
let value = tracker.move('![') | ||
const alt = safe(context, node.alt, { | ||
before: value, | ||
after: ']', | ||
...tracker.current() | ||
}) | ||
value += tracker.move(alt + '][') | ||
@@ -29,3 +36,11 @@ subexit() | ||
subexit = context.enter('reference') | ||
const reference = safe(context, association(node), {before: '[', after: ']'}) | ||
// Note: for proper tracking, we should reset the output positions when we end | ||
// up making a `shortcut` reference, because then there is no brace output. | ||
// Practically, in that case, there is no content, so it doesn’t matter that | ||
// we’ve tracked one too many characters. | ||
const reference = safe(context, association(node), { | ||
before: value, | ||
after: ']', | ||
...tracker.current() | ||
}) | ||
subexit() | ||
@@ -36,5 +51,8 @@ context.stack = stack | ||
if (type === 'full' || !alt || alt !== reference) { | ||
value += '[' + reference + ']' | ||
} else if (type !== 'shortcut') { | ||
value += '[]' | ||
value += tracker.move(reference + ']') | ||
} else if (type === 'shortcut') { | ||
// Remove the unwanted `[`. | ||
value = value.slice(0, -1) | ||
} else { | ||
value += tracker.move(']') | ||
} | ||
@@ -41,0 +59,0 @@ |
@@ -5,16 +5,12 @@ /** | ||
*/ | ||
export function image( | ||
node: Image, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export function image(node: Image, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export namespace image { | ||
export {imagePeek as peek} | ||
export { imagePeek as peek }; | ||
} | ||
export type Image = import('mdast').Image | ||
export type Handle = import('../types.js').Handle | ||
export type Image = import('mdast').Image; | ||
export type Handle = import('../types.js').Handle; | ||
/** | ||
* @type {Handle} | ||
*/ | ||
declare function imagePeek(): string | ||
export {} | ||
declare function imagePeek(): string; | ||
export {}; |
@@ -8,2 +8,3 @@ /** | ||
import {safe} from '../util/safe.js' | ||
import {track} from '../util/track.js' | ||
@@ -16,3 +17,3 @@ image.peek = imagePeek | ||
*/ | ||
export function image(node, _, context) { | ||
export function image(node, _, context, safeOptions) { | ||
const quote = checkQuote(context) | ||
@@ -22,3 +23,8 @@ const suffix = quote === '"' ? 'Quote' : 'Apostrophe' | ||
let subexit = context.enter('label') | ||
let value = '![' + safe(context, node.alt, {before: '[', after: ']'}) + '](' | ||
const tracker = track(safeOptions) | ||
let value = tracker.move('![') | ||
value += tracker.move( | ||
safe(context, node.alt, {before: value, after: ']', ...tracker.current()}) | ||
) | ||
value += tracker.move('](') | ||
@@ -34,10 +40,17 @@ subexit() | ||
subexit = context.enter('destinationLiteral') | ||
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>' | ||
value += tracker.move('<') | ||
value += tracker.move( | ||
safe(context, node.url, {before: value, after: '>', ...tracker.current()}) | ||
) | ||
value += tracker.move('>') | ||
} else { | ||
// No whitespace, raw is prettier. | ||
subexit = context.enter('destinationRaw') | ||
value += safe(context, node.url, { | ||
before: '(', | ||
after: node.title ? ' ' : ')' | ||
}) | ||
value += tracker.move( | ||
safe(context, node.url, { | ||
before: value, | ||
after: node.title ? ' ' : ')', | ||
...tracker.current() | ||
}) | ||
) | ||
} | ||
@@ -49,11 +62,15 @@ | ||
subexit = context.enter('title' + suffix) | ||
value += | ||
' ' + | ||
quote + | ||
safe(context, node.title, {before: quote, after: quote}) + | ||
quote | ||
value += tracker.move(' ' + quote) | ||
value += tracker.move( | ||
safe(context, node.title, { | ||
before: value, | ||
after: quote, | ||
...tracker.current() | ||
}) | ||
) | ||
value += tracker.move(quote) | ||
subexit() | ||
} | ||
value += ')' | ||
value += tracker.move(')') | ||
exit() | ||
@@ -60,0 +77,0 @@ |
export namespace handle { | ||
export {blockquote} | ||
export {hardBreak as break} | ||
export {code} | ||
export {definition} | ||
export {emphasis} | ||
export {hardBreak} | ||
export {heading} | ||
export {html} | ||
export {image} | ||
export {imageReference} | ||
export {inlineCode} | ||
export {link} | ||
export {linkReference} | ||
export {list} | ||
export {listItem} | ||
export {paragraph} | ||
export {root} | ||
export {strong} | ||
export {text} | ||
export {thematicBreak} | ||
export { blockquote }; | ||
export { hardBreak as break }; | ||
export { code }; | ||
export { definition }; | ||
export { emphasis }; | ||
export { hardBreak }; | ||
export { heading }; | ||
export { html }; | ||
export { image }; | ||
export { imageReference }; | ||
export { inlineCode }; | ||
export { link }; | ||
export { linkReference }; | ||
export { list }; | ||
export { listItem }; | ||
export { paragraph }; | ||
export { root }; | ||
export { strong }; | ||
export { text }; | ||
export { thematicBreak }; | ||
} | ||
import {blockquote} from './blockquote.js' | ||
import {hardBreak} from './break.js' | ||
import {code} from './code.js' | ||
import {definition} from './definition.js' | ||
import {emphasis} from './emphasis.js' | ||
import {heading} from './heading.js' | ||
import {html} from './html.js' | ||
import {image} from './image.js' | ||
import {imageReference} from './image-reference.js' | ||
import {inlineCode} from './inline-code.js' | ||
import {link} from './link.js' | ||
import {linkReference} from './link-reference.js' | ||
import {list} from './list.js' | ||
import {listItem} from './list-item.js' | ||
import {paragraph} from './paragraph.js' | ||
import {root} from './root.js' | ||
import {strong} from './strong.js' | ||
import {text} from './text.js' | ||
import {thematicBreak} from './thematic-break.js' | ||
import { blockquote } from "./blockquote.js"; | ||
import { hardBreak } from "./break.js"; | ||
import { code } from "./code.js"; | ||
import { definition } from "./definition.js"; | ||
import { emphasis } from "./emphasis.js"; | ||
import { heading } from "./heading.js"; | ||
import { html } from "./html.js"; | ||
import { image } from "./image.js"; | ||
import { imageReference } from "./image-reference.js"; | ||
import { inlineCode } from "./inline-code.js"; | ||
import { link } from "./link.js"; | ||
import { linkReference } from "./link-reference.js"; | ||
import { list } from "./list.js"; | ||
import { listItem } from "./list-item.js"; | ||
import { paragraph } from "./paragraph.js"; | ||
import { root } from "./root.js"; | ||
import { strong } from "./strong.js"; | ||
import { text } from "./text.js"; | ||
import { thematicBreak } from "./thematic-break.js"; |
@@ -5,16 +5,12 @@ /** | ||
*/ | ||
export function inlineCode( | ||
node: InlineCode, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export function inlineCode(node: InlineCode, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context): string; | ||
export namespace inlineCode { | ||
export {inlineCodePeek as peek} | ||
export { inlineCodePeek as peek }; | ||
} | ||
export type InlineCode = import('mdast').InlineCode | ||
export type Handle = import('../types.js').Handle | ||
export type InlineCode = import('mdast').InlineCode; | ||
export type Handle = import('../types.js').Handle; | ||
/** | ||
* @type {Handle} | ||
*/ | ||
declare function inlineCodePeek(): string | ||
export {} | ||
declare function inlineCodePeek(): string; | ||
export {}; |
@@ -5,16 +5,12 @@ /** | ||
*/ | ||
export function linkReference( | ||
node: LinkReference, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export function linkReference(node: LinkReference, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export namespace linkReference { | ||
export {linkReferencePeek as peek} | ||
export { linkReferencePeek as peek }; | ||
} | ||
export type LinkReference = import('mdast').LinkReference | ||
export type Handle = import('../types.js').Handle | ||
export type LinkReference = import('mdast').LinkReference; | ||
export type Handle = import('../types.js').Handle; | ||
/** | ||
* @type {Handle} | ||
*/ | ||
declare function linkReferencePeek(): string | ||
export {} | ||
declare function linkReferencePeek(): string; | ||
export {}; |
@@ -9,2 +9,3 @@ /** | ||
import {safe} from '../util/safe.js' | ||
import {track} from '../util/track.js' | ||
@@ -17,8 +18,14 @@ linkReference.peek = linkReferencePeek | ||
*/ | ||
export function linkReference(node, _, context) { | ||
export function linkReference(node, _, context, safeOptions) { | ||
const type = node.referenceType | ||
const exit = context.enter('linkReference') | ||
let subexit = context.enter('label') | ||
const text = containerPhrasing(node, context, {before: '[', after: ']'}) | ||
let value = '[' + text + ']' | ||
const tracker = track(safeOptions) | ||
let value = tracker.move('[') | ||
const text = containerPhrasing(node, context, { | ||
before: value, | ||
after: ']', | ||
...tracker.current() | ||
}) | ||
value += tracker.move(text + '][') | ||
@@ -30,3 +37,11 @@ subexit() | ||
subexit = context.enter('reference') | ||
const reference = safe(context, association(node), {before: '[', after: ']'}) | ||
// Note: for proper tracking, we should reset the output positions when we end | ||
// up making a `shortcut` reference, because then there is no brace output. | ||
// Practically, in that case, there is no content, so it doesn’t matter that | ||
// we’ve tracked one too many characters. | ||
const reference = safe(context, association(node), { | ||
before: value, | ||
after: ']', | ||
...tracker.current() | ||
}) | ||
subexit() | ||
@@ -37,5 +52,8 @@ context.stack = stack | ||
if (type === 'full' || !text || text !== reference) { | ||
value += '[' + reference + ']' | ||
} else if (type !== 'shortcut') { | ||
value += '[]' | ||
value += tracker.move(reference + ']') | ||
} else if (type === 'shortcut') { | ||
// Remove the unwanted `[`. | ||
value = value.slice(0, -1) | ||
} else { | ||
value += tracker.move(']') | ||
} | ||
@@ -42,0 +60,0 @@ |
@@ -5,13 +5,9 @@ /** | ||
*/ | ||
export function link( | ||
node: Link, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export function link(node: Link, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export namespace link { | ||
export {linkPeek as peek} | ||
export { linkPeek as peek }; | ||
} | ||
export type Link = import('mdast').Link | ||
export type Handle = import('../types.js').Handle | ||
export type Exit = import('../types.js').Exit | ||
export type Link = import('mdast').Link; | ||
export type Handle = import('../types.js').Handle; | ||
export type Exit = import('../types.js').Exit; | ||
/** | ||
@@ -21,7 +17,3 @@ * @type {Handle} | ||
*/ | ||
declare function linkPeek( | ||
node: Link, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export {} | ||
declare function linkPeek(node: Link, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context): string; | ||
export {}; |
@@ -11,2 +11,3 @@ /** | ||
import {safe} from '../util/safe.js' | ||
import {track} from '../util/track.js' | ||
@@ -19,5 +20,6 @@ link.peek = linkPeek | ||
*/ | ||
export function link(node, _, context) { | ||
export function link(node, _, context, safeOptions) { | ||
const quote = checkQuote(context) | ||
const suffix = quote === '"' ? 'Quote' : 'Apostrophe' | ||
const tracker = track(safeOptions) | ||
/** @type {Exit} */ | ||
@@ -27,4 +29,2 @@ let exit | ||
let subexit | ||
/** @type {string} */ | ||
let value | ||
@@ -36,4 +36,11 @@ if (formatLinkAsAutolink(node, context)) { | ||
exit = context.enter('autolink') | ||
value = | ||
'<' + containerPhrasing(node, context, {before: '<', after: '>'}) + '>' | ||
let value = tracker.move('<') | ||
value += tracker.move( | ||
containerPhrasing(node, context, { | ||
before: value, | ||
after: '>', | ||
...tracker.current() | ||
}) | ||
) | ||
value += tracker.move('>') | ||
exit() | ||
@@ -46,4 +53,11 @@ context.stack = stack | ||
subexit = context.enter('label') | ||
value = | ||
'[' + containerPhrasing(node, context, {before: '[', after: ']'}) + '](' | ||
let value = tracker.move('[') | ||
value += tracker.move( | ||
containerPhrasing(node, context, { | ||
before: value, | ||
after: '](', | ||
...tracker.current() | ||
}) | ||
) | ||
value += tracker.move('](') | ||
subexit() | ||
@@ -58,10 +72,17 @@ | ||
subexit = context.enter('destinationLiteral') | ||
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>' | ||
value += tracker.move('<') | ||
value += tracker.move( | ||
safe(context, node.url, {before: value, after: '>', ...tracker.current()}) | ||
) | ||
value += tracker.move('>') | ||
} else { | ||
// No whitespace, raw is prettier. | ||
subexit = context.enter('destinationRaw') | ||
value += safe(context, node.url, { | ||
before: '(', | ||
after: node.title ? ' ' : ')' | ||
}) | ||
value += tracker.move( | ||
safe(context, node.url, { | ||
before: value, | ||
after: node.title ? ' ' : ')', | ||
...tracker.current() | ||
}) | ||
) | ||
} | ||
@@ -73,11 +94,15 @@ | ||
subexit = context.enter('title' + suffix) | ||
value += | ||
' ' + | ||
quote + | ||
safe(context, node.title, {before: quote, after: quote}) + | ||
quote | ||
value += tracker.move(' ' + quote) | ||
value += tracker.move( | ||
safe(context, node.title, { | ||
before: value, | ||
after: quote, | ||
...tracker.current() | ||
}) | ||
) | ||
value += tracker.move(quote) | ||
subexit() | ||
} | ||
value += ')' | ||
value += tracker.move(')') | ||
@@ -84,0 +109,0 @@ exit() |
@@ -5,11 +5,7 @@ /** | ||
*/ | ||
export function listItem( | ||
node: ListItem, | ||
parent: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type ListItem = import('mdast').ListItem | ||
export type List = import('mdast').List | ||
export type Map = import('../util/indent-lines.js').Map | ||
export type Options = import('../types.js').Options | ||
export type Handle = import('../types.js').Handle | ||
export function listItem(node: ListItem, parent: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type ListItem = import('mdast').ListItem; | ||
export type List = import('mdast').List; | ||
export type Map = import('../util/indent-lines.js').Map; | ||
export type Options = import('../types.js').Options; | ||
export type Handle = import('../types.js').Handle; |
@@ -13,2 +13,3 @@ /** | ||
import {indentLines} from '../util/indent-lines.js' | ||
import {track} from '../util/track.js' | ||
@@ -19,3 +20,3 @@ /** | ||
*/ | ||
export function listItem(node, parent, context) { | ||
export function listItem(node, parent, context, safeOptions) { | ||
const listItemIndent = checkListItemIndent(context) | ||
@@ -46,4 +47,10 @@ let bullet = context.bulletCurrent || checkBullet(context) | ||
const tracker = track(safeOptions) | ||
tracker.move(bullet + ' '.repeat(size - bullet.length)) | ||
tracker.shift(size) | ||
const exit = context.enter('listItem') | ||
const value = indentLines(containerFlow(node, context), map) | ||
const value = indentLines( | ||
containerFlow(node, context, tracker.current()), | ||
map | ||
) | ||
exit() | ||
@@ -50,0 +57,0 @@ |
@@ -5,8 +5,4 @@ /** | ||
*/ | ||
export function list( | ||
node: List, | ||
parent: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type List = import('mdast').List | ||
export type Handle = import('../types.js').Handle | ||
export function list(node: List, parent: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type List = import('mdast').List; | ||
export type Handle = import('../types.js').Handle; |
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
export function list(node, parent, context) { | ||
export function list(node, parent, context, safeOptions) { | ||
const exit = context.enter('list') | ||
@@ -105,3 +105,3 @@ const bulletCurrent = context.bulletCurrent | ||
context.bulletCurrent = bullet | ||
const value = containerFlow(node, context) | ||
const value = containerFlow(node, context, safeOptions) | ||
context.bulletLastUsed = bullet | ||
@@ -108,0 +108,0 @@ context.bulletCurrent = bulletCurrent |
@@ -5,8 +5,4 @@ /** | ||
*/ | ||
export function paragraph( | ||
node: Paragraph, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type Paragraph = import('mdast').Paragraph | ||
export type Handle = import('../types.js').Handle | ||
export function paragraph(node: Paragraph, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type Paragraph = import('mdast').Paragraph; | ||
export type Handle = import('../types.js').Handle; |
@@ -12,6 +12,6 @@ /** | ||
*/ | ||
export function paragraph(node, _, context) { | ||
export function paragraph(node, _, context, safeOptions) { | ||
const exit = context.enter('paragraph') | ||
const subexit = context.enter('phrasing') | ||
const value = containerPhrasing(node, context, {before: '\n', after: '\n'}) | ||
const value = containerPhrasing(node, context, safeOptions) | ||
subexit() | ||
@@ -18,0 +18,0 @@ exit() |
@@ -5,8 +5,4 @@ /** | ||
*/ | ||
export function root( | ||
node: Root, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type Root = import('mdast').Root | ||
export type Handle = import('../types.js').Handle | ||
export function root(node: Root, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type Root = import('mdast').Root; | ||
export type Handle = import('../types.js').Handle; |
@@ -12,4 +12,4 @@ /** | ||
*/ | ||
export function root(node, _, context) { | ||
return containerFlow(node, context) | ||
export function root(node, _, context, safeOptions) { | ||
return containerFlow(node, context, safeOptions) | ||
} |
@@ -5,12 +5,8 @@ /** | ||
*/ | ||
export function strong( | ||
node: Strong, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export function strong(node: Strong, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export namespace strong { | ||
export {strongPeek as peek} | ||
export { strongPeek as peek }; | ||
} | ||
export type Strong = import('mdast').Strong | ||
export type Handle = import('../types.js').Handle | ||
export type Strong = import('mdast').Strong; | ||
export type Handle = import('../types.js').Handle; | ||
/** | ||
@@ -20,7 +16,3 @@ * @type {Handle} | ||
*/ | ||
declare function strongPeek( | ||
_: Strong, | ||
_1: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export {} | ||
declare function strongPeek(_: Strong, _1: import("../types.js").Parent | null | undefined, context: import("../types.js").Context): string; | ||
export {}; |
@@ -8,2 +8,3 @@ /** | ||
import {containerPhrasing} from '../util/container-phrasing.js' | ||
import {track} from '../util/track.js' | ||
@@ -20,11 +21,17 @@ strong.peek = strongPeek | ||
*/ | ||
export function strong(node, _, context) { | ||
export function strong(node, _, context, safeOptions) { | ||
const marker = checkStrong(context) | ||
const exit = context.enter('strong') | ||
const value = containerPhrasing(node, context, { | ||
before: marker, | ||
after: marker | ||
}) | ||
const tracker = track(safeOptions) | ||
let value = tracker.move(marker + marker) | ||
value += tracker.move( | ||
containerPhrasing(node, context, { | ||
before: value, | ||
after: marker, | ||
...tracker.current() | ||
}) | ||
) | ||
value += tracker.move(marker + marker) | ||
exit() | ||
return marker + marker + value + marker + marker | ||
return value | ||
} | ||
@@ -31,0 +38,0 @@ |
@@ -5,9 +5,4 @@ /** | ||
*/ | ||
export function text( | ||
node: Text, | ||
_: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context, | ||
safeOptions: import('../types.js').SafeOptions | ||
): string | ||
export type Text = import('mdast').Text | ||
export type Handle = import('../types.js').Handle | ||
export function text(node: Text, _: import("../types.js").Parent | null | undefined, context: import("../types.js").Context, safeOptions: import("../types.js").SafeOptions): string; | ||
export type Text = import('mdast').Text; | ||
export type Handle = import('../types.js').Handle; |
@@ -5,8 +5,4 @@ /** | ||
*/ | ||
export function thematicBreak( | ||
_: ThematicBreak, | ||
_1: import('../types.js').Parent | null | undefined, | ||
context: import('../types.js').Context | ||
): string | ||
export type Handle = import('../types.js').Handle | ||
export type ThematicBreak = import('mdast').ThematicBreak | ||
export function thematicBreak(_: ThematicBreak, _1: import("../types.js").Parent | null | undefined, context: import("../types.js").Context): string; | ||
export type Handle = import('../types.js').Handle; | ||
export type ThematicBreak = import('mdast').ThematicBreak; |
@@ -6,11 +6,8 @@ /** | ||
*/ | ||
export function toMarkdown( | ||
tree: Node, | ||
options?: import('./types.js').Options | undefined | ||
): string | ||
export type Node = import('./types.js').Node | ||
export type Options = import('./types.js').Options | ||
export type Context = import('./types.js').Context | ||
export type Handle = import('./types.js').Handle | ||
export type Join = import('./types.js').Join | ||
export type Unsafe = import('./types.js').Unsafe | ||
export function toMarkdown(tree: Node, options?: import("./types.js").Options | undefined): string; | ||
export type Node = import('./types.js').Node; | ||
export type Options = import('./types.js').Options; | ||
export type Context = import('./types.js').Context; | ||
export type Handle = import('./types.js').Handle; | ||
export type Join = import('./types.js').Join; | ||
export type Unsafe = import('./types.js').Unsafe; |
@@ -50,3 +50,8 @@ /** | ||
let result = context.handle(tree, null, context, {before: '\n', after: '\n'}) | ||
let result = context.handle(tree, null, context, { | ||
before: '\n', | ||
after: '\n', | ||
now: {line: 1, column: 1}, | ||
lineShift: 0 | ||
}) | ||
@@ -53,0 +58,0 @@ if ( |
@@ -1,3 +0,3 @@ | ||
/** @type {Array.<Join>} */ | ||
export const join: Array<Join> | ||
export type Join = import('./types.js').Join | ||
/** @type {Array<Join>} */ | ||
export const join: Array<Join>; | ||
export type Join = import('./types.js').Join; |
@@ -8,3 +8,3 @@ /** | ||
/** @type {Array.<Join>} */ | ||
/** @type {Array<Join>} */ | ||
export const join = [joinDefaults] | ||
@@ -11,0 +11,0 @@ |
@@ -1,84 +0,80 @@ | ||
export type UnistParent = import('unist').Parent | ||
export type Root = import('mdast').Root | ||
export type Content = import('mdast').Content | ||
export type Node = Root | Content | ||
export type Parent = Extract<Node, UnistParent> | ||
export type SafeOptions = { | ||
before: string | ||
after: string | ||
} | ||
export type Enter = (type: string) => Exit | ||
export type Exit = () => void | ||
export type UnistParent = import('unist').Parent; | ||
export type Point = import('unist').Point; | ||
export type Root = import('mdast').Root; | ||
export type Content = import('mdast').Content; | ||
export type Node = Root | Content; | ||
export type Parent = Extract<Node, UnistParent>; | ||
export type TrackFields = { | ||
now: Point; | ||
lineShift: number; | ||
}; | ||
export type SafeFields = { | ||
before: string; | ||
after: string; | ||
}; | ||
export type SafeOptions = TrackFields & SafeFields; | ||
export type Enter = (type: string) => Exit; | ||
export type Exit = () => void; | ||
export type Context = { | ||
/** | ||
* Stack of labels. | ||
*/ | ||
stack: string[] | ||
/** | ||
* Positions of children in their parents. | ||
*/ | ||
indexStack: number[] | ||
enter: Enter | ||
options: Options | ||
unsafe: Array<Unsafe> | ||
join: Array<Join> | ||
handle: Handle | ||
handlers: Handlers | ||
/** | ||
* The marker used by the current list. | ||
*/ | ||
bulletCurrent: string | undefined | ||
/** | ||
* The marker used by the previous list. | ||
*/ | ||
bulletLastUsed: string | undefined | ||
} | ||
export type Handle = ( | ||
node: any, | ||
parent: Parent | null | undefined, | ||
context: Context, | ||
safeOptions: SafeOptions | ||
) => string | ||
export type Handlers = Record<string, Handle> | ||
export type Join = ( | ||
left: Node, | ||
right: Node, | ||
parent: Parent, | ||
context: Context | ||
) => boolean | null | void | number | ||
/** | ||
* Stack of labels. | ||
*/ | ||
stack: Array<string>; | ||
/** | ||
* Positions of children in their parents. | ||
*/ | ||
indexStack: Array<number>; | ||
enter: Enter; | ||
options: Options; | ||
unsafe: Array<Unsafe>; | ||
join: Array<Join>; | ||
handle: Handle; | ||
handlers: Handlers; | ||
/** | ||
* The marker used by the current list. | ||
*/ | ||
bulletCurrent: string | undefined; | ||
/** | ||
* The marker used by the previous list. | ||
*/ | ||
bulletLastUsed: string | undefined; | ||
}; | ||
export type Handle = (node: any, parent: Parent | null | undefined, context: Context, safeOptions: SafeOptions) => string; | ||
export type Handlers = Record<string, Handle>; | ||
export type Join = (left: Node, right: Node, parent: Parent, context: Context) => boolean | null | void | number; | ||
export type Unsafe = { | ||
character: string | ||
inConstruct?: string | string[] | undefined | ||
notInConstruct?: string | string[] | undefined | ||
after?: string | undefined | ||
before?: string | undefined | ||
atBreak?: boolean | undefined | ||
/** | ||
* The unsafe pattern compiled as a regex | ||
*/ | ||
_compiled?: RegExp | undefined | ||
} | ||
character: string; | ||
inConstruct?: string | string[] | undefined; | ||
notInConstruct?: string | string[] | undefined; | ||
after?: string | undefined; | ||
before?: string | undefined; | ||
atBreak?: boolean | undefined; | ||
/** | ||
* The unsafe pattern compiled as a regex | ||
*/ | ||
_compiled?: RegExp | undefined; | ||
}; | ||
export type Options = { | ||
bullet?: '-' | '*' | '+' | undefined | ||
bulletOther?: '-' | '*' | '+' | undefined | ||
bulletOrdered?: '.' | ')' | undefined | ||
bulletOrderedOther?: '.' | ')' | undefined | ||
closeAtx?: boolean | undefined | ||
emphasis?: '*' | '_' | undefined | ||
fence?: '~' | '`' | undefined | ||
fences?: boolean | undefined | ||
incrementListMarker?: boolean | undefined | ||
listItemIndent?: 'tab' | 'one' | 'mixed' | undefined | ||
quote?: '"' | "'" | undefined | ||
resourceLink?: boolean | undefined | ||
rule?: '-' | '*' | '_' | undefined | ||
ruleRepetition?: number | undefined | ||
ruleSpaces?: boolean | undefined | ||
setext?: boolean | undefined | ||
strong?: '*' | '_' | undefined | ||
tightDefinitions?: boolean | undefined | ||
extensions?: Options[] | undefined | ||
handlers?: Handlers | undefined | ||
join?: Join[] | undefined | ||
unsafe?: Unsafe[] | undefined | ||
} | ||
bullet?: "-" | "*" | "+" | undefined; | ||
bulletOther?: "-" | "*" | "+" | undefined; | ||
bulletOrdered?: "." | ")" | undefined; | ||
bulletOrderedOther?: "." | ")" | undefined; | ||
closeAtx?: boolean | undefined; | ||
emphasis?: "*" | "_" | undefined; | ||
fence?: "~" | "`" | undefined; | ||
fences?: boolean | undefined; | ||
incrementListMarker?: boolean | undefined; | ||
listItemIndent?: "tab" | "one" | "mixed" | undefined; | ||
quote?: "\"" | "'" | undefined; | ||
resourceLink?: boolean | undefined; | ||
rule?: "-" | "*" | "_" | undefined; | ||
ruleRepetition?: number | undefined; | ||
ruleSpaces?: boolean | undefined; | ||
setext?: boolean | undefined; | ||
strong?: "*" | "_" | undefined; | ||
tightDefinitions?: boolean | undefined; | ||
extensions?: Options[] | undefined; | ||
handlers?: Handlers | undefined; | ||
join?: Join[] | undefined; | ||
unsafe?: Unsafe[] | undefined; | ||
}; |
/** | ||
* @typedef {import('unist').Parent} UnistParent | ||
* @typedef {import('unist').Point} Point | ||
* @typedef {import('mdast').Root} Root | ||
@@ -10,3 +11,9 @@ * @typedef {import('mdast').Content} Content | ||
/** | ||
* @typedef SafeOptions | ||
* @typedef TrackFields | ||
* @property {Point} now | ||
* @property {number} lineShift | ||
*/ | ||
/** | ||
* @typedef SafeFields | ||
* @property {string} before | ||
@@ -17,2 +24,6 @@ * @property {string} after | ||
/** | ||
* @typedef {TrackFields & SafeFields} SafeOptions | ||
*/ | ||
/** | ||
* @callback Enter | ||
@@ -30,10 +41,10 @@ * @param {string} type | ||
* @typedef Context | ||
* @property {string[]} stack | ||
* @property {Array<string>} stack | ||
* Stack of labels. | ||
* @property {number[]} indexStack | ||
* @property {Array<number>} indexStack | ||
* Positions of children in their parents. | ||
* @property {Enter} enter | ||
* @property {Options} options | ||
* @property {Array.<Unsafe>} unsafe | ||
* @property {Array.<Join>} join | ||
* @property {Array<Unsafe>} unsafe | ||
* @property {Array<Join>} join | ||
* @property {Handle} handle | ||
@@ -72,4 +83,4 @@ * @property {Handlers} handlers | ||
* @property {string} character | ||
* @property {string|Array.<string>} [inConstruct] | ||
* @property {string|Array.<string>} [notInConstruct] | ||
* @property {string|Array<string>} [inConstruct] | ||
* @property {string|Array<string>} [notInConstruct] | ||
* @property {string} [after] | ||
@@ -102,8 +113,8 @@ * @property {string} [before] | ||
* @property {boolean} [tightDefinitions] | ||
* @property {Array.<Options>} [extensions] | ||
* @property {Array<Options>} [extensions] | ||
* @property {Handlers} [handlers] | ||
* @property {Array.<Join>} [join] | ||
* @property {Array.<Unsafe>} [unsafe] | ||
* @property {Array<Join>} [join] | ||
* @property {Array<Unsafe>} [unsafe] | ||
*/ | ||
export {} |
@@ -1,3 +0,3 @@ | ||
/** @type {Array.<Unsafe>} */ | ||
export const unsafe: Array<Unsafe> | ||
export type Unsafe = import('./types.js').Unsafe | ||
/** @type {Array<Unsafe>} */ | ||
export const unsafe: Array<Unsafe>; | ||
export type Unsafe = import('./types.js').Unsafe; |
@@ -20,3 +20,3 @@ /** | ||
/** @type {Array.<Unsafe>} */ | ||
/** @type {Array<Unsafe>} */ | ||
export const unsafe = [ | ||
@@ -23,0 +23,0 @@ {character: '\t', after: '[\\r\\n]', inConstruct: 'phrasing'}, |
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
export function association(node: Association): string | ||
export type Association = import('mdast').Association | ||
export function association(node: Association): string; | ||
export type Association = import('mdast').Association; |
@@ -5,6 +5,4 @@ /** | ||
*/ | ||
export function checkBulletOrderedOther( | ||
context: Context | ||
): Exclude<Options['bulletOrdered'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkBulletOrderedOther(context: Context): Exclude<Options['bulletOrdered'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
export function checkBulletOrdered( | ||
context: Context | ||
): Exclude<Options['bulletOrdered'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkBulletOrdered(context: Context): Exclude<Options['bulletOrdered'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -5,6 +5,4 @@ /** | ||
*/ | ||
export function checkBulletOther( | ||
context: Context | ||
): Exclude<Options['bullet'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkBulletOther(context: Context): Exclude<Options['bullet'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
export function checkBullet( | ||
context: Context | ||
): Exclude<Options['bullet'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkBullet(context: Context): Exclude<Options['bullet'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
export function checkEmphasis( | ||
context: Context | ||
): Exclude<Options['emphasis'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkEmphasis(context: Context): Exclude<Options['emphasis'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
export function checkFence( | ||
context: Context | ||
): Exclude<Options['fence'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkFence(context: Context): Exclude<Options['fence'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
export function checkListItemIndent( | ||
context: Context | ||
): Exclude<Options['listItemIndent'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkListItemIndent(context: Context): Exclude<Options['listItemIndent'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
export function checkQuote( | ||
context: Context | ||
): Exclude<Options['quote'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkQuote(context: Context): Exclude<Options['quote'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
export function checkRuleRepetition( | ||
context: Context | ||
): Exclude<Options['ruleRepetition'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkRuleRepetition(context: Context): Exclude<Options['ruleRepetition'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,4 +9,4 @@ /** | ||
*/ | ||
export function checkRule(context: Context): Exclude<Options['rule'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkRule(context: Context): Exclude<Options['rule'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
export function checkStrong( | ||
context: Context | ||
): Exclude<Options['strong'], undefined> | ||
export type Context = import('../types.js').Context | ||
export type Options = import('../types.js').Options | ||
export function checkStrong(context: Context): Exclude<Options['strong'], undefined>; | ||
export type Context = import('../types.js').Context; | ||
export type Options = import('../types.js').Options; |
/** | ||
* @typedef {import('../types.js').Node} Node | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').Join} Join | ||
* @typedef {import('../types.js').Context} Context | ||
*/ | ||
/** | ||
* @param {Parent} parent | ||
* @param {Context} context | ||
* @param {TrackFields} safeOptions | ||
* @returns {string} | ||
*/ | ||
export function containerFlow(parent: Parent, context: Context): string | ||
export type Node = import('../types.js').Node | ||
export type Parent = import('../types.js').Parent | ||
export type Join = import('../types.js').Join | ||
export type Context = import('../types.js').Context | ||
export function containerFlow(parent: Parent, context: Context, safeOptions: TrackFields): string; | ||
export type Node = import('../types.js').Node; | ||
export type Parent = import('../types.js').Parent; | ||
export type Join = import('../types.js').Join; | ||
export type Context = import('../types.js').Context; | ||
export type TrackFields = import('../types.js').TrackFields; |
@@ -6,13 +6,18 @@ /** | ||
* @typedef {import('../types.js').Context} Context | ||
* @typedef {import('../types.js').TrackFields} TrackFields | ||
*/ | ||
import {track} from './track.js' | ||
/** | ||
* @param {Parent} parent | ||
* @param {Context} context | ||
* @param {TrackFields} safeOptions | ||
* @returns {string} | ||
*/ | ||
export function containerFlow(parent, context) { | ||
export function containerFlow(parent, context, safeOptions) { | ||
const indexStack = context.indexStack | ||
const children = parent.children || [] | ||
/** @type {Array.<string>} */ | ||
const tracker = track(safeOptions) | ||
/** @type {Array<string>} */ | ||
const results = [] | ||
@@ -29,3 +34,9 @@ let index = -1 | ||
results.push( | ||
context.handle(child, parent, context, {before: '\n', after: '\n'}) | ||
tracker.move( | ||
context.handle(child, parent, context, { | ||
before: '\n', | ||
after: '\n', | ||
...tracker.current() | ||
}) | ||
) | ||
) | ||
@@ -38,3 +49,3 @@ | ||
if (index < children.length - 1) { | ||
results.push(between(child, children[index + 1])) | ||
results.push(tracker.move(between(child, children[index + 1]))) | ||
} | ||
@@ -41,0 +52,0 @@ } |
/** | ||
* @typedef {import('../types.js').Node} Node | ||
* @typedef {import('../types.js').Parent} Parent | ||
* @typedef {import('../types.js').SafeOptions} SafeOptions | ||
* @typedef {import('../types.js').Context} Context | ||
*/ | ||
/** | ||
* @param {Parent} parent | ||
@@ -13,10 +7,6 @@ * @param {Context} context | ||
*/ | ||
export function containerPhrasing( | ||
parent: Parent, | ||
context: Context, | ||
safeOptions: SafeOptions | ||
): string | ||
export type Node = import('../types.js').Node | ||
export type Parent = import('../types.js').Parent | ||
export type SafeOptions = import('../types.js').SafeOptions | ||
export type Context = import('../types.js').Context | ||
export function containerPhrasing(parent: Parent, context: Context, safeOptions: SafeOptions): string; | ||
export type Node = import('../types.js').Node; | ||
export type Parent = import('../types.js').Parent; | ||
export type SafeOptions = import('../types.js').SafeOptions; | ||
export type Context = import('../types.js').Context; |
@@ -8,2 +8,4 @@ /** | ||
import {track} from './track.js' | ||
/** | ||
@@ -18,3 +20,3 @@ * @param {Parent} parent | ||
const children = parent.children || [] | ||
/** @type {Array.<string>} */ | ||
/** @type {Array<string>} */ | ||
const results = [] | ||
@@ -25,2 +27,3 @@ let index = -1 | ||
indexStack.push(-1) | ||
let tracker = track(safeOptions) | ||
@@ -41,3 +44,4 @@ while (++index < children.length) { | ||
before: '', | ||
after: '' | ||
after: '', | ||
...tracker.current() | ||
}).charAt(0) | ||
@@ -65,5 +69,17 @@ : '' | ||
before = ' ' | ||
// To do: does this work to reset tracker? | ||
tracker = track(safeOptions) | ||
tracker.move(results.join('')) | ||
} | ||
results.push(context.handle(child, parent, context, {before, after})) | ||
results.push( | ||
tracker.move( | ||
context.handle(child, parent, context, { | ||
...tracker.current(), | ||
before, | ||
after | ||
}) | ||
) | ||
) | ||
@@ -70,0 +86,0 @@ before = results[results.length - 1].slice(-1) |
@@ -10,4 +10,4 @@ /** | ||
*/ | ||
export function formatCodeAsIndented(node: Code, context: Context): boolean | ||
export type Code = import('mdast').Code | ||
export type Context = import('../types.js').Context | ||
export function formatCodeAsIndented(node: Code, context: Context): boolean; | ||
export type Code = import('mdast').Code; | ||
export type Context = import('../types.js').Context; |
@@ -6,4 +6,4 @@ /** | ||
*/ | ||
export function formatHeadingAsSetext(node: Heading, context: Context): boolean | ||
export type Heading = import('mdast').Heading | ||
export type Context = import('../types.js').Context | ||
export function formatHeadingAsSetext(node: Heading, context: Context): boolean; | ||
export type Heading = import('mdast').Heading; | ||
export type Context = import('../types.js').Context; |
@@ -6,4 +6,4 @@ /** | ||
*/ | ||
export function formatLinkAsAutolink(node: Link, context: Context): boolean | ||
export type Link = import('mdast').Link | ||
export type Context = import('../types.js').Context | ||
export function formatLinkAsAutolink(node: Link, context: Context): boolean; | ||
export type Link = import('mdast').Link; | ||
export type Context = import('../types.js').Context; |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export function indentLines(value: string, map: Map): string | ||
export type Map = (value: string, line: number, blank: boolean) => string | ||
export function indentLines(value: string, map: Map): string; | ||
export type Map = (value: string, line: number, blank: boolean) => string; |
@@ -17,3 +17,3 @@ /** | ||
export function indentLines(value, map) { | ||
/** @type {Array.<string>} */ | ||
/** @type {Array<string>} */ | ||
const result = [] | ||
@@ -20,0 +20,0 @@ let start = 0 |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
export function patternCompile(pattern: Unsafe): RegExp | ||
export type Unsafe = import('../types.js').Unsafe | ||
export function patternCompile(pattern: Unsafe): RegExp; | ||
export type Unsafe = import('../types.js').Unsafe; |
@@ -5,7 +5,7 @@ /** | ||
/** | ||
* @param {Array.<string>} stack | ||
* @param {Array<string>} stack | ||
* @param {Unsafe} pattern | ||
* @returns {boolean} | ||
*/ | ||
export function patternInScope(stack: Array<string>, pattern: Unsafe): boolean | ||
export type Unsafe = import('../types.js').Unsafe | ||
export function patternInScope(stack: Array<string>, pattern: Unsafe): boolean; | ||
export type Unsafe = import('../types.js').Unsafe; |
@@ -6,3 +6,3 @@ /** | ||
/** | ||
* @param {Array.<string>} stack | ||
* @param {Array<string>} stack | ||
* @param {Unsafe} pattern | ||
@@ -19,3 +19,3 @@ * @returns {boolean} | ||
/** | ||
* @param {Array.<string>} stack | ||
* @param {Array<string>} stack | ||
* @param {Unsafe['inConstruct']} list | ||
@@ -22,0 +22,0 @@ * @param {boolean} none |
/** | ||
* @param {Context} context | ||
* @param {string|null|undefined} input | ||
* @param {SafeOptions & {encode?: Array.<string>}} config | ||
* @param {SafeOptions & {encode?: Array<string>}} config | ||
* @returns {string} | ||
*/ | ||
export function safe( | ||
context: Context, | ||
input: string | null | undefined, | ||
config: SafeOptions & { | ||
encode?: Array<string> | ||
} | ||
): string | ||
export type Context = import('../types.js').Context | ||
export type SafeOptions = import('../types.js').SafeOptions | ||
export function safe(context: Context, input: string | null | undefined, config: SafeOptions & { | ||
encode?: Array<string>; | ||
}): string; | ||
export type Context = import('../types.js').Context; | ||
export type SafeOptions = import('../types.js').SafeOptions; |
@@ -12,3 +12,3 @@ /** | ||
* @param {string|null|undefined} input | ||
* @param {SafeOptions & {encode?: Array.<string>}} config | ||
* @param {SafeOptions & {encode?: Array<string>}} config | ||
* @returns {string} | ||
@@ -18,5 +18,5 @@ */ | ||
const value = (config.before || '') + (input || '') + (config.after || '') | ||
/** @type {Array.<number>} */ | ||
/** @type {Array<number>} */ | ||
const positions = [] | ||
/** @type {Array.<string>} */ | ||
/** @type {Array<string>} */ | ||
const result = [] | ||
@@ -134,5 +134,5 @@ /** @type {Record<number, {before: boolean, after: boolean}>} */ | ||
const expression = /\\(?=[!-/:-@[-`{-~])/g | ||
/** @type {Array.<number>} */ | ||
/** @type {Array<number>} */ | ||
const positions = [] | ||
/** @type {Array.<string>} */ | ||
/** @type {Array<string>} */ | ||
const results = [] | ||
@@ -139,0 +139,0 @@ const whole = value + after |
{ | ||
"name": "mdast-util-to-markdown", | ||
"version": "1.2.6", | ||
"version": "1.3.0", | ||
"description": "mdast utility to serialize markdown", | ||
@@ -61,3 +61,3 @@ "license": "MIT", | ||
"unist-util-remove-position": "^4.0.0", | ||
"xo": "^0.46.0" | ||
"xo": "^0.47.0" | ||
}, | ||
@@ -83,2 +83,3 @@ "scripts": { | ||
"complexity": "off", | ||
"unicorn/prefer-code-point": "off", | ||
"unicorn/prefer-switch": "off" | ||
@@ -85,0 +86,0 @@ } |
209
readme.md
@@ -11,17 +11,40 @@ # mdast-util-to-markdown | ||
**[mdast][]** utility to parse markdown. | ||
**[mdast][]** utility that turns a syntax tree into markdown. | ||
## When to use this | ||
## Contents | ||
Use this if you have direct access to an AST and need to serialize it. | ||
Use **[remark][]** instead, which includes this, but has a nice interface and | ||
hundreds of plugins. | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`toMarkdown(tree[, options])`](#tomarkdowntree-options) | ||
* [List of extensions](#list-of-extensions) | ||
* [Syntax](#syntax) | ||
* [Syntax tree](#syntax-tree) | ||
* [Types](#types) | ||
* [Security](#security) | ||
* [Related](#related) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## What is this? | ||
This package is a utility that takes an [mdast][] syntax tree as input and turns | ||
it into serialized markdown. | ||
This utility is a low level project. | ||
It’s used in [`remark-stringify`][remark-stringify], which focusses on making it | ||
easier to transform content by abstracting these internals away. | ||
## When should I use this? | ||
If you want to handle syntax trees manually, use this. | ||
For an easier time processing content, use the **[remark][]** ecosystem instead. | ||
## Install | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
[npm][]: | ||
```sh | ||
@@ -31,5 +54,19 @@ npm install mdast-util-to-markdown | ||
In Deno with [Skypack][]: | ||
```js | ||
import {toMarkdown} from 'https://cdn.skypack.dev/mdast-util-to-markdown@1?dts' | ||
``` | ||
In browsers with [Skypack][]: | ||
```html | ||
<script type="module"> | ||
import {toMarkdown} from 'https://cdn.skypack.dev/mdast-util-to-markdown@1?min' | ||
</script> | ||
``` | ||
## Use | ||
Say we have the following script, `example.js`: | ||
Say our module `example.js` looks as follows: | ||
@@ -39,2 +76,3 @@ ```js | ||
/** @type {import('mdast').Root} */ | ||
const tree = { | ||
@@ -66,4 +104,3 @@ type: 'root', | ||
Now, running `node example` yields (note the properly escaped characters which | ||
would otherwise turn into a list and image respectively): | ||
…now running `node example.js` yields: | ||
@@ -77,2 +114,5 @@ ```markdown | ||
> 👉 **Note**: observe the properly escaped characters which would otherwise | ||
> turn into a list and image respectively. | ||
## API | ||
@@ -85,3 +125,3 @@ | ||
Serialize **[mdast][]** to markdown. | ||
Turn an **[mdast][]** syntax tree into markdown. | ||
@@ -147,7 +187,7 @@ ##### Formatting options | ||
Marker to use to serialize emphasis (`'*'` or `'_'`, default: `'*'`). | ||
Marker to use for emphasis (`'*'` or `'_'`, default: `'*'`). | ||
###### `options.fence` | ||
Marker to use to serialize fenced code (``'`'`` or `'~'`, default: ``'`'``). | ||
Marker to use for fenced code (``'`'`` or `'~'`, default: ``'`'``). | ||
@@ -157,26 +197,27 @@ ###### `options.fences` | ||
Whether to use fenced code always (`boolean`, default: `false`). | ||
The default is to fenced code if there is a language defined, if the code is | ||
empty, or if it starts or ends in empty lines. | ||
The default is to use fenced code if there is a language defined, if the code is | ||
empty, or if it starts or ends in blank lines. | ||
###### `options.incrementListMarker` | ||
Whether to increment the value of bullets of items in ordered lists (`boolean`, | ||
default: `true`). | ||
Whether to increment the counter of ordered lists items (`boolean`, default: | ||
`true`). | ||
###### `options.listItemIndent` | ||
Whether to indent the content of list items with the size of the bullet plus one | ||
space (when `'one'`) or a tab stop (`'tab'`), or depending on the item and its | ||
parent list (`'mixed'`, uses `'one'` if the item and list are tight and `'tab'` | ||
otherwise) (`'one'`, `'tab'`, or `'mixed'`, default: `'tab'`). | ||
How to indent the content of list items (`'one'`, `'tab'`, or `'mixed'`, | ||
default: `'tab'`). | ||
Either with the size of the bullet plus one space (when `'one'`), a tab stop | ||
(`'tab'`), or depending on the item and its parent list (`'mixed'`, uses `'one'` | ||
if the item and list are tight and `'tab'` otherwise). | ||
###### `options.quote` | ||
Marker to use to serialize titles (`'"'` or `"'"`, default: `'"'`). | ||
Marker to use for titles (`'"'` or `"'"`, default: `'"'`). | ||
###### `options.resourceLink` | ||
Whether to use resource links (`[text](url)`) always (`boolean`, default: | ||
`false`). | ||
The default is to use autolinks (`<https://example.com>`) when possible. | ||
Whether to always use resource links (`boolean`, default: `false`). | ||
The default is to use autolinks (`<https://example.com>`) when possible | ||
and resource links (`[text](url)`) otherwise. | ||
@@ -189,4 +230,3 @@ ###### `options.rule` | ||
Number of markers to use for thematic breaks (`number`, default: | ||
`3`, min: `3`). | ||
Number of markers to use for thematic breaks (`number`, default: `3`, min: `3`). | ||
@@ -201,16 +241,19 @@ ###### `options.ruleSpaces` | ||
Whether to use setext headings when possible (`boolean`, default: `false`). | ||
Setext headings are not possible for headings with a rank more than 2 or when | ||
they’re empty. | ||
The default is to always use ATX headings (`# heading`) instead of setext | ||
headings (`heading\n=======`). | ||
Setext headings can’t be used for empty headings or headings with a rank of | ||
three or more. | ||
###### `options.strong` | ||
Marker to use to serialize strong (`'*'` or `'_'`, default: `'*'`). | ||
Marker to use for strong (`'*'` or `'_'`, default: `'*'`). | ||
###### `options.tightDefinitions` | ||
Whether to join definitions w/o a blank line (`boolean`, default: `false`). | ||
Shortcut for a join function like so: | ||
Whether to join definitions without a blank line (`boolean`, default: `false`). | ||
The default is to add blank lines between any flow (“block”) construct. | ||
Turning this option on is a shortcut for a join function like so: | ||
```js | ||
function (left, right) { | ||
function joinTightDefinitions(left, right) { | ||
if (left.type === 'definition' && right.type === 'definition') { | ||
@@ -224,14 +267,19 @@ return 0 | ||
Object mapping node types to custom handlers. | ||
Object mapping node types to custom handlers (`Record<string, Handle>`, default: | ||
`{}`). | ||
Useful for syntax extensions. | ||
Take a look at [`lib/handle`][handlers] for examples. | ||
This option is a bit advanced. | ||
It’s recommended to look at the code in [`lib/handle/`][handlers] for examples. | ||
###### `options.join` | ||
List of functions used to determine what to place between two flow nodes. | ||
Often, they are joined by one blank line. | ||
In certain cases, it’s nicer to have them next to each other. | ||
Or, they can’t occur together. | ||
These functions receive two adjacent nodes and their parent and can return | ||
`number` or `boolean`, referring to how many blank lines to use between them. | ||
List of functions used to determine what to place between two flow nodes | ||
(`Array<Join>`, default: `[]`). | ||
“Blocks” are typically joined by one blank line. | ||
Sometimes it’s nicer to have them flush next to each other, yet other times | ||
they can’t occur together at all. | ||
Join functions receive two adjacent siblings and their parent and can return | ||
`number` or `boolean`, to signal how many blank lines to use between them. | ||
A return value of `true` is as passing `1`. | ||
@@ -252,6 +300,8 @@ A return value of `false` means the nodes cannot be joined by a blank line, such | ||
List of patterns to escape. | ||
List of patterns to escape (`Array<Unsafe>`). | ||
Useful for syntax extensions. | ||
Take a look at [`lib/unsafe.js`][unsafe] for examples. | ||
This option is quite advanced. | ||
It’s recommended to look at the code in [`lib/unsafe.js`][unsafe] for examples. | ||
##### Extension options | ||
@@ -261,3 +311,3 @@ | ||
List of extensions (`Array.<ToMarkdownExtension>`). | ||
List of extensions (`Array<ToMarkdownExtension>`, default: `[]`). | ||
Each `ToMarkdownExtension` is an object with the same interface as `options` | ||
@@ -268,3 +318,3 @@ here. | ||
`string` — Serialized markdown. | ||
Serialized markdown (`string`). | ||
@@ -274,28 +324,45 @@ ## List of extensions | ||
* [`syntax-tree/mdast-util-directive`](https://github.com/syntax-tree/mdast-util-directive) | ||
— serialize directives | ||
— directives | ||
* [`syntax-tree/mdast-util-frontmatter`](https://github.com/syntax-tree/mdast-util-frontmatter) | ||
— serialize frontmatter (YAML, TOML, more) | ||
— frontmatter (YAML, TOML, more) | ||
* [`syntax-tree/mdast-util-gfm`](https://github.com/syntax-tree/mdast-util-gfm) | ||
— serialize GFM | ||
— GFM | ||
* [`syntax-tree/mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal) | ||
— serialize GFM autolink literals | ||
— GFM autolink literals | ||
* [`syntax-tree/mdast-util-gfm-footnote`](https://github.com/syntax-tree/mdast-util-gfm-footnote) | ||
— serialize GFM footnotes | ||
— GFM footnotes | ||
* [`syntax-tree/mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough) | ||
— serialize GFM strikethrough | ||
— GFM strikethrough | ||
* [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table) | ||
— serialize GFM tables | ||
— GFM tables | ||
* [`syntax-tree/mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item) | ||
— serialize GFM task list items | ||
— GFM task list items | ||
* [`syntax-tree/mdast-util-math`](https://github.com/syntax-tree/mdast-util-math) | ||
— serialize math | ||
— math | ||
* [`syntax-tree/mdast-util-mdx`](https://github.com/syntax-tree/mdast-util-mdx) | ||
— serialize MDX or MDX.js | ||
— MDX | ||
* [`syntax-tree/mdast-util-mdx-expression`](https://github.com/syntax-tree/mdast-util-mdx-expression) | ||
— serialize MDX or MDX.js expressions | ||
— MDX expressions | ||
* [`syntax-tree/mdast-util-mdx-jsx`](https://github.com/syntax-tree/mdast-util-mdx-jsx) | ||
— serialize MDX or MDX.js JSX | ||
— MDX JSX | ||
* [`syntax-tree/mdast-util-mdxjs-esm`](https://github.com/syntax-tree/mdast-util-mdxjs-esm) | ||
— serialize MDX.js ESM | ||
— MDX ESM | ||
## Syntax | ||
Markdown is serialized according to CommonMark but care is taken to format in | ||
such a way that the resulting markdown should work with most markdown parsers. | ||
Extensions can add support for custom syntax. | ||
## Syntax tree | ||
The syntax tree is [mdast][]. | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
It exports the types `Options`, `Map`, `Unsafe`, `Join`, `Handlers`, `Handle`, | ||
`Context`, `SafeOptions`, which model the interfaces used by options and | ||
extensions. | ||
## Security | ||
@@ -308,16 +375,16 @@ | ||
As Markdown is sometimes used for HTML, and improper use of HTML can open you up | ||
As markdown is sometimes used for HTML, and improper use of HTML can open you up | ||
to a [cross-site scripting (XSS)][xss] attack, use of `mdast-util-to-markdown` | ||
and parsing it again later could potentially be unsafe. | ||
When parsing markdown afterwards and then going to HTML, use something like | ||
[`hast-util-sanitize`][sanitize] to make the tree safe. | ||
[`hast-util-sanitize`][hast-util-sanitize] to make the tree safe. | ||
## Related | ||
* [`syntax-tree/mdast-util-from-markdown`](https://github.com/syntax-tree/mdast-util-from-markdown) | ||
— parse markdown to mdast | ||
* [`micromark/micromark`](https://github.com/micromark/micromark) | ||
— the smallest commonmark-compliant markdown parser that exists | ||
— parse markdown | ||
* [`remarkjs/remark`](https://github.com/remarkjs/remark) | ||
— markdown processor powered by plugins | ||
* [`syntax-tree/mdast-util-from-markdown`](https://github.com/syntax-tree/mdast-util-from-markdown) | ||
— parse markdown to mdast | ||
— process markdown | ||
@@ -368,2 +435,4 @@ ## Contribute | ||
[skypack]: https://www.skypack.dev | ||
[license]: license | ||
@@ -379,2 +448,6 @@ | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[typescript]: https://www.typescriptlang.org | ||
[mdast]: https://github.com/syntax-tree/mdast | ||
@@ -384,3 +457,3 @@ | ||
[sanitize]: https://github.com/syntax-tree/hast-util-sanitize | ||
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize | ||
@@ -392,1 +465,3 @@ [handlers]: lib/handle | ||
[remark]: https://github.com/remarkjs/remark | ||
[remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify |
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
102139
99
2748
448