|
| 1 | +/** |
| 2 | + * @typedef {import('mdast').Code} Code |
| 3 | + * @typedef {import('../types.js').Handle} Handle |
| 4 | + * @typedef {import('../types.js').Exit} Exit |
| 5 | + * @typedef {import('../util/indent-lines.js').Map} Map |
| 6 | + */ |
| 7 | + |
1 | 8 | import {longestStreak} from 'longest-streak' |
2 | 9 | import {formatCodeAsIndented} from '../util/format-code-as-indented.js' |
3 | 10 | import {checkFence} from '../util/check-fence.js' |
4 | 11 | import {indentLines} from '../util/indent-lines.js' |
5 | 12 | import {safe} from '../util/safe.js' |
6 | 13 |
|
| 14 | +/** |
| 15 | + * @type {Handle} |
| 16 | + * @param {Code} node |
| 17 | + */ |
7 | 18 | export function code(node, _, context) { |
8 | 19 | const marker = checkFence(context) |
9 | 20 | const raw = node.value || '' |
10 | 21 | const suffix = marker === '`' ? 'GraveAccent' : 'Tilde' |
| 22 | + /** @type {string} */ |
11 | 23 | let value |
| 24 | + /** @type {Exit} */ |
12 | 25 | let exit |
13 | 26 |
|
14 | 27 | if (formatCodeAsIndented(node, context)) { |
15 | 28 | exit = context.enter('codeIndented') |
16 | 29 | value = indentLines(raw, map) |
17 | 30 | } else { |
18 | 31 | const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3)) |
| 32 | + /** @type {Exit} */ |
19 | 33 | let subexit |
20 | 34 | exit = context.enter('codeFenced') |
21 | 35 | value = sequence |
@@ -55,6 +69,7 @@ export function code(node, _, context) { |
55 | 69 | return value |
56 | 70 | } |
57 | 71 |
|
| 72 | +/** @type {Map} */ |
58 | 73 | function map(line, _, blank) { |
59 | 74 | return (blank ? '' : ' ') + line |
60 | 75 | } |
0 commit comments