Urara-Blog/node_modules/.pnpm-store/v3/files/02/6f81fc7a08b1374deaa35bc732647718dba37d85fc6225a6cda4e17e8f5137f0a495c83c403376a5f5b2de6c30d0bd43ac9e0ef71bcc6b2d4be9d6bc165272
2022-08-14 01:14:53 +08:00

81 lines
1.8 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').Image} Image
* @typedef {import('../types.js').Handle} Handle
*/
import {checkQuote} from '../util/check-quote.js'
import {safe} from '../util/safe.js'
import {track} from '../util/track.js'
image.peek = imagePeek
/**
* @type {Handle}
* @param {Image} node
*/
export function image(node, _, context, safeOptions) {
const quote = checkQuote(context)
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
const exit = context.enter('image')
let subexit = context.enter('label')
const tracker = track(safeOptions)
let value = tracker.move('![')
value += tracker.move(
safe(context, node.alt, {before: value, after: ']', ...tracker.current()})
)
value += tracker.move('](')
subexit()
if (
// If theres no url but there is a title…
(!node.url && node.title) ||
// If there are control characters or whitespace.
/[\0- \u007F]/.test(node.url)
) {
subexit = context.enter('destinationLiteral')
value += tracker.move('<')
value += tracker.move(
safe(context, node.url, {before: value, after: '>', ...tracker.current()})
)
value += tracker.move('>')
} else {
// No whitespace, raw is prettier.
subexit = context.enter('destinationRaw')
value += tracker.move(
safe(context, node.url, {
before: value,
after: node.title ? ' ' : ')',
...tracker.current()
})
)
}
subexit()
if (node.title) {
subexit = context.enter('title' + suffix)
value += tracker.move(' ' + quote)
value += tracker.move(
safe(context, node.title, {
before: value,
after: quote,
...tracker.current()
})
)
value += tracker.move(quote)
subexit()
}
value += tracker.move(')')
exit()
return value
}
/**
* @type {Handle}
*/
function imagePeek() {
return '!'
}