UNPKG

@awesome-fe/translate

Version:
46 lines 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ListItemRenderer = void 0; const block_node_renderer_1 = require("./block-node-renderer"); const adoc_1 = require("../../utils/adoc"); function getMarker(node) { const callouts = node.getDocument().getCallouts().getCurrentList(); const attributes = node.getAttributes(); const coids = attributes.coids; const callout = callouts.find(it => it.id === coids); const ordinal = callout?.ordinal; if (ordinal === undefined) { return node.getMarker(); } else { return `<${ordinal}>`; } } class ListItemRenderer extends block_node_renderer_1.BlockNodeRenderer { ignoredAttributeNames = ['checkbox', 'checked', 'coids']; render(node) { const attributes = node.getAttributes(); const checkbox = attributes.checkbox === '' ? attributes.checked === '' ? '[x]' : '[ ]' : ''; const text = [getMarker(node), checkbox, node.getText()].filter(it => !!it?.trim?.()).join(' '); const blocks = node.getBlocks(); if (!blocks.length) { return text; } if (blocks.length > 1) { for (let i = 0; i < blocks.length; ++i) { const block = blocks[i]; if (adoc_1.adoc.isList(block)) { const wrapper = adoc_1.adoc.createBlock(node, 'open'); wrapper.getBlocks().splice(0, 0, block); blocks[i] = wrapper; } } } const separator = blocks.length === 1 && adoc_1.adoc.isList(blocks[0]) ? '\n' : '\n+\n'; const suffix = blocks.length > 0 && !adoc_1.adoc.isList(blocks[0]) ? '\n' : ''; const contents = blocks.map(it => it.convert().trim()); return [text, ...contents].filter(it => !!it).join(separator) + suffix; } } exports.ListItemRenderer = ListItemRenderer; //# sourceMappingURL=list-item-renderer.js.map