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

+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
}