@honkit/html 4.0.7 → 5.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 ADDED
@@ -0,0 +1,31 @@
1
+ /// <reference types="cheerio" />
2
+ /**
3
+ Parse an HTML string and return its content
4
+
5
+ @param html
6
+ @return {cheerio.Root}
7
+ */
8
+ export declare function parse(html: string): cheerio.Root | cheerio.Cheerio;
9
+ /**
10
+ Return main element for a DOM
11
+
12
+ @param {cheerio.DOM}
13
+ @return {cheerio.Node}
14
+ */
15
+ export declare function root($: any): any;
16
+ /**
17
+ Return text node of an element
18
+
19
+ @param {cheerio.Node}
20
+ @return {string}
21
+ */
22
+ export declare function textNode($el: any): any;
23
+ /**
24
+ Cleanup a DOM by removing all useless divs
25
+
26
+ @param {cheerio.Node}
27
+ @param {cheerio.DOM}
28
+ @return {cheerio.Node}
29
+ */
30
+ export declare function cleanup($el: any, $: any): any;
31
+ //# sourceMappingURL=dom.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ Parse an HTML content into a list of glossary entry
3
+
4
+ @param {string} html
5
+ @return {Array}
6
+ */
7
+ declare function parseGlossary(html: string): {
8
+ name: string;
9
+ description: any;
10
+ }[];
11
+ export default parseGlossary;
12
+ //# sourceMappingURL=glossary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glossary.d.ts","sourceRoot":"","sources":["../src/glossary.ts"],"names":[],"mappings":"AAGA;;;;;EAKE;AACF,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM;UAGF,MAAM;iBAAe,GAAG;IAgBxD;AACD,eAAe,aAAa,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { SummaryPart } from "./summary";
2
+ export type ToHTMLOptions = {
3
+ baseDirectory: string;
4
+ };
5
+ export type ToHTMLFunction = (content: string, options?: ToHTMLOptions) => string;
6
+ export type ToTextFunction = (content: any) => string;
7
+ export type { SummaryPart };
8
+ export type ParserSummary = ((content: string, options?: ToHTMLOptions) => {
9
+ parts: SummaryPart[];
10
+ }) & {
11
+ toText: ToTextFunction;
12
+ };
13
+ export type ParserGlossary = ((content: string, options?: ToHTMLOptions) => string[]) & {
14
+ toText: ToTextFunction;
15
+ };
16
+ export type ParserLangs = ((content: string, options?: ToHTMLOptions) => string[]) & {
17
+ toText: ToTextFunction;
18
+ };
19
+ export type ParserREADME = (content: string, options?: ToHTMLOptions) => {
20
+ title: string;
21
+ description: string;
22
+ };
23
+ export type ParserPage = ((content: string, options?: ToHTMLOptions) => {
24
+ content: string;
25
+ }) & {
26
+ prepare?: (content: string, options?: ToHTMLOptions) => string;
27
+ };
28
+ export type ParserInline = (content: string, options?: ToHTMLOptions) => {
29
+ content: string;
30
+ };
31
+ export type Parsers = {
32
+ summary: ParserSummary;
33
+ glossary: ParserGlossary;
34
+ langs: ParserLangs;
35
+ readme: ParserREADME;
36
+ page: ParserPage;
37
+ inline: ParserInline;
38
+ };
39
+ declare function createParser(toHTML: any, toText?: any): Parsers;
40
+ declare const defaultParser: Parsers;
41
+ export { defaultParser as default, createParser };
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,aA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AAM,EACf,OAAO,CAAC,EAAE,aAAa,KACtB;IACD,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,OAAO,GAAG;IAClB,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;CACxB,CAAC;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,6 +3,7 @@ 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
7
  const lodash_1 = __importDefault(require("lodash"));
7
8
  const totext_1 = __importDefault(require("./totext"));
8
9
  // import
@@ -16,22 +17,22 @@ const htmlParser = {
16
17
  glossary: glossary_1.default,
17
18
  langs: langs_1.default,
18
19
  readme: readme_1.default,
19
- page: page_1.default,
20
+ page: page_1.default
20
21
  };
21
22
  // Compose a function with a transform function for the first argument only
22
23
  function compose(toHTML, fn) {
23
- return function () {
24
- const args = lodash_1.default.toArray(arguments);
25
- args[0] = toHTML(args[0]);
26
- return fn.apply(null, args);
24
+ return function (content, options) {
25
+ // e.g. convert asciidoc to html
26
+ const html = toHTML(content, options);
27
+ return fn.call(this, html);
27
28
  };
28
29
  }
29
30
  // Create a HonKit parser from an HTML converter
30
31
  function createParser(toHTML, toText = undefined) {
31
- if (lodash_1.default.isFunction(toHTML)) {
32
+ if (typeof toHTML === "function") {
32
33
  toHTML = {
33
34
  inline: toHTML,
34
- block: toHTML,
35
+ block: toHTML
35
36
  };
36
37
  }
37
38
  const parser = {
@@ -40,7 +41,7 @@ function createParser(toHTML, toText = undefined) {
40
41
  langs: compose(toHTML.block, htmlParser.langs),
41
42
  readme: compose(toHTML.block, htmlParser.readme),
42
43
  page: compose(toHTML.block, htmlParser.page),
43
- inline: compose(toHTML.inline, htmlParser.page),
44
+ inline: compose(toHTML.inline, htmlParser.page)
44
45
  };
45
46
  // @ts-expect-error
46
47
  const _toText = new totext_1.default(toText);
@@ -49,5 +50,6 @@ function createParser(toHTML, toText = undefined) {
49
50
  parser.glossary.toText = _toText.glossary;
50
51
  return parser;
51
52
  }
52
- module.exports = createParser(lodash_1.default.identity);
53
- module.exports.createParser = createParser;
53
+ exports.createParser = createParser;
54
+ const defaultParser = createParser(lodash_1.default.identity);
55
+ exports.default = defaultParser;
package/lib/langs.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ Parse an HTML content into a list of language
3
+
4
+ @param {string} html
5
+ @return {Array}
6
+ */
7
+ declare function parseLangs(content: string): any[];
8
+ export default parseLangs;
9
+ //# sourceMappingURL=langs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"langs.d.ts","sourceRoot":"","sources":["../src/langs.ts"],"names":[],"mappings":"AAEA;;;;;EAKE;AACF,iBAAS,UAAU,CAAC,OAAO,EAAE,MAAM,SAOlC;AAED,eAAe,UAAU,CAAC"}
package/lib/page.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ Parse content of a page
3
+
4
+ @param {string} html
5
+ @return {Object}
6
+ */
7
+ declare function parsePage(html: any): {
8
+ content: any;
9
+ };
10
+ export default parsePage;
11
+ //# sourceMappingURL=page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA;;;;;EAKE;AACF,iBAAS,SAAS,CAAC,IAAI,KAAA;;EAItB;AACD,eAAe,SAAS,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ Parse an HTML content into metadata about a readme
3
+
4
+ @param {string} html
5
+ @return {Object}
6
+ */
7
+ declare function parseReadme(html: any): {
8
+ title: any;
9
+ description: any;
10
+ };
11
+ export default parseReadme;
12
+ //# sourceMappingURL=readme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readme.d.ts","sourceRoot":"","sources":["../src/readme.ts"],"names":[],"mappings":"AAEA;;;;;EAKE;AACF,iBAAS,WAAW,CAAC,IAAI,KAAA;;;EAOxB;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,15 @@
1
+ export type SummaryPart = {
2
+ title: string;
3
+ articles: any[];
4
+ };
5
+ /**
6
+ Parse an HTML content into a tree of articles/parts
7
+
8
+ @param {string} html
9
+ @return {Object}
10
+ */
11
+ declare function parseSummary(html: string): {
12
+ parts: SummaryPart[];
13
+ };
14
+ export default parseSummary;
15
+ //# sourceMappingURL=summary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../src/summary.ts"],"names":[],"mappings":"AA6HA,MAAM,MAAM,WAAW,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,GAAG,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,CAoB5D;AAED,eAAe,YAAY,CAAC"}
package/lib/summary.js CHANGED
@@ -28,11 +28,11 @@ const SELECTOR_LIST = "ol, ul";
28
28
  const SELECTOR_LINK = "> a, p > a";
29
29
  const SELECTOR_PART = "h2, h3, h4";
30
30
  /**
31
- Find a list
31
+ Find a list
32
32
 
33
- @param {cheerio.Node}
34
- @return {cheerio.Node}
35
- */
33
+ @param {cheerio.Node}
34
+ @return {cheerio.Node}
35
+ */
36
36
  function findList($parent) {
37
37
  const $container = $parent.children(".olist");
38
38
  if ($container.length > 0)
@@ -40,12 +40,12 @@ function findList($parent) {
40
40
  return $parent.children(SELECTOR_LIST);
41
41
  }
42
42
  /**
43
- Parse a ul list and return list of chapters recursvely
43
+ Parse a ul list and return list of chapters recursvely
44
44
 
45
- @param {cheerio.Node}
46
- @param {cheerio.DOM}
47
- @return {Array}
48
- */
45
+ @param {cheerio.Node}
46
+ @param {cheerio.DOM}
47
+ @return {Array}
48
+ */
49
49
  function parseList($ul, $) {
50
50
  const articles = [];
51
51
  $ul.children("li").each(function () {
@@ -70,11 +70,11 @@ function parseList($ul, $) {
70
70
  return articles;
71
71
  }
72
72
  /**
73
- Find all parts and their corresponding lists
73
+ Find all parts and their corresponding lists
74
74
 
75
- @param {cheerio.Node}
76
- @param {cheerio.DOM}
77
- @return {Array<{title: String, list: cheerio.Node}>}
75
+ @param {cheerio.Node}
76
+ @param {cheerio.DOM}
77
+ @return {Array<{title: String, list: cheerio.Node}>}
78
78
  */
79
79
  function findParts($parent, $) {
80
80
  // Find parts and lists
@@ -91,7 +91,7 @@ function findParts($parent, $) {
91
91
  }
92
92
  previousPart = {
93
93
  title: getPartTitle(el, $),
94
- list: null,
94
+ list: null
95
95
  };
96
96
  }
97
97
  else {
@@ -102,7 +102,7 @@ function findParts($parent, $) {
102
102
  else {
103
103
  previousPart = {
104
104
  title: "",
105
- list: el,
105
+ list: el
106
106
  };
107
107
  }
108
108
  parts.push(previousPart);
@@ -116,30 +116,30 @@ function findParts($parent, $) {
116
116
  return parts;
117
117
  }
118
118
  /**
119
- True if the element is a part
119
+ True if the element is a part
120
120
 
121
- @param el
122
- @return {boolean}
121
+ @param el
122
+ @return {boolean}
123
123
  */
124
124
  function isPartNode(el) {
125
125
  return SELECTOR_PART.indexOf(el.name) !== -1;
126
126
  }
127
127
  /**
128
- Parse the title of a part element
128
+ Parse the title of a part element
129
129
 
130
- @param el
131
- @param {cheerio.DOM} $
132
- @return {string}
130
+ @param el
131
+ @param {cheerio.DOM} $
132
+ @return {string}
133
133
  */
134
134
  function getPartTitle(el, $) {
135
135
  return $(el).text().trim();
136
136
  }
137
137
  /**
138
- Parse an HTML content into a tree of articles/parts
138
+ Parse an HTML content into a tree of articles/parts
139
139
 
140
- @param {string} html
141
- @return {Object}
142
- */
140
+ @param {string} html
141
+ @return {Object}
142
+ */
143
143
  function parseSummary(html) {
144
144
  const $ = dom.parse(html);
145
145
  const $root = dom.cleanup(dom.root($), $);
@@ -151,11 +151,11 @@ function parseSummary(html) {
151
151
  part = parts[i];
152
152
  parsedParts.push({
153
153
  title: part.title,
154
- articles: parseList($(part.list), $),
154
+ articles: parseList($(part.list), $)
155
155
  });
156
156
  }
157
157
  return {
158
- parts: parsedParts,
158
+ parts: parsedParts
159
159
  };
160
160
  }
161
161
  exports.default = parseSummary;
@@ -0,0 +1,3 @@
1
+ declare function ToText(markup: any): any;
2
+ export default ToText;
3
+ //# sourceMappingURL=totext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"totext.d.ts","sourceRoot":"","sources":["../src/totext.ts"],"names":[],"mappings":"AAOA,iBAAS,MAAM,CAAC,MAAM,KAAA,OAQrB;AAkKD,eAAe,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honkit/html",
3
- "version": "4.0.7",
3
+ "version": "5.0.0",
4
4
  "description": "Parse HTML content for gitbook",
5
5
  "homepage": "https://github.com/honkit/honkit",
6
6
  "bugs": {
@@ -34,7 +34,7 @@
34
34
  "scripts": {
35
35
  "build": "tsc -p .",
36
36
  "clean": "rimraf lib/",
37
- "test": "mocha test/",
37
+ "test": "mocha",
38
38
  "prepublish": "npm run --if-present build"
39
39
  },
40
40
  "dependencies": {
@@ -43,11 +43,13 @@
43
43
  "q": "^1.1.2"
44
44
  },
45
45
  "devDependencies": {
46
- "mocha": "^10.0.0",
47
- "rimraf": "^3.0.2"
46
+ "mocha": "^10.2.0",
47
+ "rimraf": "^3.0.2",
48
+ "ts-node": "^10.9.1",
49
+ "typescript": "^4.8.3"
48
50
  },
49
51
  "publishConfig": {
50
52
  "access": "public"
51
53
  },
52
- "gitHead": "b12f6eb9937552d1ff1d9a8cad75e74f1664c666"
54
+ "gitHead": "9feb7e251f1d305c2cd521f78f0a275b847a6e1b"
53
55
  }