Files
coopgo/node_modules/remark-stringify/lib/visitors/list-item.js
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

76 lines
1.7 KiB
JavaScript
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.
'use strict'
var repeat = require('repeat-string')
var pad = require('../util/pad')
module.exports = listItem
var lineFeed = '\n'
var space = ' '
var leftSquareBracket = '['
var rightSquareBracket = ']'
var lowercaseX = 'x'
var ceil = Math.ceil
var blank = lineFeed + lineFeed
var tabSize = 4
// Stringify a list item.
//
// Prefixes the content with a checked checkbox when `checked: true`:
//
// ```markdown
// [x] foo
// ```
//
// Prefixes the content with an unchecked checkbox when `checked: false`:
//
// ```markdown
// [ ] foo
// ```
function listItem(node, parent, position, bullet) {
var self = this
var style = self.options.listItemIndent
var marker = bullet || self.options.bullet
var spread = node.spread == null ? true : node.spread
var checked = node.checked
var children = node.children
var length = children.length
var values = []
var index = -1
var value
var indent
var spacing
while (++index < length) {
values[index] = self.visit(children[index], node)
}
value = values.join(spread ? blank : lineFeed)
if (typeof checked === 'boolean') {
// Note: Id like to be able to only add the space between the check and
// the value, but unfortunately github does not support empty list-items
// with a checkbox :(
value =
leftSquareBracket +
(checked ? lowercaseX : space) +
rightSquareBracket +
space +
value
}
if (style === '1' || (style === 'mixed' && value.indexOf(lineFeed) === -1)) {
indent = marker.length + 1
spacing = space
} else {
indent = ceil((marker.length + 1) / tabSize) * tabSize
spacing = repeat(space, indent - marker.length)
}
return value
? marker + spacing + pad(value, indent / tabSize).slice(indent)
: marker
}