UNPKG

markdown-vetur

Version:

simple parse markdown to vue component description for vetur auto-completion

51 lines 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var FLAG_REG = /(.*?)\s*(API|Event)/i; function codegen(artical) { var tags = {}; // const attributes = {}; var tagDescription = ''; var _loop_1 = function (i, len) { var item = artical[i]; if (item.type === 'title' && item.level === 2) { tagDescription = item.content; } else if (item.type === 'table') { var before = artical[i - 1]; if (!before) { return "continue"; } var table = item.table; var match = FLAG_REG.exec(before.content); if (!match) { return "continue"; } var key = camelCaseToKebabCase(match[1] || 'default'); var tag_1 = tags[key] || { description: tagDescription, attributes: {} }; tags[key] = tag_1; var isProp_1 = /API/i.test(match[2]); table.body.forEach(function (td) { var attrName = td[0]; var attr = { description: td[1] + ", " + (isProp_1 ? 'default: ' + td[3].replace(/`/g, '') : 'params: ' + td[2]), type: isProp_1 ? td[2].replace(/`/g, '').toLowerCase() : 'event' }; tag_1.attributes[attrName] = attr; }); } }; for (var i = 0, len = artical.length; i < len; i++) { _loop_1(i, len); } return tags; } exports.default = codegen; function camelCaseToKebabCase(input) { return input.replace(/[A-Z]/g, function (val, index) { return (index === 0 ? '' : '-') + val.toLowerCase(); }); } //# sourceMappingURL=codegen.js.map