the editable site (validation-lab)

This commit is contained in:
kpgarrod committed 2026-11-21 08:03:55 +01:00
commit 3ac81d5a52
13454 files changed
+2227005

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
export type {
AttentionInfo,
Attention,
ConstructNameMap,
ConstructName,
Handle,
Handlers,
Info,
Join,
Map,
Options,
SafeConfig,
State,
Tracker,
Unsafe
} from './lib/types.js'
export {toMarkdown} from './lib/index.js'
export {handle as defaultHandlers} from './lib/handle/index.js'
+3
View File
@@ -0,0 +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'
+14
View File
@@ -0,0 +1,14 @@
/**
* Configure a base state w/ an extension.
*
* @param {State} base
* Base state to configure.
* @param {Options} extension
* Extension to apply.
* @returns {State}
* Given `base`.
*/
export function configure(base: State, extension: Options): State;
import type { State } from './types.js';
import type { Options } from './types.js';
//# sourceMappingURL=configure.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["configure.js"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,gCAPW,KAAK,aAEL,OAAO,GAEL,KAAK,CAgDjB;2BA5DgC,YAAY;6BAAZ,YAAY"}
+98
View File
@@ -0,0 +1,98 @@
/**
* @import {Options, State} from './types.js'
*/
const own = {}.hasOwnProperty
/**
* Configure a base state w/ an extension.
*
* @param {State} base
* Base state to configure.
* @param {Options} extension
* Extension to apply.
* @returns {State}
* Given `base`.
*/
export function configure(base, extension) {
let index = -1
/** @type {keyof Options} */
let key
// First do subextensions.
if (extension.extensions) {
while (++index < extension.extensions.length) {
configure(base, extension.extensions[index])
}
}
for (key in extension) {
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]
}
}
}
}
return base
}
/**
* Merge arrays from the extension into the base state.
*
* @template T
* Kind.
* @param {Array<T>} left
* List to merge into.
* @param {Array<T> | null | undefined} right
* List to merge from.
* @returns {undefined}
* Nothing.
*/
function list(left, right) {
if (right) {
left.push(...right)
}
}
/**
* Merge objects from the extension into the base state.
*
* @template T
* Kind.
* @param {Record<string, T>} left
* Object to merge into.
* @param {Record<string, T> | null | undefined} right
* Object to merge from.
* @returns {undefined}
* Nothing.
*/
function map(left, right) {
if (right) {
Object.assign(left, right)
}
}
+24
View File
@@ -0,0 +1,24 @@
/**
* @import {Blockquote, Parents} from 'mdast'
* @import {Info, Map, State} from 'mdast-util-to-markdown'
*/
/**
* Serialize a blockquote node.
*
* @param {Blockquote} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function blockquote(node: Blockquote, _: Parents | undefined, state: State, info: Info): string;
import type { Blockquote } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=blockquote.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["blockquote.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AACH,iCAXW,UAAU,KAEV,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAclB;gCA7BqC,OAAO;6BAAP,OAAO;2BACV,wBAAwB;0BAAxB,wBAAwB"}
+40
View File
@@ -0,0 +1,40 @@
/**
* @import {Blockquote, Parents} from 'mdast'
* @import {Info, Map, State} from 'mdast-util-to-markdown'
*/
/**
* Serialize a blockquote node.
*
* @param {Blockquote} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function blockquote(node, _, state, info) {
const exit = state.enter('blockquote')
const tracker = state.createTracker(info)
tracker.move('> ')
tracker.shift(2)
const value = state.indentLines(
state.containerFlow(node, tracker.current()),
map
)
exit()
return value
}
/**
* Indent lines w/ blockquote markers.
*
* @type {Map}
*/
function map(line, _, blank) {
return '>' + (blank ? '' : ' ') + line
}
+20
View File
@@ -0,0 +1,20 @@
/**
* Serialize a break node.
*
* @param {Break} _
* Node to serialize.
* @param {Parents | undefined} _1
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function hardBreak(_: Break, _1: Parents | undefined, state: State, info: Info): string;
import type { Break } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=break.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"break.d.ts","sourceRoot":"","sources":["break.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,6BAXW,KAAK,MAEL,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAsBlB;2BAvCgC,OAAO;6BAAP,OAAO;2BACV,wBAAwB;0BAAxB,wBAAwB"}
+41
View File
@@ -0,0 +1,41 @@
/**
* @import {Break, Parents} from 'mdast'
* @import {Info, State} from 'mdast-util-to-markdown'
*/
import {patternInScope} from '../util/pattern-in-scope.js'
/**
* Serialize a break node.
*
* @param {Break} _
* Node to serialize.
* @param {Parents | undefined} _1
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function hardBreak(_, _1, state, info) {
let index = -1
while (++index < state.unsafe.length) {
const pattern = state.unsafe[index]
// If we can’t put unconditional eols in this construct (setext headings,
// tables), use a space instead.
if (
pattern.character === '\n' &&
!pattern.before &&
!pattern.after &&
patternInScope(state.stack, pattern)
) {
return /[\t ]/.test(info.before) ? '' : ' '
}
}
return '\\\n'
}
+20
View File
@@ -0,0 +1,20 @@
/**
* Serialize a code node.
*
* @param {Code} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function code(node: Code, _: Parents | undefined, state: State, info: Info): string;
import type { Code } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=code.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["code.js"],"names":[],"mappings":"AASA;;;;;;;;;;;;;GAaG;AACH,2BAXW,IAAI,KAEJ,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAwDlB;0BA1E+B,OAAO;6BAAP,OAAO;2BADJ,wBAAwB;0BAAxB,wBAAwB"}
+86
View File
@@ -0,0 +1,86 @@
/**
* @import {Info, Map, State} from 'mdast-util-to-markdown'
* @import {Code, Parents} from 'mdast'
*/
import {longestStreak} from 'longest-streak'
import {formatCodeAsIndented} from '../util/format-code-as-indented.js'
import {checkFence} from '../util/check-fence.js'
/**
* Serialize a code node.
*
* @param {Code} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function code(node, _, state, info) {
const marker = checkFence(state)
const raw = node.value || ''
if (formatCodeAsIndented(node, state)) {
const exit = state.enter('codeIndented')
const value = state.indentLines(raw, map)
exit()
return value
}
const tracker = state.createTracker(info)
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3))
const exit = state.enter('codeFenced')
const suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
let value = tracker.move(sequence)
if (node.lang) {
const subexit = state.enter(`codeFencedLang${suffix}`)
value += tracker.move(
state.safe(node.lang, {
before: value,
after: ' ',
encode: ['`'],
...tracker.current()
})
)
subexit()
}
if (node.lang && node.meta) {
const subexit = state.enter(`codeFencedMeta${suffix}`)
value += tracker.move(' ')
value += tracker.move(
state.safe(node.meta, {
before: value,
after: '\n',
encode: ['`'],
...tracker.current()
})
)
subexit()
}
value += tracker.move('\n')
if (raw) {
value += tracker.move(raw + '\n')
}
value += tracker.move(sequence)
exit()
return value
}
/**
* Indent lines w/ code indent.
*
* @type {Map}
*/
function map(line, _, blank) {
return (blank ? '' : ' ') + line
}
+20
View File
@@ -0,0 +1,20 @@
/**
* Serialize a definition node.
*
* @param {Definition} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function definition(node: Definition, _: Parents | undefined, state: State, info: Info): string;
import type { Definition } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=definition.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["definition.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,iCAXW,UAAU,KAEV,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAgElB;gCAhFqC,OAAO;6BAAP,OAAO;2BADf,wBAAwB;0BAAxB,wBAAwB"}
+83
View File
@@ -0,0 +1,83 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Definition, Parents} from 'mdast'
*/
import {checkQuote} from '../util/check-quote.js'
/**
* Serialize a definition node.
*
* @param {Definition} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function definition(node, _, state, info) {
const quote = checkQuote(state)
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
const exit = state.enter('definition')
let subexit = state.enter('label')
const tracker = state.createTracker(info)
let value = tracker.move('[')
value += tracker.move(
state.safe(state.associationId(node), {
before: value,
after: ']',
...tracker.current()
})
)
value += tracker.move(']: ')
subexit()
if (
// If there’s no url, or…
!node.url ||
// If there are control characters, whitespace, or a leading `<`.
/^<|[\0- \u007F]/.test(node.url)
) {
subexit = state.enter('destinationLiteral')
value += tracker.move('<')
value += tracker.move(
state.safe(node.url, {before: value, after: '>', ...tracker.current()})
)
value += tracker.move('>')
} else {
// No whitespace, raw is prettier.
subexit = state.enter('destinationRaw')
value += tracker.move(
state.safe(node.url, {
before: value,
after: node.title ? ' ' : '\n',
...tracker.current()
})
)
}
subexit()
if (node.title) {
subexit = state.enter(`title${suffix}`)
value += tracker.move(' ' + quote)
value += tracker.move(
state.safe(node.title, {
before: value,
after: quote,
...tracker.current()
})
)
value += tracker.move(quote)
subexit()
}
exit()
return value
}
+52
View File
@@ -0,0 +1,52 @@
/**
* Serialize an emphasis node.
*
* Attention is properly handled by `containerPhrasing`.
*
* @param {Emphasis} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function emphasis(node: Emphasis, _: Parents | undefined, state: State, info: Info): string;
export namespace emphasis {
export { attention };
export { peek };
}
import type { Emphasis } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
/**
* Serialize an emphasis node as attention.
*
* @param {Emphasis} _
* Node to serialize.
* @param {State} state
* Info passed around.
* @returns {AttentionInfo}
* Info on how to serialize the node.
*/
declare function attention(_: Emphasis, state: State): AttentionInfo;
/**
* Peek at this node.
*
* @param {Emphasis} _
* Node to serialize.
* @param {Parents | undefined} _1
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Start of the serialized markdown.
*/
declare function peek(_: Emphasis, _1: Parents | undefined, state: State): string;
import type { AttentionInfo } from 'mdast-util-to-markdown';
export {};
//# sourceMappingURL=emphasis.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["emphasis.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;GAeG;AACH,+BAXW,QAAQ,KAER,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CASlB;;;;;8BA/BmC,OAAO;6BAAP,OAAO;2BADE,wBAAwB;0BAAxB,wBAAwB;AAkCrE;;;;;;;;;GASG;AACH,8BAPW,QAAQ,SAER,KAAK,GAEH,aAAa,CAUzB;AAED;;;;;;;;;;;GAWG;AACH,yBATW,QAAQ,MAER,OAAO,GAAG,SAAS,SAEnB,KAAK,GAEH,MAAM,CAKlB;mCAnE4C,wBAAwB"}
+69
View File
@@ -0,0 +1,69 @@
/**
* @import {AttentionInfo, Info, State} from 'mdast-util-to-markdown'
* @import {Emphasis, Parents} from 'mdast'
*/
import {checkEmphasis} from '../util/check-emphasis.js'
import {attentionItem, serialize} from '../util/container-phrasing.js'
emphasis.attention = attention
emphasis.peek = peek
/**
* Serialize an emphasis node.
*
* Attention is properly handled by `containerPhrasing`.
*
* @param {Emphasis} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function emphasis(node, _, state, info) {
const exit = state.enter('phrasing')
const item = attentionItem(node, attention, state, state.createTracker(info))
const value = item ? serialize([item], info.before, info.after) : ''
exit()
return value
}
/**
* Serialize an emphasis node as attention.
*
* @param {Emphasis} _
* Node to serialize.
* @param {State} state
* Info passed around.
* @returns {AttentionInfo}
* Info on how to serialize the node.
*/
function attention(_, state) {
const marker = checkEmphasis(state)
return {
construct: 'emphasis',
markers: marker === '*' ? ['*', '_'] : ['_', '*'],
sizes: [1]
}
}
/**
* Peek at this node.
*
* @param {Emphasis} _
* Node to serialize.
* @param {Parents | undefined} _1
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Start of the serialized markdown.
*/
function peek(_, _1, state) {
return state.options.emphasis || '*'
}
+20
View File
@@ -0,0 +1,20 @@
/**
* Serialize a heading node.
*
* @param {Heading} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function heading(node: Heading, _: Parents | undefined, state: State, info: Info): string;
import type { Heading } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=heading.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["heading.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;GAaG;AACH,8BAXW,OAAO,KAEP,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAgElB;6BAjFkC,OAAO;6BAAP,OAAO;2BADZ,wBAAwB;0BAAxB,wBAAwB"}
+84
View File
@@ -0,0 +1,84 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Heading, Parents} from 'mdast'
*/
import {encodeCharacterReference} from '../util/encode-character-reference.js'
import {formatHeadingAsSetext} from '../util/format-heading-as-setext.js'
/**
* Serialize a heading node.
*
* @param {Heading} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function heading(node, _, state, info) {
const rank = Math.max(Math.min(6, node.depth || 1), 1)
const tracker = state.createTracker(info)
if (formatHeadingAsSetext(node, state)) {
const exit = state.enter('headingSetext')
const subexit = state.enter('phrasing')
const value = state.containerPhrasing(node, {
...tracker.current(),
before: '\n',
after: '\n'
})
subexit()
exit()
return (
value +
'\n' +
(rank === 1 ? '=' : '-').repeat(
// The whole size…
value.length -
// Minus the position of the character after the last EOL (or
// 0 if there is none)…
(Math.max(value.lastIndexOf('\r'), value.lastIndexOf('\n')) + 1)
)
)
}
const sequence = '#'.repeat(rank)
const exit = state.enter('headingAtx')
const subexit = state.enter('phrasing')
// 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 = state.containerPhrasing(node, {
before: '# ',
after: '\n',
...tracker.current()
})
const head = value.charCodeAt(0)
if (head === 9 /* `\t` */ || head === 32 /* ` ` */) {
// To do: what effect has the character reference on tracking?
value = encodeCharacterReference(head) + value.slice(1)
}
value = value ? sequence + ' ' + value : sequence
if (state.options.closeAtx) {
value += ' ' + sequence
}
subexit()
exit()
return value
}
+22
View File
@@ -0,0 +1,22 @@
/**
* Serialize an HTML node.
*
* @param {Html} node
* Node to serialize.
* @returns {string}
* Serialized markdown.
*/
export function html(node: Html): string;
export namespace html {
export { htmlPeek as peek };
}
import type { Html } from 'mdast';
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
declare function htmlPeek(): string;
export {};
//# sourceMappingURL=html.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["html.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,2BALW,IAAI,GAEF,MAAM,CAKlB;;;;0BAfsB,OAAO;AAiB9B;;;;;GAKG;AACH,6BAHa,MAAM,CAKlB"}
+27
View File
@@ -0,0 +1,27 @@
/**
* @import {Html} from 'mdast'
*/
html.peek = htmlPeek
/**
* Serialize an HTML node.
*
* @param {Html} node
* Node to serialize.
* @returns {string}
* Serialized markdown.
*/
export function html(node) {
return node.value || ''
}
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
function htmlPeek() {
return '<'
}
+31
View File
@@ -0,0 +1,31 @@
/**
* Serialize an image reference node.
*
* @param {ImageReference} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function imageReference(node: ImageReference, _: Parents | undefined, state: State, info: Info): string;
export namespace imageReference {
export { imageReferencePeek as peek };
}
import type { ImageReference } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
declare function imageReferencePeek(): string;
export {};
//# sourceMappingURL=image-reference.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"image-reference.d.ts","sourceRoot":"","sources":["image-reference.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,qCAXW,cAAc,KAEd,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAiDlB;;;;oCAjEyC,OAAO;6BAAP,OAAO;2BADnB,wBAAwB;0BAAxB,wBAAwB;AAoEtD;;;;;GAKG;AACH,uCAHa,MAAM,CAKlB"}
+78
View File
@@ -0,0 +1,78 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {ImageReference, Parents} from 'mdast'
*/
imageReference.peek = imageReferencePeek
/**
* Serialize an image reference node.
*
* @param {ImageReference} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function imageReference(node, _, state, info) {
const type = node.referenceType
const exit = state.enter('imageReference')
let subexit = state.enter('label')
const tracker = state.createTracker(info)
let value = tracker.move('![')
const alt = state.safe(node.alt, {
before: value,
after: ']',
...tracker.current()
})
value += tracker.move(alt + '][')
subexit()
// Hide that we’re in phrasing as things like attention or code cannot form
// in references.
// Character escapes and references *do* work.
// It is important to know about other constructs, such as table cells.
const stack = state.stack
state.stack = stack.filter(function (d) {
return d !== 'phrasing'
})
subexit = state.enter('reference')
// 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 = state.safe(state.associationId(node), {
before: value,
after: ']',
...tracker.current()
})
subexit()
state.stack = stack
exit()
if (type === 'full' || !alt || alt !== reference) {
value += tracker.move(reference + ']')
} else if (type === 'shortcut') {
// Remove the unwanted `[`.
value = value.slice(0, -1)
} else {
value += tracker.move(']')
}
return value
}
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
function imageReferencePeek() {
return '!'
}
+31
View File
@@ -0,0 +1,31 @@
/**
* Serialize an image node.
*
* @param {Image} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function image(node: Image, _: Parents | undefined, state: State, info: Info): string;
export namespace image {
export { imagePeek as peek };
}
import type { Image } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
declare function imagePeek(): string;
export {};
//# sourceMappingURL=image.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["image.js"],"names":[],"mappings":"AASA;;;;;;;;;;;;;GAaG;AACH,4BAXW,KAAK,KAEL,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CA6DlB;;;;2BA/EgC,OAAO;6BAAP,OAAO;2BADV,wBAAwB;0BAAxB,wBAAwB;AAkFtD;;;;;GAKG;AACH,8BAHa,MAAM,CAKlB"}
+92
View File
@@ -0,0 +1,92 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Image, Parents} from 'mdast'
*/
import {checkQuote} from '../util/check-quote.js'
image.peek = imagePeek
/**
* Serialize an image node.
*
* @param {Image} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function image(node, _, state, info) {
const quote = checkQuote(state)
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
const exit = state.enter('image')
let subexit = state.enter('label')
const tracker = state.createTracker(info)
let value = tracker.move('![')
value += tracker.move(
state.safe(node.alt, {before: value, after: ']', ...tracker.current()})
)
value += tracker.move('](')
subexit()
if (
// If there’s no url but there is a title…
(!node.url && node.title) ||
// If there are control characters, whitespace, or a leading `<`.
/^<|[\0- \u007F]/.test(node.url)
) {
subexit = state.enter('destinationLiteral')
value += tracker.move('<')
value += tracker.move(
state.safe(node.url, {before: value, after: '>', ...tracker.current()})
)
value += tracker.move('>')
} else {
// No whitespace, raw is prettier.
subexit = state.enter('destinationRaw')
value += tracker.move(
state.safe(node.url, {
before: value,
after: node.title ? ' ' : ')',
...tracker.current()
})
)
}
subexit()
if (node.title) {
subexit = state.enter(`title${suffix}`)
value += tracker.move(' ' + quote)
value += tracker.move(
state.safe(node.title, {
before: value,
after: quote,
...tracker.current()
})
)
value += tracker.move(quote)
subexit()
}
value += tracker.move(')')
exit()
return value
}
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
function imagePeek() {
return '!'
}
+42
View File
@@ -0,0 +1,42 @@
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 };
}
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';
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;2BAAyB,iBAAiB;0BAClB,YAAY;qBACjB,WAAW;2BACL,iBAAiB;yBACnB,eAAe;wBAChB,cAAc;qBACjB,WAAW;sBACV,YAAY;+BACH,sBAAsB;2BAC1B,kBAAkB;qBACxB,WAAW;8BACF,qBAAqB;qBAC9B,WAAW;yBACP,gBAAgB;0BACf,gBAAgB;qBACrB,WAAW;uBACT,aAAa;qBACf,WAAW;8BACF,qBAAqB"}
+45
View File
@@ -0,0 +1,45 @@
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'
/**
* Default (CommonMark) handlers.
*/
export const handle = {
blockquote,
break: hardBreak,
code,
definition,
emphasis,
hardBreak,
heading,
html,
image,
imageReference,
inlineCode,
link,
linkReference,
list,
listItem,
paragraph,
root,
strong,
text,
thematicBreak
}
+28
View File
@@ -0,0 +1,28 @@
/**
* Serialize an inline code node.
*
* @param {InlineCode} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Serialized markdown.
*/
export function inlineCode(node: InlineCode, _: Parents | undefined, state: State): string;
export namespace inlineCode {
export { inlineCodePeek as peek };
}
import type { InlineCode } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
declare function inlineCodePeek(): string;
export {};
//# sourceMappingURL=inline-code.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"inline-code.d.ts","sourceRoot":"","sources":["inline-code.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,iCATW,UAAU,KAEV,OAAO,GAAG,SAAS,SAEnB,KAAK,GAEH,MAAM,CA2DlB;;;;gCAzEqC,OAAO;6BAAP,OAAO;2BADrB,wBAAwB;AA4EhD;;;;;GAKG;AACH,mCAHa,MAAM,CAKlB"}
+86
View File
@@ -0,0 +1,86 @@
/**
* @import {State} from 'mdast-util-to-markdown'
* @import {InlineCode, Parents} from 'mdast'
*/
inlineCode.peek = inlineCodePeek
/**
* Serialize an inline code node.
*
* @param {InlineCode} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Serialized markdown.
*/
export function inlineCode(node, _, state) {
let value = node.value || ''
let sequence = '`'
let index = -1
// If there is a single grave accent on its own in the code, use a fence of
// two.
// If there are two in a row, use one.
while (new RegExp('(^|[^`])' + sequence + '([^`]|$)').test(value)) {
sequence += '`'
}
// If this is not just spaces or eols (tabs don’t count), and either the
// first or last character are a space, eol, or tick, then pad with spaces.
if (
/[^\n\r ]/.test(value) &&
((/^[\n\r ]/.test(value) && /[\n\r ]$/.test(value)) || /^`|`$/.test(value))
) {
value = ' ' + value + ' '
}
// We have a potential problem: certain characters after eols could result in
// blocks being seen.
// For example, if someone injected the string `'\n# b'`, then that would
// result in an ATX heading.
// We can’t escape characters in `inlineCode`, but because eols are
// transformed to spaces when going from markdown to HTML anyway, we can swap
// them out.
while (++index < state.unsafe.length) {
const pattern = state.unsafe[index]
const expression = state.compilePattern(pattern)
// Only look for `atBreak`s.
// Btw: note that `atBreak` patterns will always start the regex at LF or
// CR.
if (!pattern.atBreak) continue
/** @type {RegExpExecArray | null} */
let match
while ((match = expression.exec(value))) {
let position = match.index
// Support CRLF (patterns only look for one of the characters).
if (
value.charCodeAt(position) === 10 /* `\n` */ &&
value.charCodeAt(position - 1) === 13 /* `\r` */
) {
position--
}
value = value.slice(0, position) + ' ' + value.slice(match.index + 1)
}
}
return sequence + value + sequence
}
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
function inlineCodePeek() {
return '`'
}
+31
View File
@@ -0,0 +1,31 @@
/**
* Serialize a link reference node.
*
* @param {LinkReference} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function linkReference(node: LinkReference, _: Parents | undefined, state: State, info: Info): string;
export namespace linkReference {
export { linkReferencePeek as peek };
}
import type { LinkReference } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
declare function linkReferencePeek(): string;
export {};
//# sourceMappingURL=link-reference.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"link-reference.d.ts","sourceRoot":"","sources":["link-reference.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,oCAXW,aAAa,KAEb,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAiDlB;;;;mCAjEwC,OAAO;6BAAP,OAAO;2BADlB,wBAAwB;0BAAxB,wBAAwB;AAoEtD;;;;;GAKG;AACH,sCAHa,MAAM,CAKlB"}
+78
View File
@@ -0,0 +1,78 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {LinkReference, Parents} from 'mdast'
*/
linkReference.peek = linkReferencePeek
/**
* Serialize a link reference node.
*
* @param {LinkReference} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function linkReference(node, _, state, info) {
const type = node.referenceType
const exit = state.enter('linkReference')
let subexit = state.enter('label')
const tracker = state.createTracker(info)
let value = tracker.move('[')
const text = state.containerPhrasing(node, {
before: value,
after: ']',
...tracker.current()
})
value += tracker.move(text + '][')
subexit()
// Hide that we’re in phrasing as things like attention or code cannot form
// in references.
// Character escapes and references *do* work.
// It is important to know about other constructs, such as table cells.
const stack = state.stack
state.stack = stack.filter(function (d) {
return d !== 'phrasing'
})
subexit = state.enter('reference')
// 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 = state.safe(state.associationId(node), {
before: value,
after: ']',
...tracker.current()
})
subexit()
state.stack = stack
exit()
if (type === 'full' || !text || text !== reference) {
value += tracker.move(reference + ']')
} else if (type === 'shortcut') {
// Remove the unwanted `[`.
value = value.slice(0, -1)
} else {
value += tracker.move(']')
}
return value
}
/**
* Peek at this node.
*
* @returns {string}
* Start of the serialized markdown.
*/
function linkReferencePeek() {
return '['
}
+37
View File
@@ -0,0 +1,37 @@
/**
* Serialize a link node.
*
* @param {Link} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function link(node: Link, _: Parents | undefined, state: State, info: Info): string;
export namespace link {
export { linkPeek as peek };
}
import type { Link } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
/**
* Peek at this node.
*
* @param {Link} node
* Node to peek at.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Start of the serialized markdown.
*/
declare function linkPeek(node: Link, _: Parents | undefined, state: State): string;
export {};
//# sourceMappingURL=link.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;GAaG;AACH,2BAXW,IAAI,KAEJ,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CA6HlB;;;;0BAjJ+B,OAAO;6BAAP,OAAO;2BADT,wBAAwB;0BAAxB,wBAAwB;AAoJtD;;;;;;;;;;;GAWG;AACH,gCATW,IAAI,KAEJ,OAAO,GAAG,SAAS,SAEnB,KAAK,GAEH,MAAM,CAKlB"}
+164
View File
@@ -0,0 +1,164 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Link, Parents} from 'mdast'
* @import {Exit} from '../types.js'
*/
import {checkQuote} from '../util/check-quote.js'
import {formatLinkAsAutolink} from '../util/format-link-as-autolink.js'
link.peek = linkPeek
/**
* Serialize a link node.
*
* @param {Link} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function link(node, _, state, info) {
const quote = checkQuote(state)
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
const tracker = state.createTracker(info)
if (formatLinkAsAutolink(node, state)) {
// Hide that we’re in phrasing as things like attention or code cannot form
// in autolinks.
// Character escapes also don’t work (nor character references),
// but that is a different matter, which `safe.js` handles for `autolink`.
// It is important to know about other constructs, such as table cells.
const stack = state.stack
state.stack = stack.filter(function (d) {
return d !== 'phrasing'
})
const exit = state.enter('autolink')
let value = tracker.move('<')
value += tracker.move(
state.containerPhrasing(node, {
before: value,
after: '>',
...tracker.current()
})
)
value += tracker.move('>')
exit()
state.stack = stack
return value
}
const exit = state.enter('link')
let subexit = state.enter('label')
let value = tracker.move('[')
const text = state.containerPhrasing(node, {
before: value,
after: '](',
...tracker.current()
})
value += tracker.move(text)
subexit()
value += tracker.move('](')
// A link could accidentally turn into a definition in certain contexts:
// at the start of a line, without title, when its text has a `]` that
// cannot be escaped (such as in code).
//
// We can prevent that with an empty title:
//
// ```
// [`a]:`](b)
// ```
//
// …is a definition with `` `](b) `` as its destination.
//
// Using:
//
// ```
// [`a]:`](b "")
// ```
//
// …instead fixes it.
//
// Control characters, whitespace, or a leading `<` in the url need an
// enclosed destination, which also prevents this.
const enclose = /^<|[\0- \u007F]/.test(node.url)
const last = info.before.charAt(info.before.length - 1)
let title = node.title || undefined
if (!title && !enclose && (last === '\n' || last === '\r')) {
let index = 0
while (index < text.length && text.charCodeAt(index) !== 93 /* `]` */) {
index += text.charCodeAt(index) === 92 /* `\` */ ? 2 : 1
}
if (text.charCodeAt(index + 1) === 58 /* `:` */) title = ''
}
if (
// If there’s no url but there is a title…
(!node.url && typeof title === 'string') ||
// If there are control characters or whitespace.
enclose
) {
subexit = state.enter('destinationLiteral')
value += tracker.move('<')
value += tracker.move(
state.safe(node.url, {before: value, after: '>', ...tracker.current()})
)
value += tracker.move('>')
} else {
// No whitespace, raw is prettier.
subexit = state.enter('destinationRaw')
value += tracker.move(
state.safe(node.url, {
before: value,
after: typeof title === 'string' ? ' ' : ')',
...tracker.current()
})
)
}
subexit()
if (typeof title === 'string') {
subexit = state.enter(`title${suffix}`)
value += tracker.move(' ' + quote)
value += tracker.move(
state.safe(title, {
before: value,
after: quote,
...tracker.current()
})
)
value += tracker.move(quote)
subexit()
}
value += tracker.move(')')
exit()
return value
}
/**
* Peek at this node.
*
* @param {Link} node
* Node to peek at.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Start of the serialized markdown.
*/
function linkPeek(node, _, state) {
return formatLinkAsAutolink(node, state) ? '<' : '['
}
+20
View File
@@ -0,0 +1,20 @@
/**
* Serialize a list item node.
*
* @param {ListItem} node
* Node to serialize.
* @param {Parents | undefined} parent
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function listItem(node: ListItem, parent: Parents | undefined, state: State, info: Info): string;
import type { ListItem } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=list-item.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["list-item.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;GAaG;AACH,+BAXW,QAAQ,UAER,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAqDlB;8BAtEmC,OAAO;6BAAP,OAAO;2BADR,wBAAwB;0BAAxB,wBAAwB"}
+73
View File
@@ -0,0 +1,73 @@
/**
* @import {Info, Map, State} from 'mdast-util-to-markdown'
* @import {ListItem, Parents} from 'mdast'
*/
import {checkBullet} from '../util/check-bullet.js'
import {checkListItemIndent} from '../util/check-list-item-indent.js'
/**
* Serialize a list item node.
*
* @param {ListItem} node
* Node to serialize.
* @param {Parents | undefined} parent
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function listItem(node, parent, state, info) {
const listItemIndent = checkListItemIndent(state)
let bullet = state.bulletCurrent || checkBullet(state)
// Add the marker value for ordered lists.
if (parent && parent.type === 'list' && parent.ordered) {
bullet =
(typeof parent.start === 'number' && parent.start > -1
? parent.start
: 1) +
(state.options.incrementListMarker === false
? 0
: parent.children.indexOf(node)) +
bullet
}
let size = bullet.length + 1
if (
listItemIndent === 'tab' ||
(listItemIndent === 'mixed' &&
((parent && parent.type === 'list' && parent.spread) || node.spread))
) {
size = Math.ceil(size / 4) * 4
}
const tracker = state.createTracker(info)
tracker.move(bullet + ' '.repeat(size - bullet.length))
tracker.shift(size)
const exit = state.enter('listItem')
const value = state.indentLines(
state.containerFlow(node, tracker.current()),
map
)
exit()
return value
/**
* Indent lines of the list item.
*
* @type {Map}
*/
function map(line, index, blank) {
if (index) {
return (blank ? '' : ' '.repeat(size)) + line
}
return (blank ? bullet : bullet + ' '.repeat(size - bullet.length)) + line
}
}
+20
View File
@@ -0,0 +1,20 @@
/**
* Serialize a list node.
*
* @param {List} node
* Node to serialize.
* @param {Parents | undefined} parent
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function list(node: List, parent: Parents | undefined, state: State, info: Info): string;
import type { List } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=list.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["list.js"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;GAaG;AACH,2BAXW,IAAI,UAEJ,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAqFlB;0BAxG+B,OAAO;6BAAP,OAAO;2BADT,wBAAwB;0BAAxB,wBAAwB"}
+107
View File
@@ -0,0 +1,107 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {List, Parents} from 'mdast'
*/
import {checkBullet} from '../util/check-bullet.js'
import {checkBulletOther} from '../util/check-bullet-other.js'
import {checkBulletOrdered} from '../util/check-bullet-ordered.js'
import {checkRule} from '../util/check-rule.js'
/**
* Serialize a list node.
*
* @param {List} node
* Node to serialize.
* @param {Parents | undefined} parent
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function list(node, parent, state, info) {
const exit = state.enter('list')
const bulletCurrent = state.bulletCurrent
/** @type {string} */
let bullet = node.ordered ? checkBulletOrdered(state) : checkBullet(state)
/** @type {string} */
const bulletOther = node.ordered
? bullet === '.'
? ')'
: '.'
: checkBulletOther(state)
let useDifferentMarker =
parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false
if (!node.ordered) {
const firstListItem = node.children ? node.children[0] : undefined
// If there’s an empty first list item directly in two list items,
// we have to use a different bullet:
//
// ```markdown
// * - *
// ```
//
// …because otherwise it would become one big thematic break.
if (
// Bullet could be used as a thematic break marker:
(bullet === '*' || bullet === '-') &&
// Empty first list item:
firstListItem &&
(!firstListItem.children || !firstListItem.children[0]) &&
// Directly in two other list items:
state.stack[state.stack.length - 1] === 'list' &&
state.stack[state.stack.length - 2] === 'listItem' &&
state.stack[state.stack.length - 3] === 'list' &&
state.stack[state.stack.length - 4] === 'listItem' &&
// That are each the first child.
state.indexStack[state.indexStack.length - 1] === 0 &&
state.indexStack[state.indexStack.length - 2] === 0 &&
state.indexStack[state.indexStack.length - 3] === 0
) {
useDifferentMarker = true
}
// If there’s a thematic break at the start of the first list item,
// we have to use a different bullet:
//
// ```markdown
// * ---
// ```
//
// …because otherwise it would become one big thematic break.
if (checkRule(state) === bullet && firstListItem) {
let index = -1
while (++index < node.children.length) {
const item = node.children[index]
if (
item &&
item.type === 'listItem' &&
item.children &&
item.children[0] &&
item.children[0].type === 'thematicBreak'
) {
useDifferentMarker = true
break
}
}
}
}
if (useDifferentMarker) {
bullet = bulletOther
}
state.bulletCurrent = bullet
const value = state.containerFlow(node, info)
state.bulletLastUsed = bullet
state.bulletCurrent = bulletCurrent
exit()
return value
}
+24
View File
@@ -0,0 +1,24 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Paragraph, Parents} from 'mdast'
*/
/**
* Serialize a paragraph node.
*
* @param {Paragraph} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function paragraph(node: Paragraph, _: Parents | undefined, state: State, info: Info): string;
import type { Paragraph } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=paragraph.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["paragraph.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AACH,gCAXW,SAAS,KAET,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAUlB;+BAxBoC,OAAO;6BAAP,OAAO;2BADd,wBAAwB;0BAAxB,wBAAwB"}
+27
View File
@@ -0,0 +1,27 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Paragraph, Parents} from 'mdast'
*/
/**
* Serialize a paragraph node.
*
* @param {Paragraph} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function paragraph(node, _, state, info) {
const exit = state.enter('paragraph')
const subexit = state.enter('phrasing')
const value = state.containerPhrasing(node, info)
subexit()
exit()
return value
}
+20
View File
@@ -0,0 +1,20 @@
/**
* Serialize a root node.
*
* @param {Root} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function root(node: Root, _: Parents | undefined, state: State, info: Info): string;
import type { Root } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=root.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["root.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,2BAXW,IAAI,KAEJ,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAelB;0BA/B+B,OAAO;6BAAP,OAAO;2BADT,wBAAwB;0BAAxB,wBAAwB"}
+34
View File
@@ -0,0 +1,34 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Parents, Root} from 'mdast'
*/
import {phrasing} from 'mdast-util-phrasing'
/**
* Serialize a root node.
*
* @param {Root} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function root(node, _, state, info) {
// Note: `html` nodes are ambiguous.
const hasPhrasing = node.children.some(function (d) {
return phrasing(d)
})
if (!hasPhrasing) return state.containerFlow(node, info)
const exit = state.enter('phrasing')
const value = state.containerPhrasing(node, info)
exit()
return value
}
+52
View File
@@ -0,0 +1,52 @@
/**
* Serialize a strong node.
*
* Attention is properly handled by `containerPhrasing`.
*
* @param {Strong} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function strong(node: Strong, _: Parents | undefined, state: State, info: Info): string;
export namespace strong {
export { attention };
export { peek };
}
import type { Strong } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
/**
* Serialize a strong node as attention.
*
* @param {Strong} _
* Node to serialize.
* @param {State} state
* Info passed around.
* @returns {AttentionInfo}
* Info on how to serialize the node.
*/
declare function attention(_: Strong, state: State): AttentionInfo;
/**
* Peek at this node.
*
* @param {Strong} _
* Node to serialize.
* @param {Parents | undefined} _1
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Start of the serialized markdown.
*/
declare function peek(_: Strong, _1: Parents | undefined, state: State): string;
import type { AttentionInfo } from 'mdast-util-to-markdown';
export {};
//# sourceMappingURL=strong.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["strong.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;GAeG;AACH,6BAXW,MAAM,KAEN,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CASlB;;;;;4BA/BiC,OAAO;6BAAP,OAAO;2BADI,wBAAwB;0BAAxB,wBAAwB;AAkCrE;;;;;;;;;GASG;AACH,8BAPW,MAAM,SAEN,KAAK,GAEH,aAAa,CAUzB;AAED;;;;;;;;;;;GAWG;AACH,yBATW,MAAM,MAEN,OAAO,GAAG,SAAS,SAEnB,KAAK,GAEH,MAAM,CAKlB;mCAnE4C,wBAAwB"}
+69
View File
@@ -0,0 +1,69 @@
/**
* @import {AttentionInfo, Info, State} from 'mdast-util-to-markdown'
* @import {Parents, Strong} from 'mdast'
*/
import {checkStrong} from '../util/check-strong.js'
import {attentionItem, serialize} from '../util/container-phrasing.js'
strong.attention = attention
strong.peek = peek
/**
* Serialize a strong node.
*
* Attention is properly handled by `containerPhrasing`.
*
* @param {Strong} node
* Node to serialize.
* @param {Parents | undefined} _
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function strong(node, _, state, info) {
const exit = state.enter('phrasing')
const item = attentionItem(node, attention, state, state.createTracker(info))
const value = item ? serialize([item], info.before, info.after) : ''
exit()
return value
}
/**
* Serialize a strong node as attention.
*
* @param {Strong} _
* Node to serialize.
* @param {State} state
* Info passed around.
* @returns {AttentionInfo}
* Info on how to serialize the node.
*/
function attention(_, state) {
const marker = checkStrong(state)
return {
construct: 'strong',
markers: marker === '*' ? ['*', '_'] : ['_', '*'],
sizes: [2]
}
}
/**
* Peek at this node.
*
* @param {Strong} _
* Node to serialize.
* @param {Parents | undefined} _1
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Start of the serialized markdown.
*/
function peek(_, _1, state) {
return state.options.strong || '*'
}
+24
View File
@@ -0,0 +1,24 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Parents, Text} from 'mdast'
*/
/**
* Serialize a text node.
*
* @param {Text} node
* Node to serialize.
* @param {Parents | undefined} parent
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function text(node: Text, parent: Parents | undefined, state: State, info: Info): string;
import type { Text } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
import type { Info } from 'mdast-util-to-markdown';
//# sourceMappingURL=text.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["text.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AACH,2BAXW,IAAI,UAEJ,OAAO,GAAG,SAAS,SAEnB,KAAK,QAEL,IAAI,GAEF,MAAM,CAalB;0BA3B+B,OAAO;6BAAP,OAAO;2BADT,wBAAwB;0BAAxB,wBAAwB"}
+30
View File
@@ -0,0 +1,30 @@
/**
* @import {Info, State} from 'mdast-util-to-markdown'
* @import {Parents, Text} from 'mdast'
*/
/**
* Serialize a text node.
*
* @param {Text} node
* Node to serialize.
* @param {Parents | undefined} parent
* Parent node.
* @param {State} state
* Info passed around.
* @param {Info} info
* Info on surrounding context.
* @returns {string}
* Serialized markdown.
*/
export function text(node, parent, state, info) {
/* c8 ignore next -- parent always passed */
const siblings = parent ? parent.children : []
const index = state.indexStack[state.indexStack.length - 1]
return state.safe(node.value, {
...info,
afterNode: siblings[index + 1],
beforeNode: siblings[index - 1]
})
}
+17
View File
@@ -0,0 +1,17 @@
/**
* Serialize a thematic break node.
*
* @param {ThematicBreak} _
* Node to serialize.
* @param {Parents | undefined} _1
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Serialized markdown.
*/
export function thematicBreak(_: ThematicBreak, _1: Parents | undefined, state: State): string;
import type { ThematicBreak } from 'mdast';
import type { Parents } from 'mdast';
import type { State } from 'mdast-util-to-markdown';
//# sourceMappingURL=thematic-break.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"thematic-break.d.ts","sourceRoot":"","sources":["thematic-break.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;GAWG;AACH,iCATW,aAAa,MAEb,OAAO,GAAG,SAAS,SAEnB,KAAK,GAEH,MAAM,CASlB;mCAxBwC,OAAO;6BAAP,OAAO;2BADxB,wBAAwB"}
+27
View File
@@ -0,0 +1,27 @@
/**
* @import {State} from 'mdast-util-to-markdown'
* @import {Parents, ThematicBreak} from 'mdast'
*/
import {checkRuleRepetition} from '../util/check-rule-repetition.js'
import {checkRule} from '../util/check-rule.js'
/**
* Serialize a thematic break node.
*
* @param {ThematicBreak} _
* Node to serialize.
* @param {Parents | undefined} _1
* Parent node.
* @param {State} state
* Info passed around.
* @returns {string}
* Serialized markdown.
*/
export function thematicBreak(_, _1, state) {
const value = (
checkRule(state) + (state.options.ruleSpaces ? ' ' : '')
).repeat(checkRuleRepetition(state))
return state.options.ruleSpaces ? value.slice(0, -1) : value
}
+14
View File
@@ -0,0 +1,14 @@
/**
* Turn an mdast syntax tree into markdown.
*
* @param {Nodes} tree
* Tree to serialize.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {string}
* Serialized markdown representing `tree`.
*/
export function toMarkdown(tree: Nodes, options?: Options | null | undefined): string;
import type { Nodes } from 'mdast';
import type { Options } from 'mdast-util-to-markdown';
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAoBA;;;;;;;;;GASG;AACH,iCAPW,KAAK,YAEL,OAAO,GAAG,IAAI,GAAG,SAAS,GAExB,MAAM,CA6ElB;2BAtGuB,OAAO;6BAD0B,wBAAwB"}
+213
View File
@@ -0,0 +1,213 @@
/**
* @import {Info, Join, Options, SafeConfig, State} from 'mdast-util-to-markdown'
* @import {Nodes} from 'mdast'
* @import {Enter, FlowParents, PhrasingParents, TrackFields} from './types.js'
*/
import {phrasing} from 'mdast-util-phrasing'
import {zwitch} from 'zwitch'
import {configure} from './configure.js'
import {handle as handlers} from './handle/index.js'
import {join} from './join.js'
import {unsafe} from './unsafe.js'
import {association} from './util/association.js'
import {compilePattern} from './util/compile-pattern.js'
import {containerPhrasing} from './util/container-phrasing.js'
import {containerFlow} from './util/container-flow.js'
import {indentLines} from './util/indent-lines.js'
import {safe} from './util/safe.js'
import {track} from './util/track.js'
/**
* Turn an mdast syntax tree into markdown.
*
* @param {Nodes} tree
* Tree to serialize.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {string}
* Serialized markdown representing `tree`.
*/
export function toMarkdown(tree, options) {
const settings = options || {}
/** @type {State} */
const state = {
associationId: association,
bulletCurrent: undefined,
bulletLastUsed: undefined,
containerPhrasing: containerPhrasingBound,
containerFlow: containerFlowBound,
createTracker: track,
compilePattern,
enter,
// @ts-expect-error: GFM / frontmatter are typed in `mdast` but not defined
// here.
handlers: {...handlers},
// @ts-expect-error: add `handle` in a second.
handle: undefined,
indentLines,
indexStack: [],
join: [...join],
options: {},
safe: safeBound,
stack: [],
unsafe: [...unsafe]
}
configure(state, settings)
if (state.options.tightDefinitions) {
state.join.push(joinDefinition)
}
state.handle = zwitch('type', {
invalid,
unknown,
handlers: state.handlers
})
let result = state.handle(
phrasing(tree) ? {type: 'root', children: [tree]} : tree,
undefined,
state,
{before: '\n', after: '\n', now: {line: 1, column: 1}, lineShift: 0}
)
if (
result &&
result.charCodeAt(result.length - 1) !== 10 &&
result.charCodeAt(result.length - 1) !== 13
) {
result += '\n'
}
return result
/**
* Enter a construct.
*
* @type {Enter}
*/
function enter(name) {
state.stack.push(name)
return exit
/**
* Exit a construct.
*
* @returns {undefined}
* Nothing.
*/
function exit() {
state.stack.pop()
}
}
}
/**
* Handle an invalid value that cannot be processed.
*
* @param {unknown} value
* Value.
* @returns {never}
* Never.
* @throws {Error}
* Always.
*/
function invalid(value) {
throw new Error('Cannot handle value `' + value + '`, expected node')
}
/**
* Handle an unknown node.
*
* @param {unknown} value
* Value.
* @returns {never}
* Never.
* @throws {Error}
* Always.
*/
function unknown(value) {
// Always a node.
const node = /** @type {Nodes} */ (value)
throw new Error('Cannot handle unknown node `' + node.type + '`')
}
/**
* Join function for `tightDefinitions` option.
*
* @type {Join}
*/
function joinDefinition(left, right) {
// No blank line between adjacent definitions.
if (left.type === 'definition' && left.type === right.type) {
return 0
}
}
/**
* Serialize the children of a parent that contains phrasing children.
*
* These children will be joined flush together.
*
* @this {State}
* Info passed around about the current state.
* @param {PhrasingParents} parent
* Parent of flow nodes.
* @param {Info} info
* Info on where we are in the document we are generating.
* @returns {string}
* Serialized children, joined together.
*/
function containerPhrasingBound(parent, info) {
return containerPhrasing(parent, this, info)
}
/**
* Serialize the children of a parent that contains flow children.
*
* These children will typically be joined by blank lines.
* What they are joined by exactly is defined by `Join` functions.
*
* @this {State}
* Info passed around about the current state.
* @param {FlowParents} parent
* Parent of flow nodes.
* @param {TrackFields} info
* Info on where we are in the document we are generating.
* @returns {string}
* Serialized children, joined by (blank) lines.
*/
function containerFlowBound(parent, info) {
return containerFlow(parent, this, info)
}
/**
* Make a string safe for embedding in markdown constructs.
*
* In markdown, almost all punctuation characters can, in certain cases,
* result in something.
* Whether they do is highly subjective to where they happen and in what
* they happen.
*
* To solve this, `mdast-util-to-markdown` tracks:
*
* * Characters before and after something;
* * What “constructs” we are in.
*
* This information is then used by this function to escape or encode
* special characters.
*
* @this {State}
* Info passed around about the current state.
* @param {string | null | undefined} value
* Raw value to make safe.
* @param {SafeConfig} config
* Configuration.
* @returns {string}
* Serialized markdown safe for embedding.
*/
function safeBound(value, config) {
return safe(this, value, config)
}
+4
View File
@@ -0,0 +1,4 @@
/** @type {Array<Join>} */
export const join: Array<Join>;
import type { Join } from 'mdast-util-to-markdown';
//# sourceMappingURL=join.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"join.d.ts","sourceRoot":"","sources":["join.js"],"names":[],"mappings":"AASA,0BAA0B;AAC1B,mBADW,KAAK,CAAC,IAAI,CAAC,CACY;0BATX,wBAAwB"}
+101
View File
@@ -0,0 +1,101 @@
/**
* @import {Join} from 'mdast-util-to-markdown'
*/
import {checkRule} from './util/check-rule.js'
import {formatCodeAsIndented} from './util/format-code-as-indented.js'
import {formatHeadingAsSetext} from './util/format-heading-as-setext.js'
import {htmlKind} from './util/html-kind.js'
/** @type {Array<Join>} */
export const join = [joinDefaults]
/**
* Default join function.
*
* @type {Join}
*/
function joinDefaults(left, right, parent, state) {
// Indented code after list or another indented code.
if (
right.type === 'code' &&
formatCodeAsIndented(right, state) &&
(left.type === 'list' ||
(left.type === right.type && formatCodeAsIndented(left, state)))
) {
return false
}
// Join children of a list or an item.
// In which case, `parent` has a `spread` field.
if ('spread' in parent && typeof parent.spread === 'boolean') {
if (parent.spread) return 1
// HTML that only ends at a blank line.
if (left.type === 'html') {
const kind = htmlKind(left.value)
if (kind === undefined || kind === 6 || kind === 7) return 1
}
if (left.type === 'blockquote' && right.type === 'blockquote') return 1
// Lists with non-1 start would turn into a paragraph.
if (
(left.type === 'definition' || left.type === 'paragraph') &&
right.type === 'list' &&
((right.ordered &&
typeof right.start === 'number' &&
right.start !== 1) ||
(right.children.length > 0 && right.children[0].children.length === 0))
) {
return 1
}
// Thematic break with dashes would turn into a setext heading.
if (
left.type === 'paragraph' &&
right.type === 'thematicBreak' &&
checkRule(state) === '-' &&
!state.options.ruleSpaces
) {
return 1
}
// We have to “delve” into containers that form from the left margin.
let tail = left
while (
(tail.type === 'blockquote' ||
tail.type === 'list' ||
tail.type === 'listItem') &&
tail.children.length > 0
) {
tail = tail.children[tail.children.length - 1]
}
if (tail.type !== 'definition' && tail.type !== 'paragraph') return 0
// Indented code would turn into a paragraph.
if (right.type === 'code' && formatCodeAsIndented(right, state)) return 1
// Kind 7 HTML would turn into a paragraph.
if (right.type === 'html') {
const kind = htmlKind(right.value)
if (kind === undefined || kind === 7) return 1
}
// Text joins the paragraph before it, also one at the end of a container.
// Not a definition before it: definitions are parsed out of the start of
// a paragraph, so they and the text after them are read back the same.
if (
(left.type === 'paragraph' || left !== tail) &&
(right.type === 'definition' ||
(right.type === 'heading' && formatHeadingAsSetext(right, state)) ||
right.type === 'paragraph')
) {
return 1
}
return 0
}
}
File diff suppressed because it is too large. Load diff
+2
View File
@@ -0,0 +1,2 @@
// Note: types exposed from `types.d.ts`.
export {}
+4
View File
@@ -0,0 +1,4 @@
/** @type {Array<Unsafe>} */
export const unsafe: Array<Unsafe>;
import type { Unsafe } from 'mdast-util-to-markdown';
//# sourceMappingURL=unsafe.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"unsafe.d.ts","sourceRoot":"","sources":["unsafe.js"],"names":[],"mappings":"AAqBA,4BAA4B;AAC5B,qBADW,KAAK,CAAC,MAAM,CAAC,CAoJvB;4BAxKuC,wBAAwB"}
+177
View File
@@ -0,0 +1,177 @@
/**
* @import {ConstructName, Unsafe} from 'mdast-util-to-markdown'
*/
/**
* List of constructs that occur in phrasing (paragraphs, headings), but cannot
* contain things like attention (emphasis, strong), images, or links.
* So they sort of cancel each other out.
* Note: could use a better name.
*
* @type {Array<ConstructName>}
*/
const fullPhrasingSpans = [
'autolink',
'destinationLiteral',
'destinationRaw',
'reference',
'titleQuote',
'titleApostrophe'
]
/** @type {Array<Unsafe>} */
export const unsafe = [
{character: '\t', after: '[\\r\\n]', inConstruct: 'phrasing'},
{character: '\t', before: '[\\r\\n]', inConstruct: 'phrasing'},
{
character: '\t',
inConstruct: ['codeFencedLangGraveAccent', 'codeFencedLangTilde']
},
{
character: '\r',
inConstruct: [
'codeFencedLangGraveAccent',
'codeFencedLangTilde',
'codeFencedMetaGraveAccent',
'codeFencedMetaTilde',
'destinationLiteral',
'headingAtx'
]
},
{
character: '\n',
inConstruct: [
'codeFencedLangGraveAccent',
'codeFencedLangTilde',
'codeFencedMetaGraveAccent',
'codeFencedMetaTilde',
'destinationLiteral',
'headingAtx'
]
},
{character: '\r', before: '[\\r\\n]', inConstruct: 'phrasing'},
{character: '\r', after: '\\r', inConstruct: 'phrasing'},
{character: '\n', before: '\\n', inConstruct: 'phrasing'},
{character: '\n', after: '[\\r\\n]', inConstruct: 'phrasing'},
{character: ' ', after: '[\\r\\n]', inConstruct: 'phrasing'},
{character: ' ', before: '[\\r\\n]', inConstruct: 'phrasing'},
{
character: ' ',
inConstruct: ['codeFencedLangGraveAccent', 'codeFencedLangTilde']
},
// An exclamation mark can start an image, if it is followed by a link or
// a link reference.
{
character: '!',
after: '\\[',
inConstruct: 'phrasing',
notInConstruct: fullPhrasingSpans
},
// A quote can break out of a title.
{character: '"', inConstruct: 'titleQuote'},
// A number sign could start an ATX heading if it starts a line.
{atBreak: true, character: '#'},
{character: '#', inConstruct: 'headingAtx', after: '(?:[\r\n]|$)'},
// Dollar sign and percentage are not used in markdown.
// An ampersand could start a character reference.
// Labels match on their source.
{
character: '&',
after: '[#A-Za-z]',
inConstruct: [
'codeFencedLangGraveAccent',
'codeFencedLangTilde',
'codeFencedMetaGraveAccent',
'codeFencedMetaTilde',
'destinationLiteral',
'destinationRaw',
'phrasing',
'titleApostrophe',
'titleQuote'
]
},
// An apostrophe can break out of a title.
{character: "'", inConstruct: 'titleApostrophe'},
// A left paren could break out of a destination raw.
{character: '(', inConstruct: 'destinationRaw'},
// A left paren followed by `]` could make something into a link or image.
{
before: '\\]',
character: '(',
inConstruct: 'phrasing',
notInConstruct: fullPhrasingSpans
},
// A right paren could start a list item or break out of a destination
// raw.
{atBreak: true, before: '\\d+', character: ')'},
{character: ')', inConstruct: 'destinationRaw'},
// An asterisk can start thematic breaks, list items, emphasis, strong.
{atBreak: true, character: '*', after: '(?:[ \t\r\n*])'},
{character: '*', inConstruct: 'phrasing', notInConstruct: fullPhrasingSpans},
// A plus sign could start a list item.
{atBreak: true, character: '+', after: '(?:[ \t\r\n])'},
// A dash can start thematic breaks, list items, and setext heading
// underlines.
{atBreak: true, character: '-', after: '(?:[ \t\r\n-])'},
// A dot could start a list item.
{atBreak: true, before: '\\d+', character: '.', after: '(?:[ \t\r\n]|$)'},
// Slash, colon, and semicolon are not used in markdown for constructs.
// A less than can start html (flow or text) or an autolink.
// HTML could start with an exclamation mark (declaration, cdata, comment),
// slash (closing tag), question mark (instruction), or a letter (tag).
// An autolink also starts with a letter.
// It could break out of a destination literal,
// or start one at the start of a destination raw.
{atBreak: true, character: '<', after: '[!/?A-Za-z]'},
{
character: '<',
after: '[!/?A-Za-z]',
inConstruct: 'phrasing',
notInConstruct: fullPhrasingSpans
},
{character: '<', inConstruct: 'destinationLiteral'},
{character: '<', before: '[( ]', inConstruct: 'destinationRaw'},
// An equals to can start setext heading underlines.
{atBreak: true, character: '='},
// A greater than can start block quotes and it can break out of a
// destination literal.
{atBreak: true, character: '>'},
{character: '>', inConstruct: 'destinationLiteral'},
// Question mark and at sign are not used in markdown for constructs.
// A left bracket can start definitions, references, labels,
{atBreak: true, character: '['},
{character: '[', inConstruct: 'phrasing', notInConstruct: fullPhrasingSpans},
{character: '[', inConstruct: ['label', 'reference']},
// A backslash can start an escape (when followed by punctuation) or a
// hard break (when followed by an eol).
// Note: typical escapes are handled in `safe`!
{character: '\\', after: '[\\r\\n]', inConstruct: 'phrasing'},
// A right bracket can exit labels.
{character: ']', inConstruct: ['label', 'reference']},
// Caret is not used in markdown for constructs.
// An underscore can start emphasis, strong, or a thematic break.
{atBreak: true, character: '_'},
{character: '_', inConstruct: 'phrasing', notInConstruct: fullPhrasingSpans},
// A grave accent can start code (fenced or text), or it can break out of
// a grave accent code fence.
{atBreak: true, character: '`'},
{
character: '`',
inConstruct: ['codeFencedLangGraveAccent', 'codeFencedMetaGraveAccent']
},
{character: '`', inConstruct: 'phrasing', notInConstruct: fullPhrasingSpans},
// Left brace, vertical bar, right brace are not used in markdown for
// constructs.
// A tilde can start code (fenced).
{atBreak: true, character: '~'},
{character: '<', inConstruct: 'autolink'},
{character: '>', inConstruct: 'autolink'},
{character: '\u007F', inConstruct: 'autolink'}
]
// Also the low ASCII control characters including space.
let code = -1
while (++code < 33) {
unsafe.push({character: String.fromCharCode(code), inConstruct: 'autolink'})
}
+2
View File
@@ -0,0 +1,2 @@
export function association(node: import("mdast").Association): string;
//# sourceMappingURL=association.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"association.d.ts","sourceRoot":"","sources":["association.js"],"names":[],"mappings":""}
+33
View File
@@ -0,0 +1,33 @@
/**
* @import {AssociationId} from '../types.js'
*/
import {decodeString} from 'micromark-util-decode-string'
/**
* Get an identifier from an association to match it to others.
*
* Associations are nodes that match to something else through an ID:
* <https://github.com/syntax-tree/mdast#association>.
*
* The `label` of an association is the string value: character escapes and
* references work, and casing is intact.
* The `identifier` is used to match one association to another:
* controversially, character escapes and references don’t work in this
* matching: `&copy;` does not match `©`, and `\+` does not match `+`.
*
* But casing is ignored (and whitespace) is trimmed and collapsed: ` A\nb`
* matches `a b`.
* So, we do prefer the label when figuring out how we’re going to serialize:
* it has whitespace, casing, and we can ignore most useless character
* escapes and all character references.
*
* @type {AssociationId}
*/
export function association(node) {
if (node.label || !node.identifier) {
return node.label || ''
}
return decodeString(node.identifier)
}
+23
View File
@@ -0,0 +1,23 @@
/**
* Get the first character of a value.
*
* Is aware of astral characters (such as emoji).
*
* @param {string} value
* Value.
* @returns {string}
* First character; empty if `value` is empty.
*/
export function firstCharacter(value: string): string;
/**
* Get the last character of a value.
*
* Is aware of astral characters (such as emoji).
*
* @param {string} value
* Value.
* @returns {string}
* Last character; empty if `value` is empty.
*/
export function lastCharacter(value: string): string;
//# sourceMappingURL=character.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"character.d.ts","sourceRoot":"","sources":["character.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,sCALW,MAAM,GAEJ,MAAM,CAMlB;AAED;;;;;;;;;GASG;AACH,qCALW,MAAM,GAEJ,MAAM,CASlB"}
+32
View File
@@ -0,0 +1,32 @@
/**
* Get the first character of a value.
*
* Is aware of astral characters (such as emoji).
*
* @param {string} value
* Value.
* @returns {string}
* First character; empty if `value` is empty.
*/
export function firstCharacter(value) {
const code = value.codePointAt(0)
return code === undefined ? '' : String.fromCodePoint(code)
}
/**
* Get the last character of a value.
*
* Is aware of astral characters (such as emoji).
*
* @param {string} value
* Value.
* @returns {string}
* Last character; empty if `value` is empty.
*/
export function lastCharacter(value) {
// Only a surrogate pair gives a code point above the BMP.
const code = value.codePointAt(value.length - 2)
return code !== undefined && code > 0xff_ff
? value.slice(-2)
: value.slice(-1)
}
+15
View File
@@ -0,0 +1,15 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred ordered list bullet option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['bulletOrdered'], null | undefined>}
* Preferred ordered list bullet.
*/
export function checkBulletOrdered(state: State): Exclude<Options["bulletOrdered"], null | undefined>;
import type { State } from 'mdast-util-to-markdown';
import type { Options } from 'mdast-util-to-markdown';
//# sourceMappingURL=check-bullet-ordered.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"check-bullet-ordered.d.ts","sourceRoot":"","sources":["check-bullet-ordered.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,0CALW,KAAK,GAEH,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAe/D;2BAvBgC,wBAAwB;6BAAxB,wBAAwB"}
+25
View File
@@ -0,0 +1,25 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred ordered list bullet option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['bulletOrdered'], null | undefined>}
* Preferred ordered list bullet.
*/
export function checkBulletOrdered(state) {
const marker = state.options.bulletOrdered || '.'
if (marker !== '.' && marker !== ')') {
throw new Error(
'Cannot serialize items with `' +
marker +
'` for `options.bulletOrdered`, expected `.` or `)`'
)
}
return marker
}
+12
View File
@@ -0,0 +1,12 @@
/**
* Checks the preferred alternate list bullet option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['bullet'], null | undefined>}
* Preferred alternate list bullet.
*/
export function checkBulletOther(state: State): Exclude<Options["bullet"], null | undefined>;
import type { State } from 'mdast-util-to-markdown';
import type { Options } from 'mdast-util-to-markdown';
//# sourceMappingURL=check-bullet-other.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"check-bullet-other.d.ts","sourceRoot":"","sources":["check-bullet-other.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,wCALW,KAAK,GAEH,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CA8BxD;2BAxCgC,wBAAwB;6BAAxB,wBAAwB"}
+42
View File
@@ -0,0 +1,42 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
import {checkBullet} from './check-bullet.js'
/**
* Checks the preferred alternate list bullet option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['bullet'], null | undefined>}
* Preferred alternate list bullet.
*/
export function checkBulletOther(state) {
const bullet = checkBullet(state)
const bulletOther = state.options.bulletOther
if (!bulletOther) {
return bullet === '*' ? '-' : '*'
}
if (bulletOther !== '*' && bulletOther !== '+' && bulletOther !== '-') {
throw new Error(
'Cannot serialize items with `' +
bulletOther +
'` for `options.bulletOther`, expected `*`, `+`, or `-`'
)
}
if (bulletOther === bullet) {
throw new Error(
'Expected `bullet` (`' +
bullet +
'`) and `bulletOther` (`' +
bulletOther +
'`) to be different'
)
}
return bulletOther
}
+15
View File
@@ -0,0 +1,15 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred list bullet option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['bullet'], null | undefined>}
* Preferred list bullet.
*/
export function checkBullet(state: State): Exclude<Options["bullet"], null | undefined>;
import type { State } from 'mdast-util-to-markdown';
import type { Options } from 'mdast-util-to-markdown';
//# sourceMappingURL=check-bullet.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"check-bullet.d.ts","sourceRoot":"","sources":["check-bullet.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,mCALW,KAAK,GAEH,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAexD;2BAvBgC,wBAAwB;6BAAxB,wBAAwB"}
+25
View File
@@ -0,0 +1,25 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred list bullet option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['bullet'], null | undefined>}
* Preferred list bullet.
*/
export function checkBullet(state) {
const marker = state.options.bullet || '*'
if (marker !== '*' && marker !== '+' && marker !== '-') {
throw new Error(
'Cannot serialize items with `' +
marker +
'` for `options.bullet`, expected `*`, `+`, or `-`'
)
}
return marker
}
+15
View File
@@ -0,0 +1,15 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred emphasis option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['emphasis'], null | undefined>}
* Preferred emphasis marker.
*/
export function checkEmphasis(state: State): Exclude<Options["emphasis"], null | undefined>;
import type { State } from 'mdast-util-to-markdown';
import type { Options } from 'mdast-util-to-markdown';
//# sourceMappingURL=check-emphasis.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"check-emphasis.d.ts","sourceRoot":"","sources":["check-emphasis.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,qCALW,KAAK,GAEH,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAe1D;2BAvBgC,wBAAwB;6BAAxB,wBAAwB"}
+25
View File
@@ -0,0 +1,25 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred emphasis option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['emphasis'], null | undefined>}
* Preferred emphasis marker.
*/
export function checkEmphasis(state) {
const marker = state.options.emphasis || '*'
if (marker !== '*' && marker !== '_') {
throw new Error(
'Cannot serialize emphasis with `' +
marker +
'` for `options.emphasis`, expected `*`, or `_`'
)
}
return marker
}
+15
View File
@@ -0,0 +1,15 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred fence option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['fence'], null | undefined>}
* Preferred fence marker.
*/
export function checkFence(state: State): Exclude<Options["fence"], null | undefined>;
import type { State } from 'mdast-util-to-markdown';
import type { Options } from 'mdast-util-to-markdown';
//# sourceMappingURL=check-fence.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"check-fence.d.ts","sourceRoot":"","sources":["check-fence.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,kCALW,KAAK,GAEH,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAevD;2BAvBgC,wBAAwB;6BAAxB,wBAAwB"}
+25
View File
@@ -0,0 +1,25 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred fence option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['fence'], null | undefined>}
* Preferred fence marker.
*/
export function checkFence(state) {
const marker = state.options.fence || '`'
if (marker !== '`' && marker !== '~') {
throw new Error(
'Cannot serialize code with `' +
marker +
'` for `options.fence`, expected `` ` `` or `~`'
)
}
return marker
}
@@ -0,0 +1,15 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred list item indent option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['listItemIndent'], null | undefined>}
* Preferred list item indent.
*/
export function checkListItemIndent(state: State): Exclude<Options["listItemIndent"], null | undefined>;
import type { State } from 'mdast-util-to-markdown';
import type { Options } from 'mdast-util-to-markdown';
//# sourceMappingURL=check-list-item-indent.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"check-list-item-indent.d.ts","sourceRoot":"","sources":["check-list-item-indent.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,2CALW,KAAK,GAEH,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAehE;2BAvBgC,wBAAwB;6BAAxB,wBAAwB"}
+25
View File
@@ -0,0 +1,25 @@
/**
* @import {Options, State} from 'mdast-util-to-markdown'
*/
/**
* Checks the preferred list item indent option.
*
* @param {State} state
* Info passed around.
* @returns {Exclude<Options['listItemIndent'], null | undefined>}
* Preferred list item indent.
*/
export function checkListItemIndent(state) {
const style = state.options.listItemIndent || 'one'
if (style !== 'tab' && style !== 'one' && style !== 'mixed') {
throw new Error(
'Cannot serialize items with `' +
style +
'` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`'
)
}
return style
}
Loaded 100 of 13454 files, more files were not shown because too many files have changed in this diff. Show more