index.cjs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. const primitives_js_1 = require("../primitives.cjs");
  6. const util_js_1 = require("../util.cjs");
  7. const block_parser_js_1 = require("./block-parser.cjs");
  8. const source_parser_js_1 = require("./source-parser.cjs");
  9. const spec_parser_js_1 = require("./spec-parser.cjs");
  10. const tag_js_1 = require("./tokenizers/tag.cjs");
  11. const type_js_1 = require("./tokenizers/type.cjs");
  12. const name_js_1 = require("./tokenizers/name.cjs");
  13. const description_js_1 = require("./tokenizers/description.cjs");
  14. function getParser({
  15. startLine = 0,
  16. fence = '```',
  17. spacing = 'compact',
  18. markers = primitives_js_1.Markers,
  19. tokenizers = [(0, tag_js_1.default)(), (0, type_js_1.default)(spacing), (0, name_js_1.default)(), (0, description_js_1.default)(spacing)]
  20. } = {}) {
  21. if (startLine < 0 || startLine % 1 > 0) throw new Error('Invalid startLine');
  22. const parseSource = (0, source_parser_js_1.default)({
  23. startLine,
  24. markers
  25. });
  26. const parseBlock = (0, block_parser_js_1.default)({
  27. fence
  28. });
  29. const parseSpec = (0, spec_parser_js_1.default)({
  30. tokenizers
  31. });
  32. const joinDescription = (0, description_js_1.getJoiner)(spacing);
  33. return function (source) {
  34. const blocks = [];
  35. for (const line of (0, util_js_1.splitLines)(source)) {
  36. const lines = parseSource(line);
  37. if (lines === null) continue;
  38. const sections = parseBlock(lines);
  39. const specs = sections.slice(1).map(parseSpec);
  40. blocks.push({
  41. description: joinDescription(sections[0], markers),
  42. tags: specs,
  43. source: lines,
  44. problems: specs.reduce((acc, spec) => acc.concat(spec.problems), [])
  45. });
  46. }
  47. return blocks;
  48. };
  49. }
  50. exports.default = getParser;
  51. //# sourceMappingURL=index.cjs.map