index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.default = exports.loadHtml = void 0;
  7. exports.createParser = createParser;
  8. const lodash_1 = __importDefault(require("lodash"));
  9. const totext_1 = __importDefault(require("./totext"));
  10. // import
  11. const summary_1 = __importDefault(require("./summary"));
  12. const glossary_1 = __importDefault(require("./glossary"));
  13. const langs_1 = __importDefault(require("./langs"));
  14. const readme_1 = __importDefault(require("./readme"));
  15. const page_1 = __importDefault(require("./page"));
  16. const htmlParser = {
  17. summary: summary_1.default,
  18. glossary: glossary_1.default,
  19. langs: langs_1.default,
  20. readme: readme_1.default,
  21. page: page_1.default
  22. };
  23. /**
  24. * Utility for loading HTML content
  25. */
  26. var dom_1 = require("./dom");
  27. Object.defineProperty(exports, "loadHtml", { enumerable: true, get: function () { return dom_1.loadHtml; } });
  28. // Compose a function with a transform function for the first argument only
  29. function compose(toHTML, fn) {
  30. return function (content, options) {
  31. // e.g. convert asciidoc to html
  32. const html = toHTML(content, options);
  33. return fn.call(this, html);
  34. };
  35. }
  36. // Create a HonKit parser from an HTML converter
  37. function createParser(toHTML, toText = undefined) {
  38. if (typeof toHTML === "function") {
  39. toHTML = {
  40. inline: toHTML,
  41. block: toHTML
  42. };
  43. }
  44. const parser = {
  45. summary: compose(toHTML.block, htmlParser.summary),
  46. glossary: compose(toHTML.block, htmlParser.glossary),
  47. langs: compose(toHTML.block, htmlParser.langs),
  48. readme: compose(toHTML.block, htmlParser.readme),
  49. page: compose(toHTML.block, htmlParser.page),
  50. inline: compose(toHTML.inline, htmlParser.page)
  51. };
  52. // @ts-expect-error
  53. const _toText = new totext_1.default(toText);
  54. parser.summary.toText = _toText.summary;
  55. parser.langs.toText = _toText.langs;
  56. parser.glossary.toText = _toText.glossary;
  57. return parser;
  58. }
  59. const defaultParser = createParser(lodash_1.default.identity);
  60. exports.default = defaultParser;