mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-06 01:49:14 +08:00
65 lines
1.8 KiB
Text
65 lines
1.8 KiB
Text
/**
|
|
* @typedef {import('mdast').ListItem} ListItem
|
|
* @typedef {import('mdast').List} List
|
|
* @typedef {import('../util/indent-lines.js').Map} Map
|
|
* @typedef {import('../types.js').Options} Options
|
|
* @typedef {import('../types.js').Handle} Handle
|
|
*/
|
|
|
|
import {checkBullet} from '../util/check-bullet.js'
|
|
import {checkListItemIndent} from '../util/check-list-item-indent.js'
|
|
import {containerFlow} from '../util/container-flow.js'
|
|
import {indentLines} from '../util/indent-lines.js'
|
|
import {track} from '../util/track.js'
|
|
|
|
/**
|
|
* @type {Handle}
|
|
* @param {ListItem} node
|
|
*/
|
|
export function listItem(node, parent, context, safeOptions) {
|
|
const listItemIndent = checkListItemIndent(context)
|
|
let bullet = context.bulletCurrent || checkBullet(context)
|
|
|
|
// Add the marker value for ordered lists.
|
|
if (parent && parent.type === 'list' && parent.ordered) {
|
|
bullet =
|
|
(typeof parent.start === 'number' && parent.start > -1
|
|
? parent.start
|
|
: 1) +
|
|
(context.options.incrementListMarker === false
|
|
? 0
|
|
: parent.children.indexOf(node)) +
|
|
bullet
|
|
}
|
|
|
|
let size = bullet.length + 1
|
|
|
|
if (
|
|
listItemIndent === 'tab' ||
|
|
(listItemIndent === 'mixed' &&
|
|
((parent && parent.type === 'list' && parent.spread) || node.spread))
|
|
) {
|
|
size = Math.ceil(size / 4) * 4
|
|
}
|
|
|
|
const tracker = track(safeOptions)
|
|
tracker.move(bullet + ' '.repeat(size - bullet.length))
|
|
tracker.shift(size)
|
|
const exit = context.enter('listItem')
|
|
const value = indentLines(
|
|
containerFlow(node, context, tracker.current()),
|
|
map
|
|
)
|
|
exit()
|
|
|
|
return value
|
|
|
|
/** @type {Map} */
|
|
function map(line, index, blank) {
|
|
if (index) {
|
|
return (blank ? '' : ' '.repeat(size)) + line
|
|
}
|
|
|
|
return (blank ? bullet : bullet + ' '.repeat(size - bullet.length)) + line
|
|
}
|
|
}
|