Urara-Blog/node_modules/.pnpm-store/v3/files/ae/03f179b1a765f9497181e229b42b049edfd48bcf74d89f4e9986d017401211eade21e66893e0e8206e327c6ea52577b5e896119ce20920518bb30947f7ca99
2022-08-14 01:14:53 +08:00

64 lines
1.7 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @typedef {import('mdast').ImageReference} ImageReference
* @typedef {import('../types.js').Handle} Handle
*/
import {association} from '../util/association.js'
import {safe} from '../util/safe.js'
import {track} from '../util/track.js'
imageReference.peek = imageReferencePeek
/**
* @type {Handle}
* @param {ImageReference} node
*/
export function imageReference(node, _, context, safeOptions) {
const type = node.referenceType
const exit = context.enter('imageReference')
let subexit = context.enter('label')
const tracker = track(safeOptions)
let value = tracker.move('![')
const alt = safe(context, node.alt, {
before: value,
after: ']',
...tracker.current()
})
value += tracker.move(alt + '][')
subexit()
// Hide the fact that were in phrasing, because escapes dont work.
const stack = context.stack
context.stack = []
subexit = context.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 doesnt matter that
// weve tracked one too many characters.
const reference = safe(context, association(node), {
before: value,
after: ']',
...tracker.current()
})
subexit()
context.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
}
/**
* @type {Handle}
*/
function imageReferencePeek() {
return '!'
}