honkit 3.7.5 → 4.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/README.md +5 -0
- package/lib/__tests__/e2e.test.js +13 -13
- package/lib/__tests__/snapshot-honkit.js +6 -3
- package/lib/output/__tests__/website.js +1 -1
- package/lib/output/modifiers/__tests__/addHeadingId.js +26 -3
- package/lib/output/modifiers/__tests__/annotateText.js +41 -4
- package/lib/output/modifiers/__tests__/fetchRemoteImages.js +26 -3
- package/lib/output/modifiers/__tests__/highlightCode.js +28 -5
- package/lib/output/modifiers/__tests__/inlinePng.js +25 -2
- package/lib/output/modifiers/__tests__/inlineSvg.js +26 -3
- package/lib/output/modifiers/__tests__/resolveImages.js +27 -4
- package/lib/output/modifiers/__tests__/resolveLinks.js +31 -8
- package/lib/output/modifiers/__tests__/svgToImg.js +26 -3
- package/lib/output/modifiers/annotateText.js +16 -11
- package/lib/output/modifiers/inlineSvg.js +25 -2
- package/lib/output/modifiers/modifyHTML.js +25 -2
- package/lib/plugins/PluginResolver.js +5 -1
- package/lib/plugins/validatePlugin.js +1 -1
- package/lib/templating/__tests__/conrefsLoader.js +3 -6
- package/lib/utils/__tests__/git.js +5 -6
- package/package.json +11 -22
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ const cwdPlugin = {
|
|
|
12
12
|
test: (value) => typeof value === "string" && value.includes(CWD),
|
|
13
13
|
print: (value, serialize) => {
|
|
14
14
|
if (typeof value === "string") {
|
|
15
|
-
return serialize(value.split(CWD).join("<CWD>").replace(/\\/g,
|
|
15
|
+
return serialize(value.split(CWD).join("<CWD>").replace(/\\/g, "/"));
|
|
16
16
|
}
|
|
17
17
|
return value;
|
|
18
18
|
},
|
|
@@ -30,48 +30,48 @@ describe("e2e", function () {
|
|
|
30
30
|
it("`honkit parse` for multilang", async () => {
|
|
31
31
|
await (0, bin_1.run)([process.argv[0], "honkit", "parse", path_1.default.join(__dirname, "__fixtures__/multilang")]);
|
|
32
32
|
expect(stdoutMock.mock.calls).toMatchInlineSnapshot(`
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
[
|
|
34
|
+
[
|
|
35
35
|
"info: parsing multilingual book, with 2 languages
|
|
36
36
|
",
|
|
37
37
|
],
|
|
38
|
-
|
|
38
|
+
[
|
|
39
39
|
"warn: no summary file in this book
|
|
40
40
|
",
|
|
41
41
|
],
|
|
42
|
-
|
|
42
|
+
[
|
|
43
43
|
"warn: no summary file in this book
|
|
44
44
|
",
|
|
45
45
|
],
|
|
46
|
-
|
|
46
|
+
[
|
|
47
47
|
"info: Book located in: <CWD>/src/__tests__/__fixtures__/multilang
|
|
48
48
|
",
|
|
49
49
|
],
|
|
50
|
-
|
|
50
|
+
[
|
|
51
51
|
"info: 2 languages
|
|
52
52
|
",
|
|
53
53
|
],
|
|
54
|
-
|
|
54
|
+
[
|
|
55
55
|
"info: Language: English
|
|
56
56
|
",
|
|
57
57
|
],
|
|
58
|
-
|
|
58
|
+
[
|
|
59
59
|
"info: Introduction file is README.md
|
|
60
60
|
",
|
|
61
61
|
],
|
|
62
|
-
|
|
62
|
+
[
|
|
63
63
|
"info:
|
|
64
64
|
",
|
|
65
65
|
],
|
|
66
|
-
|
|
66
|
+
[
|
|
67
67
|
"info: Language: Japanese
|
|
68
68
|
",
|
|
69
69
|
],
|
|
70
|
-
|
|
70
|
+
[
|
|
71
71
|
"info: Introduction file is README.md
|
|
72
72
|
",
|
|
73
73
|
],
|
|
74
|
-
|
|
74
|
+
[
|
|
75
75
|
"info:
|
|
76
76
|
",
|
|
77
77
|
],
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -26,7 +30,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
26
30
|
const internal_test_utils_1 = require("@honkit/internal-test-utils");
|
|
27
31
|
const bin = __importStar(require("../bin"));
|
|
28
32
|
it("HonKit snapshots", async () => {
|
|
29
|
-
jest.setTimeout(60 * 1000);
|
|
30
33
|
const bookDir = path_1.default.join(__dirname, "__fixtures__/honkit");
|
|
31
34
|
const outputDir = path_1.default.join(__dirname, "__fixtures__/honkit/_book");
|
|
32
35
|
await bin.run([process.argv[0], ".", "build", bookDir, "--reload"]);
|
|
@@ -42,4 +45,4 @@ it("HonKit snapshots", async () => {
|
|
|
42
45
|
})) {
|
|
43
46
|
expect(item).toMatchSnapshot(item.filePath);
|
|
44
47
|
}
|
|
45
|
-
});
|
|
48
|
+
}, 60 * 1000);
|
|
@@ -1,20 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
29
|
+
const cheerio = __importStar(require("cheerio"));
|
|
7
30
|
const addHeadingId_1 = __importDefault(require("../addHeadingId"));
|
|
8
31
|
describe("addHeadingId", () => {
|
|
9
32
|
test("should add an ID if none", () => {
|
|
10
|
-
const $ =
|
|
33
|
+
const $ = cheerio.load("<h1>Hello World</h1><h2>Cool !!</h2>", { _useHtmlParser2: true });
|
|
11
34
|
return (0, addHeadingId_1.default)($).then(() => {
|
|
12
35
|
const html = $.html();
|
|
13
36
|
expect(html).toBe("<h1 id=\"hello-world\">Hello World</h1><h2 id=\"cool-\">Cool !!</h2>");
|
|
14
37
|
});
|
|
15
38
|
});
|
|
16
39
|
test("should not change existing IDs", () => {
|
|
17
|
-
const $ =
|
|
40
|
+
const $ = cheerio.load("<h1 id=\"awesome\">Hello World</h1>", { _useHtmlParser2: true });
|
|
18
41
|
return (0, addHeadingId_1.default)($).then(() => {
|
|
19
42
|
const html = $.html();
|
|
20
43
|
expect(html).toBe("<h1 id=\"awesome\">Hello World</h1>");
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
-
const
|
|
30
|
+
const cheerio = __importStar(require("cheerio"));
|
|
8
31
|
const glossaryEntry_1 = __importDefault(require("../../../models/glossaryEntry"));
|
|
9
32
|
const annotateText_1 = __importDefault(require("../annotateText"));
|
|
10
33
|
describe("annotateText", () => {
|
|
@@ -13,7 +36,7 @@ describe("annotateText", () => {
|
|
|
13
36
|
new glossaryEntry_1.default({ name: "Multiple Words" }),
|
|
14
37
|
]);
|
|
15
38
|
test("should annotate text", () => {
|
|
16
|
-
const $ =
|
|
39
|
+
const $ = cheerio.load("<p>This is a word, and multiple words</p>", { _useHtmlParser2: true });
|
|
17
40
|
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
|
|
18
41
|
const links = $("a");
|
|
19
42
|
expect(links.length).toBe(2);
|
|
@@ -26,13 +49,27 @@ describe("annotateText", () => {
|
|
|
26
49
|
expect(words.text()).toBe("multiple words");
|
|
27
50
|
expect(words.hasClass("glossary-term")).toBeTruthy();
|
|
28
51
|
});
|
|
52
|
+
test("should annotate text with regardless of glossary order", () => {
|
|
53
|
+
const $ = cheerio.load("<p>This is multiple words, and another word.</p>", { _useHtmlParser2: true });
|
|
54
|
+
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
|
|
55
|
+
const links = $("a");
|
|
56
|
+
expect(links.length).toBe(2);
|
|
57
|
+
const word = $(links.get(0));
|
|
58
|
+
expect(word.attr("href")).toBe("/GLOSSARY.md#multiple-words");
|
|
59
|
+
expect(word.text()).toBe("multiple words");
|
|
60
|
+
expect(word.hasClass("glossary-term")).toBeTruthy();
|
|
61
|
+
const words = $(links.get(1));
|
|
62
|
+
expect(words.attr("href")).toBe("/GLOSSARY.md#word");
|
|
63
|
+
expect(words.text()).toBe("word");
|
|
64
|
+
expect(words.hasClass("glossary-term")).toBeTruthy();
|
|
65
|
+
});
|
|
29
66
|
test("should not annotate scripts", () => {
|
|
30
|
-
const $ =
|
|
67
|
+
const $ = cheerio.load("<script>This is a word, and multiple words</script>", { _useHtmlParser2: true });
|
|
31
68
|
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
|
|
32
69
|
expect($("a").length).toBe(0);
|
|
33
70
|
});
|
|
34
71
|
test('should not annotate when has class "no-glossary"', () => {
|
|
35
|
-
const $ =
|
|
72
|
+
const $ = cheerio.load('<p class="no-glossary">This is a word, and multiple words</p>', { _useHtmlParser2: true });
|
|
36
73
|
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
|
|
37
74
|
expect($("a").length).toBe(0);
|
|
38
75
|
});
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
29
|
+
const cheerio = __importStar(require("cheerio"));
|
|
7
30
|
const tmp_1 = __importDefault(require("tmp"));
|
|
8
31
|
const path_1 = __importDefault(require("path"));
|
|
9
32
|
const fetchRemoteImages_1 = __importDefault(require("../fetchRemoteImages"));
|
|
@@ -14,7 +37,7 @@ describe.skip("fetchRemoteImages", () => {
|
|
|
14
37
|
dir = tmp_1.default.dirSync();
|
|
15
38
|
});
|
|
16
39
|
test("should download image file", () => {
|
|
17
|
-
const $ =
|
|
40
|
+
const $ = cheerio.load(`<img src="${URL}" />`, { _useHtmlParser2: true });
|
|
18
41
|
return (0, fetchRemoteImages_1.default)(dir.name, "index.html", $).then(() => {
|
|
19
42
|
const $img = $("img");
|
|
20
43
|
const src = $img.attr("src");
|
|
@@ -22,7 +45,7 @@ describe.skip("fetchRemoteImages", () => {
|
|
|
22
45
|
});
|
|
23
46
|
});
|
|
24
47
|
test("should download image file and replace with relative path", () => {
|
|
25
|
-
const $ =
|
|
48
|
+
const $ = cheerio.load(`<img src="${URL}" />`, { _useHtmlParser2: true });
|
|
26
49
|
return (0, fetchRemoteImages_1.default)(dir.name, "test/index.html", $).then(() => {
|
|
27
50
|
const $img = $("img");
|
|
28
51
|
const src = $img.attr("src");
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
29
|
+
const cheerio = __importStar(require("cheerio"));
|
|
7
30
|
const promise_1 = __importDefault(require("../../../utils/promise"));
|
|
8
31
|
const highlightCode_1 = __importDefault(require("../highlightCode"));
|
|
9
32
|
describe("highlightCode", () => {
|
|
@@ -18,28 +41,28 @@ describe("highlightCode", () => {
|
|
|
18
41
|
});
|
|
19
42
|
}
|
|
20
43
|
test("should call it for normal code element", () => {
|
|
21
|
-
const $ =
|
|
44
|
+
const $ = cheerio.load("<p>This is a <code>test</code></p>", { _useHtmlParser2: true });
|
|
22
45
|
return (0, highlightCode_1.default)(doHighlight, $).then(() => {
|
|
23
46
|
const $code = $("code");
|
|
24
47
|
expect($code.text()).toBe("$test");
|
|
25
48
|
});
|
|
26
49
|
});
|
|
27
50
|
test("should call it for markdown code block", () => {
|
|
28
|
-
const $ =
|
|
51
|
+
const $ = cheerio.load("<pre><code class=\"lang-js\">test</code></pre>", { _useHtmlParser2: true });
|
|
29
52
|
return (0, highlightCode_1.default)(doHighlight, $).then(() => {
|
|
30
53
|
const $code = $("code");
|
|
31
54
|
expect($code.text()).toBe("js$test");
|
|
32
55
|
});
|
|
33
56
|
});
|
|
34
57
|
test("should call it for asciidoc code block", () => {
|
|
35
|
-
const $ =
|
|
58
|
+
const $ = cheerio.load("<pre><code class=\"language-python\">test</code></pre>", { _useHtmlParser2: true });
|
|
36
59
|
return (0, highlightCode_1.default)(doHighlight, $).then(() => {
|
|
37
60
|
const $code = $("code");
|
|
38
61
|
expect($code.text()).toBe("python$test");
|
|
39
62
|
});
|
|
40
63
|
});
|
|
41
64
|
test("should accept async highlighter", () => {
|
|
42
|
-
const $ =
|
|
65
|
+
const $ = cheerio.load("<pre><code class=\"language-python\">test</code></pre>", { _useHtmlParser2: true });
|
|
43
66
|
return (0, highlightCode_1.default)(doHighlightAsync, $).then(() => {
|
|
44
67
|
const $code = $("code");
|
|
45
68
|
expect($code.text()).toBe("python$test");
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
29
|
+
const cheerio = __importStar(require("cheerio"));
|
|
7
30
|
const tmp_1 = __importDefault(require("tmp"));
|
|
8
31
|
const inlinePng_1 = __importDefault(require("../inlinePng"));
|
|
9
32
|
describe("inlinePng", () => {
|
|
@@ -12,7 +35,7 @@ describe("inlinePng", () => {
|
|
|
12
35
|
dir = tmp_1.default.dirSync();
|
|
13
36
|
});
|
|
14
37
|
test("should write an inline PNG using data URI as a file", () => {
|
|
15
|
-
const $ =
|
|
38
|
+
const $ = cheerio.load("<img alt=\"HonKit Logo 20x20\" src=\"data:image/png;base64,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\"/>", { _useHtmlParser2: true });
|
|
16
39
|
return (0, inlinePng_1.default)(dir.name, "index.html", $).then(() => {
|
|
17
40
|
const $img = $("img");
|
|
18
41
|
const src = $img.attr("src");
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
29
|
+
const cheerio = __importStar(require("cheerio"));
|
|
7
30
|
const tmp_1 = __importDefault(require("tmp"));
|
|
8
31
|
const path_1 = __importDefault(require("path"));
|
|
9
32
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -17,7 +40,7 @@ describe("inlineSvg", () => {
|
|
|
17
40
|
});
|
|
18
41
|
test("should inline svg icons", () => {
|
|
19
42
|
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke-width="6"/></svg>';
|
|
20
|
-
const $ =
|
|
43
|
+
const $ = cheerio.load('<img src="test.svg"/>', { _useHtmlParser2: true });
|
|
21
44
|
return fs_1.default.promises
|
|
22
45
|
.writeFile(svgPath, svg)
|
|
23
46
|
.then(() => {
|
|
@@ -29,7 +52,7 @@ describe("inlineSvg", () => {
|
|
|
29
52
|
});
|
|
30
53
|
test("should not inline svgs with style tags", () => {
|
|
31
54
|
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1" style="background-color:red"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>';
|
|
32
|
-
const $ =
|
|
55
|
+
const $ = cheerio.load('<img src="test.svg"/>', { _useHtmlParser2: true });
|
|
33
56
|
return fs_1.default.promises
|
|
34
57
|
.writeFile(svgPath, svg)
|
|
35
58
|
.then(() => {
|
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
29
|
+
const cheerio = __importStar(require("cheerio"));
|
|
7
30
|
const resolveImages_1 = __importDefault(require("../resolveImages"));
|
|
8
31
|
describe("resolveImages", () => {
|
|
9
32
|
describe("img tag", () => {
|
|
10
33
|
const TEST = "<img src=\"http://www.github.com\">";
|
|
11
34
|
test("no error occurs and return undefined", () => {
|
|
12
|
-
const $ =
|
|
35
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
13
36
|
return (0, resolveImages_1.default)("hello.md", $).then(() => {
|
|
14
37
|
const src = $("img").attr("src");
|
|
15
38
|
expect(src).toBe("http://www.github.com");
|
|
@@ -19,7 +42,7 @@ describe("resolveImages", () => {
|
|
|
19
42
|
describe("img tag with break line", () => {
|
|
20
43
|
const TEST = "<img \nsrc=\"http://www.github.com\">";
|
|
21
44
|
test("no error occurs and return undefined", () => {
|
|
22
|
-
const $ =
|
|
45
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
23
46
|
return (0, resolveImages_1.default)("hello.md", $).then(() => {
|
|
24
47
|
const src = $("img").attr("src");
|
|
25
48
|
expect(src).toBe("http://www.github.com");
|
|
@@ -29,7 +52,7 @@ describe("resolveImages", () => {
|
|
|
29
52
|
describe("img tag with src with plus sign", () => {
|
|
30
53
|
const TEST = "<img +src=\"http://www.github.com\">";
|
|
31
54
|
test("no error occurs and return undefined", () => {
|
|
32
|
-
const $ =
|
|
55
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
33
56
|
return (0, resolveImages_1.default)("hello.md", $).then(() => {
|
|
34
57
|
const src = $("img").attr("src");
|
|
35
58
|
expect(src).toBe(undefined);
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const
|
|
30
|
+
const cheerio = __importStar(require("cheerio"));
|
|
8
31
|
const resolveLinks_1 = __importDefault(require("../resolveLinks"));
|
|
9
32
|
describe("resolveLinks", () => {
|
|
10
33
|
function resolveFileBasic(href) {
|
|
@@ -19,14 +42,14 @@ describe("resolveLinks", () => {
|
|
|
19
42
|
describe("Absolute path", () => {
|
|
20
43
|
const TEST = "<p>This is a <a href=\"/test/cool.md\"></a></p>";
|
|
21
44
|
test("should resolve path starting by \"/\" in root directory", () => {
|
|
22
|
-
const $ =
|
|
45
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
23
46
|
return (0, resolveLinks_1.default)("hello.md", resolveFileBasic, $).then(() => {
|
|
24
47
|
const link = $("a");
|
|
25
48
|
expect(link.attr("href")).toBe("fakeDir/test/cool.md");
|
|
26
49
|
});
|
|
27
50
|
});
|
|
28
51
|
test("should resolve path starting by \"/\" in child directory", () => {
|
|
29
|
-
const $ =
|
|
52
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
30
53
|
return (0, resolveLinks_1.default)("afolder/hello.md", resolveFileBasic, $).then(() => {
|
|
31
54
|
const link = $("a");
|
|
32
55
|
expect(link.attr("href")).toBe("../fakeDir/test/cool.md");
|
|
@@ -36,7 +59,7 @@ describe("resolveLinks", () => {
|
|
|
36
59
|
describe("Anchor", () => {
|
|
37
60
|
test("should prevent anchors in resolution", () => {
|
|
38
61
|
const TEST = "<p>This is a <a href=\"test/cool.md#an-anchor\"></a></p>";
|
|
39
|
-
const $ =
|
|
62
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
40
63
|
return (0, resolveLinks_1.default)("hello.md", resolveFileCustom, $).then(() => {
|
|
41
64
|
const link = $("a");
|
|
42
65
|
expect(link.attr("href")).toBe("test/cool.html#an-anchor");
|
|
@@ -44,7 +67,7 @@ describe("resolveLinks", () => {
|
|
|
44
67
|
});
|
|
45
68
|
test("should ignore pure anchor links", () => {
|
|
46
69
|
const TEST = "<p>This is a <a href=\"#an-anchor\"></a></p>";
|
|
47
|
-
const $ =
|
|
70
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
48
71
|
return (0, resolveLinks_1.default)("hello.md", resolveFileCustom, $).then(() => {
|
|
49
72
|
const link = $("a");
|
|
50
73
|
expect(link.attr("href")).toBe("#an-anchor");
|
|
@@ -54,14 +77,14 @@ describe("resolveLinks", () => {
|
|
|
54
77
|
describe("Custom Resolver", () => {
|
|
55
78
|
const TEST = "<p>This is a <a href=\"/test/cool.md\"></a> <a href=\"afile.png\"></a></p>";
|
|
56
79
|
test("should resolve path correctly for absolute path", () => {
|
|
57
|
-
const $ =
|
|
80
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
58
81
|
return (0, resolveLinks_1.default)("hello.md", resolveFileCustom, $).then(() => {
|
|
59
82
|
const link = $("a").first();
|
|
60
83
|
expect(link.attr("href")).toBe("test/cool.html");
|
|
61
84
|
});
|
|
62
85
|
});
|
|
63
86
|
test("should resolve path correctly for absolute path (2)", () => {
|
|
64
|
-
const $ =
|
|
87
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
65
88
|
return (0, resolveLinks_1.default)("afodler/hello.md", resolveFileCustom, $).then(() => {
|
|
66
89
|
const link = $("a").first();
|
|
67
90
|
expect(link.attr("href")).toBe("../test/cool.html");
|
|
@@ -71,7 +94,7 @@ describe("resolveLinks", () => {
|
|
|
71
94
|
describe("External link", () => {
|
|
72
95
|
const TEST = "<p>This is a <a href=\"http://www.github.com\">external link</a></p>";
|
|
73
96
|
test("should have target=\"_blank\" attribute", () => {
|
|
74
|
-
const $ =
|
|
97
|
+
const $ = cheerio.load(TEST, { _useHtmlParser2: true });
|
|
75
98
|
return (0, resolveLinks_1.default)("hello.md", resolveFileBasic, $).then(() => {
|
|
76
99
|
const link = $("a");
|
|
77
100
|
expect(link.attr("target")).toBe("_blank");
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
29
|
+
const cheerio = __importStar(require("cheerio"));
|
|
7
30
|
const tmp_1 = __importDefault(require("tmp"));
|
|
8
31
|
const svgToImg_1 = __importDefault(require("../svgToImg"));
|
|
9
32
|
describe("svgToImg", () => {
|
|
@@ -12,7 +35,7 @@ describe("svgToImg", () => {
|
|
|
12
35
|
dir = tmp_1.default.dirSync();
|
|
13
36
|
});
|
|
14
37
|
test("should write svg as a file", () => {
|
|
15
|
-
const $ =
|
|
38
|
+
const $ = cheerio.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>', { _useHtmlParser2: true });
|
|
16
39
|
return (0, svgToImg_1.default)(dir.name, "index.html", $).then(() => {
|
|
17
40
|
const $img = $("img");
|
|
18
41
|
const src = $img.attr("src");
|
|
@@ -20,7 +43,7 @@ describe("svgToImg", () => {
|
|
|
20
43
|
});
|
|
21
44
|
});
|
|
22
45
|
it("should not write icon svg as a file", () => {
|
|
23
|
-
const $ =
|
|
46
|
+
const $ = cheerio.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1" fill="currentColor"><rect width="200" height="100" stroke-width="6"/></svg>', { _useHtmlParser2: true });
|
|
24
47
|
return (0, svgToImg_1.default)(dir.name, "index.html", $).then(() => {
|
|
25
48
|
// @ts-expect-error
|
|
26
49
|
expect($.contains("img")).toBe(false);
|
|
@@ -11,10 +11,11 @@ function pregQuote(str) {
|
|
|
11
11
|
}
|
|
12
12
|
function replaceText($, el, search, replace, text_only) {
|
|
13
13
|
return $(el).each(function () {
|
|
14
|
-
let node = this.firstChild
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
let node = this.firstChild;
|
|
15
|
+
let val;
|
|
16
|
+
let new_val;
|
|
17
17
|
// Only continue if firstChild exists.
|
|
18
|
+
const replaceMap = new Map();
|
|
18
19
|
if (node) {
|
|
19
20
|
// Loop over all childNodes.
|
|
20
21
|
while (node) {
|
|
@@ -22,16 +23,18 @@ function replaceText($, el, search, replace, text_only) {
|
|
|
22
23
|
if (node.nodeType === 3) {
|
|
23
24
|
// The original node value.
|
|
24
25
|
val = node.nodeValue;
|
|
25
|
-
// The new value.
|
|
26
26
|
new_val = val.replace(search, replace);
|
|
27
27
|
// Only replace text if the new value is actually different!
|
|
28
28
|
if (new_val !== val) {
|
|
29
29
|
if (!text_only && /</.test(new_val)) {
|
|
30
|
-
// The new value contains HTML, set it in a slower but far more
|
|
31
|
-
// robust way.
|
|
32
|
-
$(node).before(new_val);
|
|
30
|
+
// The new value contains HTML, set it in a slower but far more // robust way.
|
|
33
31
|
// Don't remove the node yet, or the loop will lose its place.
|
|
34
|
-
|
|
32
|
+
const currentTextNode = $(node);
|
|
33
|
+
const newHTML = val.replace(val, new_val);
|
|
34
|
+
if (newHTML !== val) {
|
|
35
|
+
// should not replace in looping, keep it in map
|
|
36
|
+
replaceMap.set(currentTextNode, newHTML);
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
39
|
else {
|
|
37
40
|
// The new value contains no HTML, so it can be set in this
|
|
@@ -43,9 +46,11 @@ function replaceText($, el, search, replace, text_only) {
|
|
|
43
46
|
node = node.nextSibling;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
// replace nodes after looping
|
|
50
|
+
for (const [node, newHTML] of replaceMap.entries()) {
|
|
51
|
+
node.replaceWith(newHTML);
|
|
52
|
+
}
|
|
53
|
+
replaceMap.clear(); // clean up
|
|
49
54
|
});
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -7,7 +30,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
7
30
|
const fs_1 = __importDefault(require("../../utils/fs"));
|
|
8
31
|
const location_1 = __importDefault(require("../../utils/location"));
|
|
9
32
|
const editHTMLElement_1 = __importDefault(require("./editHTMLElement"));
|
|
10
|
-
const
|
|
33
|
+
const cheerio = __importStar(require("cheerio"));
|
|
11
34
|
/**
|
|
12
35
|
Inline SVG images as needed
|
|
13
36
|
|
|
@@ -26,7 +49,7 @@ function inlineSvg(rootFolder, currentFile, $) {
|
|
|
26
49
|
src = location_1.default.toAbsolute(src, currentDirectory, ".");
|
|
27
50
|
const inputPath = path_1.default.join(rootFolder, src);
|
|
28
51
|
return fs_1.default.readFile(inputPath).then((svgContext) => {
|
|
29
|
-
const $ =
|
|
52
|
+
const $ = cheerio.load(svgContext, { _useHtmlParser2: true, xmlMode: true });
|
|
30
53
|
const $svg = $("svg");
|
|
31
54
|
if ($svg.attr("style")) {
|
|
32
55
|
return;
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
29
|
+
const cheerio = __importStar(require("cheerio"));
|
|
7
30
|
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
8
31
|
/**
|
|
9
32
|
Apply a list of operations to a page and
|
|
@@ -15,7 +38,7 @@ const promise_1 = __importDefault(require("../../utils/promise"));
|
|
|
15
38
|
*/
|
|
16
39
|
function modifyHTML(page, operations) {
|
|
17
40
|
const html = page.getContent();
|
|
18
|
-
const $ =
|
|
41
|
+
const $ = cheerio.load(html, { _useHtmlParser2: true });
|
|
19
42
|
return promise_1.default.forEach(operations, (op) => {
|
|
20
43
|
return op($);
|
|
21
44
|
}).then(() => {
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
|
@@ -26,7 +26,7 @@ function validatePlugin(plugin) {
|
|
|
26
26
|
const honkitVersion = packageInfos.get("engines").get("honkit");
|
|
27
27
|
// support "gitbook" and "honkit"
|
|
28
28
|
if (gitbookVersion && !honkit_1.default.satisfies(gitbookVersion)) {
|
|
29
|
-
return promise_1.default.reject(new Error(`HonKit doesn't satisfy the requirements of this plugin: ${pluginName} require ${
|
|
29
|
+
return promise_1.default.reject(new Error(`HonKit doesn't satisfy the requirements of this plugin: ${pluginName} require ${gitbookVersion}`));
|
|
30
30
|
}
|
|
31
31
|
if (honkitVersion && !honkit_1.default.satisfies(honkitVersion)) {
|
|
32
32
|
return promise_1.default.reject(new Error(`HonKit doesn't satisfy the requirements of this plugin: ${pluginName} require ${honkitVersion}`));
|
|
@@ -16,26 +16,23 @@ describe("ConrefsLoader", () => {
|
|
|
16
16
|
loader: new conrefsLoader_1.default(dirName),
|
|
17
17
|
});
|
|
18
18
|
test("should include content from git", () => {
|
|
19
|
-
jest.setTimeout(20 * 1000);
|
|
20
19
|
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
21
20
|
return (0, render_1.default)(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}').then((out) => {
|
|
22
21
|
expect(out.getContent()).toBe("Hello from git");
|
|
23
22
|
});
|
|
24
|
-
});
|
|
23
|
+
}, 60 * 1000);
|
|
25
24
|
test("should handle deep inclusion (1)", () => {
|
|
26
|
-
jest.setTimeout(20 * 1000);
|
|
27
25
|
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
28
26
|
return (0, render_1.default)(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}').then((out) => {
|
|
29
27
|
expect(out.getContent()).toBe("First Hello. Hello from git");
|
|
30
28
|
});
|
|
31
|
-
});
|
|
29
|
+
}, 60 * 1000);
|
|
32
30
|
test("should handle deep inclusion (2)", () => {
|
|
33
|
-
jest.setTimeout(20 * 1000);
|
|
34
31
|
// @ts-expect-error ts-migrate(2554) FIXME: Expected 4 arguments, but got 3.
|
|
35
32
|
return (0, render_1.default)(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}').then((out) => {
|
|
36
33
|
expect(out.getContent()).toBe("First Hello. Hello from git");
|
|
37
34
|
});
|
|
38
|
-
});
|
|
35
|
+
}, 60 * 1000);
|
|
39
36
|
});
|
|
40
37
|
describe("Local", () => {
|
|
41
38
|
const engine = new templateEngine_1.default({
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
const git_1 = __importDefault(require("../git"));
|
|
8
8
|
describe("Git", () => {
|
|
9
|
-
jest.setTimeout(30 * 1000);
|
|
10
9
|
describe("URL parsing", () => {
|
|
11
10
|
test("should correctly validate git urls", () => {
|
|
12
11
|
// HTTPS
|
|
@@ -16,25 +15,25 @@ describe("Git", () => {
|
|
|
16
15
|
// Non valid
|
|
17
16
|
expect(git_1.default.isUrl("https://github.com/Hello/world.git")).toBeFalsy();
|
|
18
17
|
expect(git_1.default.isUrl("README.md")).toBeFalsy();
|
|
19
|
-
});
|
|
18
|
+
}, 60 * 1000);
|
|
20
19
|
test("should parse HTTPS urls", () => {
|
|
21
20
|
const parts = git_1.default.parseUrl("git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md");
|
|
22
21
|
expect(parts.host).toBe("https://gist.github.com/69ea4542e4c8967d2fa7.git");
|
|
23
22
|
expect(parts.ref).toBe(null);
|
|
24
23
|
expect(parts.filepath).toBe("test.md");
|
|
25
|
-
});
|
|
24
|
+
}, 60 * 1000);
|
|
26
25
|
test("should parse HTTPS urls with a reference", () => {
|
|
27
26
|
const parts = git_1.default.parseUrl("git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md#1.0.0");
|
|
28
27
|
expect(parts.host).toBe("https://gist.github.com/69ea4542e4c8967d2fa7.git");
|
|
29
28
|
expect(parts.ref).toBe("1.0.0");
|
|
30
29
|
expect(parts.filepath).toBe("test.md");
|
|
31
|
-
});
|
|
30
|
+
}, 60 * 1000);
|
|
32
31
|
test("should parse SSH urls", () => {
|
|
33
32
|
const parts = git_1.default.parseUrl("git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1");
|
|
34
33
|
expect(parts.host).toBe("git@github.com:GitbookIO/gitbook.git");
|
|
35
34
|
expect(parts.ref).toBe("e1594cde2c32e4ff48f6c4eff3d3d461743d74e1");
|
|
36
35
|
expect(parts.filepath).toBe("directory/README.md");
|
|
37
|
-
});
|
|
36
|
+
}, 60 * 1000);
|
|
38
37
|
});
|
|
39
38
|
describe("Cloning and resolving", () => {
|
|
40
39
|
test("should clone an HTTPS url", () => {
|
|
@@ -42,6 +41,6 @@ describe("Git", () => {
|
|
|
42
41
|
return git.resolve("git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md").then((filename) => {
|
|
43
42
|
expect(path_1.default.extname(filename)).toBe(".md");
|
|
44
43
|
});
|
|
45
|
-
});
|
|
44
|
+
}, 60 * 1000);
|
|
46
45
|
});
|
|
47
46
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "honkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "HonKit is building beautiful books using Markdown.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"git",
|
|
@@ -19,16 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"author": "azu <azuciao@gmail.com>",
|
|
22
|
-
"contributors": [
|
|
23
|
-
{
|
|
24
|
-
"name": "Aaron O'Mullan",
|
|
25
|
-
"email": "aaron@gitbook.com"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"name": "Samy Pessé",
|
|
29
|
-
"email": "samy@gitbook.com"
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
22
|
"main": "lib/index.js",
|
|
33
23
|
"browser": "./lib/browser.js",
|
|
34
24
|
"bin": {
|
|
@@ -47,12 +37,12 @@
|
|
|
47
37
|
"updateSnapshot": "jest src -u"
|
|
48
38
|
},
|
|
49
39
|
"dependencies": {
|
|
50
|
-
"@honkit/asciidoc": "^
|
|
51
|
-
"@honkit/honkit-plugin-highlight": "^
|
|
52
|
-
"@honkit/honkit-plugin-theme-default": "^
|
|
53
|
-
"@honkit/markdown-legacy": "^
|
|
40
|
+
"@honkit/asciidoc": "^4.0.1",
|
|
41
|
+
"@honkit/honkit-plugin-highlight": "^4.0.0",
|
|
42
|
+
"@honkit/honkit-plugin-theme-default": "^4.0.1",
|
|
43
|
+
"@honkit/markdown-legacy": "^4.0.1",
|
|
54
44
|
"bash-color": "^0.0.4",
|
|
55
|
-
"cheerio": "^0.
|
|
45
|
+
"cheerio": "^1.0.0-rc.12",
|
|
56
46
|
"chokidar": "^3.3.0",
|
|
57
47
|
"commander": "^5.1.0",
|
|
58
48
|
"cp": "^0.2.0",
|
|
@@ -72,7 +62,6 @@
|
|
|
72
62
|
"gitbook-plugin-lunr": "^1.2.0",
|
|
73
63
|
"gitbook-plugin-search": "^2.2.1",
|
|
74
64
|
"github-slugid": "^1.0.1",
|
|
75
|
-
"global-npm": "^0.4.0",
|
|
76
65
|
"i18n-t": "^1.0.1",
|
|
77
66
|
"ignore": "^5.1.8",
|
|
78
67
|
"immutable": "^3.8.1",
|
|
@@ -80,7 +69,7 @@
|
|
|
80
69
|
"js-yaml": "^3.6.1",
|
|
81
70
|
"json-schema-defaults": "^0.1.1",
|
|
82
71
|
"jsonschema": "1.1.0",
|
|
83
|
-
"juice": "^
|
|
72
|
+
"juice": "^8.0.0",
|
|
84
73
|
"lru_map": "^0.4.1",
|
|
85
74
|
"memoize-one": "^5.1.1",
|
|
86
75
|
"mkdirp": "^1.0.4",
|
|
@@ -102,14 +91,14 @@
|
|
|
102
91
|
"urijs": "^1.19.6"
|
|
103
92
|
},
|
|
104
93
|
"devDependencies": {
|
|
105
|
-
"@honkit/internal-test-utils": "^
|
|
94
|
+
"@honkit/internal-test-utils": "^4.0.0",
|
|
106
95
|
"@relmify/jest-serializer-strip-ansi": "^1.0.2",
|
|
107
96
|
"@types/nunjucks": "^3.1.3",
|
|
108
97
|
"cross-env": "^7.0.3",
|
|
109
|
-
"jest": "^
|
|
110
|
-
"jest-mock-process": "^
|
|
98
|
+
"jest": "^29.0.3",
|
|
99
|
+
"jest-mock-process": "^2.0.0",
|
|
111
100
|
"rimraf": "^3.0.2",
|
|
112
101
|
"typescript": "^4.1.3"
|
|
113
102
|
},
|
|
114
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "422e59c878e8c3a65c6b80818c579a45b6647d3c"
|
|
115
104
|
}
|