@awesome-fe/translate
Version:
Translation utils
54 lines • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listItemVisitor = void 0;
const pad_1 = require("./utils/pad");
const 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 listItemVisitor(node, parent, position, bullet) {
const style = this.options.listItemIndent;
const marker = node.marker || bullet || this.options.bullet;
const spread = node.spread == null ? true : node.spread;
const checked = node.checked;
const children = node.children;
const values = children.map(it => this.visit(it, node).trim());
if (spread) {
values.push('');
}
let value = values.join(spread ? '\n\n' : '\n');
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 = `[${checked ? 'x' : ' '}] ${value}`;
}
let indent;
let spacing;
if (style === '1' || (style === 'mixed' && value.indexOf('\n') === -1)) {
indent = marker.length + 1;
spacing = ' ';
}
else {
indent = Math.ceil((marker.length + 1) / tabSize) * tabSize;
spacing = ' '.repeat(indent - marker.length);
}
if (value) {
return marker + spacing + (0, pad_1.pad)(value, indent / tabSize).slice(indent);
}
else {
return marker;
}
}
exports.listItemVisitor = listItemVisitor;
//# sourceMappingURL=list-item-visitor.js.map