@awesome-fe/translate
Version:
Translation utils
76 lines • 3.62 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListItemRenderer = void 0;
var block_node_renderer_1 = require("./block-node-renderer");
var adoc_1 = require("../../utils/adoc");
function getMarker(node) {
var callouts = node.getDocument().getCallouts().getCurrentList();
var attributes = node.getAttributes();
var coids = attributes.coids;
var callout = callouts.find(function (it) { return it.id === coids; });
var ordinal = callout === null || callout === void 0 ? void 0 : callout.ordinal;
if (ordinal === undefined) {
return node.getMarker();
}
else {
return "<".concat(ordinal, ">");
}
}
var ListItemRenderer = /** @class */ (function (_super) {
__extends(ListItemRenderer, _super);
function ListItemRenderer() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.ignoredAttributeNames = ['checkbox', 'checked', 'coids'];
return _this;
}
ListItemRenderer.prototype.render = function (node) {
var attributes = node.getAttributes();
var checkbox = attributes.checkbox === '' ? attributes.checked === '' ? '[x]' : '[ ]' : '';
var text = [getMarker(node), checkbox, node.getText()].filter(function (it) { var _a; return !!((_a = it === null || it === void 0 ? void 0 : it.trim) === null || _a === void 0 ? void 0 : _a.call(it)); }).join(' ');
var blocks = node.getBlocks();
if (!blocks.length) {
return text;
}
if (blocks.length > 1) {
for (var i = 0; i < blocks.length; ++i) {
var block = blocks[i];
if (adoc_1.adoc.isList(block)) {
var wrapper = adoc_1.adoc.createBlock(node, 'open');
wrapper.getBlocks().splice(0, 0, block);
blocks[i] = wrapper;
}
}
}
var separator = blocks.length === 1 && adoc_1.adoc.isList(blocks[0]) ? '\n' : '\n+\n';
var suffix = blocks.length > 0 && !adoc_1.adoc.isList(blocks[0]) ? '\n' : '';
var contents = blocks.map(function (it) { return it.convert().trim(); });
return __spreadArray([text], contents, true).filter(function (it) { return !!it; }).join(separator) + suffix;
};
return ListItemRenderer;
}(block_node_renderer_1.BlockNodeRenderer));
exports.ListItemRenderer = ListItemRenderer;
//# sourceMappingURL=list-item-renderer.js.map