Skip to content

Commit e812c79

Browse files
committed
Add improved docs
1 parent 501f668 commit e812c79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+542
-402
lines changed

index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
* @typedef {import('./lib/types.js').Info} SafeOptions
33
* To do: remove next major: renamed because it doesn’t really reflect
44
* options, but instead info on the surrounding of the generated thing.
5+
* @typedef {import('./lib/types.js').State} Context
6+
* To do: remove next major: renamed because the word state more clearly
7+
* represents one thing that is passed down to everything and is changed.
58
*/
69

710
/**
8-
* @typedef {import('./lib/types.js').Info} Info
9-
* @typedef {import('./lib/types.js').Context} Context
1011
* @typedef {import('./lib/types.js').Handle} Handle
1112
* @typedef {import('./lib/types.js').Handlers} Handlers
13+
* @typedef {import('./lib/types.js').Info} Info
1214
* @typedef {import('./lib/types.js').Join} Join
13-
* @typedef {import('./lib/types.js').Unsafe} Unsafe
1415
* @typedef {import('./lib/types.js').Options} Options
16+
* @typedef {import('./lib/types.js').State} State
17+
* @typedef {import('./lib/types.js').Unsafe} Unsafe
1518
* @typedef {import('./lib/util/indent-lines.js').Map} Map
1619
*/
1720

lib/configure.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* @typedef {import('./types.js').Options} Options
3-
* @typedef {import('./types.js').Context} Context
3+
* @typedef {import('./types.js').State} State
44
*/
55

66
/**
7-
* @param {Context} base
7+
* @param {State} base
88
* @param {Options} extension
9-
* @returns {Context}
9+
* @returns {State}
1010
*/
1111
export function configure(base, extension) {
1212
let index = -1

lib/handle/blockquote.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @typedef {import('mdast').Blockquote} Blockquote
33
* @typedef {import('../types.js').Parent} Parent
4-
* @typedef {import('../types.js').Context} Context
4+
* @typedef {import('../types.js').State} State
55
* @typedef {import('../types.js').Info} Info
66
* @typedef {import('../util/indent-lines.js').Map} Map
77
*/
@@ -13,19 +13,16 @@ import {track} from '../util/track.js'
1313
/**
1414
* @param {Blockquote} node
1515
* @param {Parent | undefined} _
16-
* @param {Context} context
16+
* @param {State} state
1717
* @param {Info} info
1818
* @returns {string}
1919
*/
20-
export function blockquote(node, _, context, info) {
21-
const exit = context.enter('blockquote')
20+
export function blockquote(node, _, state, info) {
21+
const exit = state.enter('blockquote')
2222
const tracker = track(info)
2323
tracker.move('> ')
2424
tracker.shift(2)
25-
const value = indentLines(
26-
containerFlow(node, context, tracker.current()),
27-
map
28-
)
25+
const value = indentLines(containerFlow(node, state, tracker.current()), map)
2926
exit()
3027
return value
3128
}

lib/handle/break.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @typedef {import('mdast').Break} Break
33
* @typedef {import('../types.js').Parent} Parent
4-
* @typedef {import('../types.js').Context} Context
4+
* @typedef {import('../types.js').State} State
55
* @typedef {import('../types.js').Info} Info
66
*/
77

@@ -10,19 +10,19 @@ import {patternInScope} from '../util/pattern-in-scope.js'
1010
/**
1111
* @param {Break} _
1212
* @param {Parent | undefined} _1
13-
* @param {Context} context
13+
* @param {State} state
1414
* @param {Info} info
1515
* @returns {string}
1616
*/
17-
export function hardBreak(_, _1, context, info) {
17+
export function hardBreak(_, _1, state, info) {
1818
let index = -1
1919

20-
while (++index < context.unsafe.length) {
20+
while (++index < state.unsafe.length) {
2121
// If we can’t put eols in this construct (setext headings, tables), use a
2222
// space instead.
2323
if (
24-
context.unsafe[index].character === '\n' &&
25-
patternInScope(context.stack, context.unsafe[index])
24+
state.unsafe[index].character === '\n' &&
25+
patternInScope(state.stack, state.unsafe[index])
2626
) {
2727
return /[ \t]/.test(info.before) ? '' : ' '
2828
}

lib/handle/code.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @typedef {import('mdast').Code} Code
33
* @typedef {import('../types.js').Parent} Parent
4-
* @typedef {import('../types.js').Context} Context
4+
* @typedef {import('../types.js').State} State
55
* @typedef {import('../types.js').Info} Info
66
* @typedef {import('../util/indent-lines.js').Map} Map
77
*/
@@ -16,31 +16,31 @@ import {track} from '../util/track.js'
1616
/**
1717
* @param {Code} node
1818
* @param {Parent | undefined} _
19-
* @param {Context} context
19+
* @param {State} state
2020
* @param {Info} info
2121
* @returns {string}
2222
*/
23-
export function code(node, _, context, info) {
24-
const marker = checkFence(context)
23+
export function code(node, _, state, info) {
24+
const marker = checkFence(state)
2525
const raw = node.value || ''
2626
const suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
2727

28-
if (formatCodeAsIndented(node, context)) {
29-
const exit = context.enter('codeIndented')
28+
if (formatCodeAsIndented(node, state)) {
29+
const exit = state.enter('codeIndented')
3030
const value = indentLines(raw, map)
3131
exit()
3232
return value
3333
}
3434

3535
const tracker = track(info)
3636
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3))
37-
const exit = context.enter('codeFenced')
37+
const exit = state.enter('codeFenced')
3838
let value = tracker.move(sequence)
3939

4040
if (node.lang) {
41-
const subexit = context.enter('codeFencedLang' + suffix)
41+
const subexit = state.enter('codeFencedLang' + suffix)
4242
value += tracker.move(
43-
safe(context, node.lang, {
43+
safe(state, node.lang, {
4444
before: value,
4545
after: ' ',
4646
encode: ['`'],
@@ -51,10 +51,10 @@ export function code(node, _, context, info) {
5151
}
5252

5353
if (node.lang && node.meta) {
54-
const subexit = context.enter('codeFencedMeta' + suffix)
54+
const subexit = state.enter('codeFencedMeta' + suffix)
5555
value += tracker.move(' ')
5656
value += tracker.move(
57-
safe(context, node.meta, {
57+
safe(state, node.meta, {
5858
before: value,
5959
after: '\n',
6060
encode: ['`'],

lib/handle/definition.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @typedef {import('mdast').Definition} Definition
33
* @typedef {import('../types.js').Parent} Parent
4-
* @typedef {import('../types.js').Context} Context
4+
* @typedef {import('../types.js').State} State
55
* @typedef {import('../types.js').Info} Info
66
*/
77

@@ -13,19 +13,19 @@ import {track} from '../util/track.js'
1313
/**
1414
* @param {Definition} node
1515
* @param {Parent | undefined} _
16-
* @param {Context} context
16+
* @param {State} state
1717
* @param {Info} info
1818
* @returns {string}
1919
*/
20-
export function definition(node, _, context, info) {
21-
const quote = checkQuote(context)
20+
export function definition(node, _, state, info) {
21+
const quote = checkQuote(state)
2222
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
23-
const exit = context.enter('definition')
24-
let subexit = context.enter('label')
23+
const exit = state.enter('definition')
24+
let subexit = state.enter('label')
2525
const tracker = track(info)
2626
let value = tracker.move('[')
2727
value += tracker.move(
28-
safe(context, association(node), {
28+
safe(state, association(node), {
2929
before: value,
3030
after: ']',
3131
...tracker.current()
@@ -41,17 +41,17 @@ export function definition(node, _, context, info) {
4141
// If there are control characters or whitespace.
4242
/[\0- \u007F]/.test(node.url)
4343
) {
44-
subexit = context.enter('destinationLiteral')
44+
subexit = state.enter('destinationLiteral')
4545
value += tracker.move('<')
4646
value += tracker.move(
47-
safe(context, node.url, {before: value, after: '>', ...tracker.current()})
47+
safe(state, node.url, {before: value, after: '>', ...tracker.current()})
4848
)
4949
value += tracker.move('>')
5050
} else {
5151
// No whitespace, raw is prettier.
52-
subexit = context.enter('destinationRaw')
52+
subexit = state.enter('destinationRaw')
5353
value += tracker.move(
54-
safe(context, node.url, {
54+
safe(state, node.url, {
5555
before: value,
5656
after: node.title ? ' ' : '\n',
5757
...tracker.current()
@@ -62,10 +62,10 @@ export function definition(node, _, context, info) {
6262
subexit()
6363

6464
if (node.title) {
65-
subexit = context.enter('title' + suffix)
65+
subexit = state.enter('title' + suffix)
6666
value += tracker.move(' ' + quote)
6767
value += tracker.move(
68-
safe(context, node.title, {
68+
safe(state, node.title, {
6969
before: value,
7070
after: quote,
7171
...tracker.current()

lib/handle/emphasis.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @typedef {import('mdast').Emphasis} Emphasis
33
* @typedef {import('../types.js').Parent} Parent
4-
* @typedef {import('../types.js').Context} Context
4+
* @typedef {import('../types.js').State} State
55
* @typedef {import('../types.js').Info} Info
66
*/
77

@@ -18,17 +18,17 @@ emphasis.peek = emphasisPeek
1818
/**
1919
* @param {Emphasis} node
2020
* @param {Parent | undefined} _
21-
* @param {Context} context
21+
* @param {State} state
2222
* @param {Info} info
2323
* @returns {string}
2424
*/
25-
export function emphasis(node, _, context, info) {
26-
const marker = checkEmphasis(context)
27-
const exit = context.enter('emphasis')
25+
export function emphasis(node, _, state, info) {
26+
const marker = checkEmphasis(state)
27+
const exit = state.enter('emphasis')
2828
const tracker = track(info)
2929
let value = tracker.move(marker)
3030
value += tracker.move(
31-
containerPhrasing(node, context, {
31+
containerPhrasing(node, state, {
3232
before: value,
3333
after: marker,
3434
...tracker.current()
@@ -42,9 +42,9 @@ export function emphasis(node, _, context, info) {
4242
/**
4343
* @param {Emphasis} _
4444
* @param {Parent | undefined} _1
45-
* @param {Context} context
45+
* @param {State} state
4646
* @returns {string}
4747
*/
48-
function emphasisPeek(_, _1, context) {
49-
return context.options.emphasis || '*'
48+
function emphasisPeek(_, _1, state) {
49+
return state.options.emphasis || '*'
5050
}

lib/handle/heading.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @typedef {import('mdast').Heading} Heading
33
* @typedef {import('../types.js').Parent} Parent
4-
* @typedef {import('../types.js').Context} Context
4+
* @typedef {import('../types.js').State} State
55
* @typedef {import('../types.js').Info} Info
66
*/
77

@@ -12,18 +12,18 @@ import {track} from '../util/track.js'
1212
/**
1313
* @param {Heading} node
1414
* @param {Parent | undefined} _
15-
* @param {Context} context
15+
* @param {State} state
1616
* @param {Info} info
1717
* @returns {string}
1818
*/
19-
export function heading(node, _, context, info) {
19+
export function heading(node, _, state, info) {
2020
const rank = Math.max(Math.min(6, node.depth || 1), 1)
2121
const tracker = track(info)
2222

23-
if (formatHeadingAsSetext(node, context)) {
24-
const exit = context.enter('headingSetext')
25-
const subexit = context.enter('phrasing')
26-
const value = containerPhrasing(node, context, {
23+
if (formatHeadingAsSetext(node, state)) {
24+
const exit = state.enter('headingSetext')
25+
const subexit = state.enter('phrasing')
26+
const value = containerPhrasing(node, state, {
2727
...tracker.current(),
2828
before: '\n',
2929
after: '\n'
@@ -45,16 +45,16 @@ export function heading(node, _, context, info) {
4545
}
4646

4747
const sequence = '#'.repeat(rank)
48-
const exit = context.enter('headingAtx')
49-
const subexit = context.enter('phrasing')
48+
const exit = state.enter('headingAtx')
49+
const subexit = state.enter('phrasing')
5050

5151
// Note: for proper tracking, we should reset the output positions when there
5252
// is no content returned, because then the space is not output.
5353
// Practically, in that case, there is no content, so it doesn’t matter that
5454
// we’ve tracked one too many characters.
5555
tracker.move(sequence + ' ')
5656

57-
let value = containerPhrasing(node, context, {
57+
let value = containerPhrasing(node, state, {
5858
before: '# ',
5959
after: '\n',
6060
...tracker.current()
@@ -71,7 +71,7 @@ export function heading(node, _, context, info) {
7171

7272
value = value ? sequence + ' ' + value : sequence
7373

74-
if (context.options.closeAtx) {
74+
if (state.options.closeAtx) {
7575
value += ' ' + sequence
7676
}
7777

0 commit comments

Comments
 (0)