Files
react-native-devtools-frontend/node_modules/remark-stringify/lib/visitors/list-item.js
T
Mathias Bynens 79e2cf0633 Add stylelint dependency
This also adds CC-BY-4.0 to the list of accepted licenses.

DISABLE_THIRD_PARTY_CHECK=update dependencies

Bug: chromium:1083142
Change-Id: I8612de2fba52dae32eeb71af79d5aacfde52142b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2220097
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
2020-06-11 06:20:04 +00: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: I’d 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
}