@honkit/html 5.1.5 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/dom.d.ts CHANGED
@@ -1,31 +1,36 @@
1
- /// <reference types="cheerio" />
1
+ import * as cheerio from "cheerio";
2
2
  /**
3
- Parse an HTML string and return its content
3
+ * Load an HTML string and return a cheerio instance
4
+ * @param html
5
+ */
6
+ export declare function loadHtml(html: string): cheerio.CheerioAPI;
7
+ /**
8
+ Parse an HTML string and return its content
4
9
 
5
- @param html
6
- @return {cheerio.Root}
7
- */
8
- export declare function parse(html: string): cheerio.Root | cheerio.Cheerio;
10
+ @param html
11
+ @return {cheerio.Root}
12
+ */
13
+ export declare function parse(html: string): cheerio.CheerioAPI;
9
14
  /**
10
- Return main element for a DOM
15
+ Return main element for a DOM
11
16
 
12
- @param {cheerio.DOM}
13
- @return {cheerio.Node}
14
- */
17
+ @param {cheerio.DOM}
18
+ @return {cheerio.Node}
19
+ */
15
20
  export declare function root($: any): any;
16
21
  /**
17
- Return text node of an element
22
+ Return text node of an element
18
23
 
19
- @param {cheerio.Node}
20
- @return {string}
21
- */
24
+ @param {cheerio.Node}
25
+ @return {string}
26
+ */
22
27
  export declare function textNode($el: any): any;
23
28
  /**
24
- Cleanup a DOM by removing all useless divs
29
+ Cleanup a DOM by removing all useless divs
25
30
 
26
- @param {cheerio.Node}
27
- @param {cheerio.DOM}
28
- @return {cheerio.Node}
29
- */
31
+ @param {cheerio.Node}
32
+ @param {cheerio.DOM}
33
+ @return {cheerio.Node}
34
+ */
30
35
  export declare function cleanup($el: any, $: any): any;
31
36
  //# sourceMappingURL=dom.d.ts.map
package/lib/dom.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":";AAGA;;;;;EAKE;AACF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,kCAKjC;AAED;;;;;EAKE;AACF,wBAAgB,IAAI,CAAC,CAAC,KAAA,OAGrB;AAED;;;;;EAKE;AACF,wBAAgB,QAAQ,CAAC,GAAG,KAAA,OAS3B;AAED;;;;;;EAME;AACF,wBAAgB,OAAO,CAAC,GAAG,KAAA,EAAE,CAAC,KAAA,OAS7B"}
1
+ {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAOnC;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAEzD;AACD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAKtD;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,KAAA,OAGrB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,KAAA,OAS3B;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,KAAA,EAAE,CAAC,KAAA,OAS7B"}
package/lib/dom.js CHANGED
@@ -26,38 +26,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.cleanup = exports.textNode = exports.root = exports.parse = void 0;
29
+ exports.loadHtml = loadHtml;
30
+ exports.parse = parse;
31
+ exports.root = root;
32
+ exports.textNode = textNode;
33
+ exports.cleanup = cleanup;
30
34
  const lodash_1 = __importDefault(require("lodash"));
31
35
  const cheerio = __importStar(require("cheerio"));
32
36
  /**
33
- Parse an HTML string and return its content
37
+ * Load an HTML string and return a cheerio instance
38
+ * @param html
39
+ */
40
+ function loadHtml(html) {
41
+ return cheerio.load(html, { _useHtmlParser2: true });
42
+ }
43
+ /**
44
+ Parse an HTML string and return its content
34
45
 
35
- @param html
36
- @return {cheerio.Root}
37
- */
46
+ @param html
47
+ @return {cheerio.Root}
48
+ */
38
49
  function parse(html) {
39
50
  const $ = cheerio.load(html, { _useHtmlParser2: true });
40
51
  const $el = $("html, body").first();
41
- return $el.length > 0 ? $el : $;
52
+ return ($el.length > 0 ? $el : $);
42
53
  }
43
- exports.parse = parse;
44
54
  /**
45
- Return main element for a DOM
55
+ Return main element for a DOM
46
56
 
47
- @param {cheerio.DOM}
48
- @return {cheerio.Node}
49
- */
57
+ @param {cheerio.DOM}
58
+ @return {cheerio.Node}
59
+ */
50
60
  function root($) {
51
61
  const $el = $("html, body, > div").first();
52
62
  return $el.length > 0 ? $el : $.root();
53
63
  }
54
- exports.root = root;
55
64
  /**
56
- Return text node of an element
65
+ Return text node of an element
57
66
 
58
- @param {cheerio.Node}
59
- @return {string}
60
- */
67
+ @param {cheerio.Node}
68
+ @return {string}
69
+ */
61
70
  function textNode($el) {
62
71
  return lodash_1.default.reduce($el.children, (text, e) => {
63
72
  if (e.type == "text")
@@ -65,14 +74,13 @@ function textNode($el) {
65
74
  return text;
66
75
  }, "");
67
76
  }
68
- exports.textNode = textNode;
69
77
  /**
70
- Cleanup a DOM by removing all useless divs
78
+ Cleanup a DOM by removing all useless divs
71
79
 
72
- @param {cheerio.Node}
73
- @param {cheerio.DOM}
74
- @return {cheerio.Node}
75
- */
80
+ @param {cheerio.Node}
81
+ @param {cheerio.DOM}
82
+ @return {cheerio.Node}
83
+ */
76
84
  function cleanup($el, $) {
77
85
  $el.find("div").each(function () {
78
86
  const $div = $(this);
@@ -81,4 +89,3 @@ function cleanup($el, $) {
81
89
  });
82
90
  return $el;
83
91
  }
84
- exports.cleanup = cleanup;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { SummaryPart } from "./summary";
2
+ /**
3
+ * Utility for loading HTML content
4
+ */
5
+ export { loadHtml } from "./dom";
2
6
  export type ToHTMLOptions = {
3
7
  baseDirectory: string;
4
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","s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OAAO,EAAE,YAAY,EAAE,CAAC"}
package/lib/index.js CHANGED
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createParser = exports.default = void 0;
6
+ exports.default = exports.loadHtml = void 0;
7
+ exports.createParser = createParser;
7
8
  const lodash_1 = __importDefault(require("lodash"));
8
9
  const totext_1 = __importDefault(require("./totext"));
9
10
  // import
@@ -19,6 +20,11 @@ const htmlParser = {
19
20
  readme: readme_1.default,
20
21
  page: page_1.default
21
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; } });
22
28
  // Compose a function with a transform function for the first argument only
23
29
  function compose(toHTML, fn) {
24
30
  return function (content, options) {
@@ -50,6 +56,5 @@ function createParser(toHTML, toText = undefined) {
50
56
  parser.glossary.toText = _toText.glossary;
51
57
  return parser;
52
58
  }
53
- exports.createParser = createParser;
54
59
  const defaultParser = createParser(lodash_1.default.identity);
55
60
  exports.default = defaultParser;
package/lib/readme.d.ts CHANGED
@@ -5,8 +5,8 @@
5
5
  @return {Object}
6
6
  */
7
7
  declare function parseReadme(html: any): {
8
- title: any;
9
- description: any;
8
+ title: string;
9
+ description: string;
10
10
  };
11
11
  export default parseReadme;
12
12
  //# sourceMappingURL=readme.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honkit/html",
3
- "version": "5.1.5",
3
+ "version": "6.0.1",
4
4
  "description": "Parse HTML content for gitbook",
5
5
  "homepage": "https://github.com/honkit/honkit",
6
6
  "bugs": {
@@ -38,18 +38,18 @@
38
38
  "prepublish": "npm run --if-present build"
39
39
  },
40
40
  "dependencies": {
41
- "cheerio": "^1.0.0-rc.12",
42
- "lodash": "^4.13.1",
43
- "q": "^1.1.2"
41
+ "cheerio": "^1.0.0",
42
+ "lodash": "^4.17.21",
43
+ "q": "^1.5.1"
44
44
  },
45
45
  "devDependencies": {
46
- "mocha": "^10.2.0",
46
+ "mocha": "^10.7.3",
47
47
  "rimraf": "^3.0.2",
48
- "ts-node": "^10.9.1",
49
- "typescript": "^4.8.3"
48
+ "ts-node": "^10.9.2",
49
+ "typescript": "^5.6.2"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "d75ed67c85e3fc6976e837b56402f84e860886c7"
54
+ "gitHead": "8a67601b23ce480bce2bd1a8fb787f1f6f56656f"
55
55
  }