@honkit/html 5.1.4 → 6.0.0

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;AAEnC;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAIzD;AACD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAOtD;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,51 @@ 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
+ // https://github.com/cheeriojs/cheerio/issues/1260
42
+ // @ts-expect-error -- _useHtmlParser2 is not in the types
43
+ return cheerio.load(html, { _useHtmlParser2: true });
44
+ }
45
+ /**
46
+ Parse an HTML string and return its content
34
47
 
35
- @param html
36
- @return {cheerio.Root}
37
- */
48
+ @param html
49
+ @return {cheerio.Root}
50
+ */
38
51
  function parse(html) {
52
+ // https://github.com/cheeriojs/cheerio/issues/1260
53
+ // @ts-expect-error -- _useHtmlParser2 is not in the types
39
54
  const $ = cheerio.load(html, { _useHtmlParser2: true });
40
55
  const $el = $("html, body").first();
41
- return $el.length > 0 ? $el : $;
56
+ return ($el.length > 0 ? $el : $);
42
57
  }
43
- exports.parse = parse;
44
58
  /**
45
- Return main element for a DOM
59
+ Return main element for a DOM
46
60
 
47
- @param {cheerio.DOM}
48
- @return {cheerio.Node}
49
- */
61
+ @param {cheerio.DOM}
62
+ @return {cheerio.Node}
63
+ */
50
64
  function root($) {
51
65
  const $el = $("html, body, > div").first();
52
66
  return $el.length > 0 ? $el : $.root();
53
67
  }
54
- exports.root = root;
55
68
  /**
56
- Return text node of an element
69
+ Return text node of an element
57
70
 
58
- @param {cheerio.Node}
59
- @return {string}
60
- */
71
+ @param {cheerio.Node}
72
+ @return {string}
73
+ */
61
74
  function textNode($el) {
62
75
  return lodash_1.default.reduce($el.children, (text, e) => {
63
76
  if (e.type == "text")
@@ -65,14 +78,13 @@ function textNode($el) {
65
78
  return text;
66
79
  }, "");
67
80
  }
68
- exports.textNode = textNode;
69
81
  /**
70
- Cleanup a DOM by removing all useless divs
82
+ Cleanup a DOM by removing all useless divs
71
83
 
72
- @param {cheerio.Node}
73
- @param {cheerio.DOM}
74
- @return {cheerio.Node}
75
- */
84
+ @param {cheerio.Node}
85
+ @param {cheerio.DOM}
86
+ @return {cheerio.Node}
87
+ */
76
88
  function cleanup($el, $) {
77
89
  $el.find("div").each(function () {
78
90
  const $div = $(this);
@@ -81,4 +93,3 @@ function cleanup($el, $) {
81
93
  });
82
94
  return $el;
83
95
  }
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","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAcjD,MAAM,MAAM,aAAa,GAAG;IACxB,aAAa,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,MAAM,CAAC;AAElF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,CAAC;AAC5B,MAAM,MAAM,aAAa,GAAG,CAAC,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,aAAa,KACtB;IACD,KAAK,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC,GAAG;IACD,MAAM,EAAE,cAAc,CAAC;CAC1B,CAAC;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,MAAM,EAAE,CAAC,GAAG;IACpF,MAAM,EAAE,cAAc,CAAC;CAC1B,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,MAAM,EAAE,CAAC,GAAG;IACjF,MAAM,EAAE,cAAc,CAAC;CAC1B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,aAAa,KACtB;IACD,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,CAAC,CACtB,OA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;AAYF,iBAAS,YAAY,CAAC,MAAM,KAAA,EAAE,MAAM,MAAY,GAAG,OAAO,CAwBzD;AAED,QAAA,MAAM,aAAa,SAA2B,CAAC;AAC/C,OAAO,EAAE,aAAa,IAAI,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.4",
3
+ "version": "6.0.0",
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": "1c26afb66065cd7437e0e8f9d226327d49259313"
54
+ "gitHead": "367fe659a4a33c656ae51a1ec75fff0447365f9f"
55
55
  }