mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-05 05:49:31 +08:00
43 lines
1.1 KiB
Text
43 lines
1.1 KiB
Text
/**
|
||
* @typedef {import('mdast').Emphasis} Emphasis
|
||
* @typedef {import('../types.js').Handle} Handle
|
||
*/
|
||
|
||
import {checkEmphasis} from '../util/check-emphasis.js'
|
||
import {containerPhrasing} from '../util/container-phrasing.js'
|
||
import {track} from '../util/track.js'
|
||
|
||
emphasis.peek = emphasisPeek
|
||
|
||
// To do: there are cases where emphasis cannot “form” depending on the
|
||
// previous or next character of sequences.
|
||
// There’s no way around that though, except for injecting zero-width stuff.
|
||
// Do we need to safeguard against that?
|
||
/**
|
||
* @type {Handle}
|
||
* @param {Emphasis} node
|
||
*/
|
||
export function emphasis(node, _, context, safeOptions) {
|
||
const marker = checkEmphasis(context)
|
||
const exit = context.enter('emphasis')
|
||
const tracker = track(safeOptions)
|
||
let value = tracker.move(marker)
|
||
value += tracker.move(
|
||
containerPhrasing(node, context, {
|
||
before: value,
|
||
after: marker,
|
||
...tracker.current()
|
||
})
|
||
)
|
||
value += tracker.move(marker)
|
||
exit()
|
||
return value
|
||
}
|
||
|
||
/**
|
||
* @type {Handle}
|
||
* @param {Emphasis} _
|
||
*/
|
||
function emphasisPeek(_, _1, context) {
|
||
return context.options.emphasis || '*'
|
||
}
|