epub2md 1.6.0 → 1.6.2
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/bin/cli.cjs +1 -1
- package/lib/convert/convert.cjs +2 -1
- package/lib/convert/convert.mjs +4 -1
- package/lib/epub/parseEpub.cjs +2 -2
- package/lib/epub/parseEpub.mjs +1 -1
- package/lib/epub/zip.cjs +11 -1
- package/lib/epub/zip.mjs +12 -3
- package/lib/parseLink.cjs +5 -1
- package/lib/parseLink.mjs +6 -1
- package/lib/xml/index.cjs +2 -2
- package/lib/xml/index.mjs +1 -1
- package/lib/xml/meta-container.cjs +2 -2
- package/lib/xml/meta-container.mjs +1 -1
- package/package.json +2 -2
package/lib/bin/cli.cjs
CHANGED
package/lib/convert/convert.cjs
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Converter = void 0;
|
|
7
7
|
var _nodePath = require("node:path");
|
|
8
|
+
var _posix = require("node:path/posix");
|
|
8
9
|
var _logger = _interopRequireDefault(require("../logger.cjs"));
|
|
9
10
|
var iteratorHelpersPolyfill = _interopRequireWildcard(require("iterator-helpers-polyfill"));
|
|
10
11
|
var _parseEpub = _interopRequireDefault(require("../epub/parseEpub.cjs"));
|
|
@@ -79,7 +80,7 @@ class Converter {
|
|
|
79
80
|
let validPath = (0, _helper.sanitizeFileName)((0, _nodePath.extname)(internalNavName) ? internalNavName : internalNavName + ".md");
|
|
80
81
|
const file = structures.find(file2 => file2.id === sectionId);
|
|
81
82
|
if (file) validPath = (0, _nodePath.basename)(clearOutpath(file, this.epub.structure.toc).outPath);
|
|
82
|
-
const toId = this.epub.structure.opf.manifest.getItemId((0,
|
|
83
|
+
const toId = this.epub.structure.opf.manifest.getItemId((0, _posix.join)((0, _posix.dirname)(filepath), url));
|
|
83
84
|
return this.options.shouldMerge ? linkStartSep + toId + (hash ? "#" + hash : "") : linkStartSep + validPath + `${hash ? "#" + hash : ""}`;
|
|
84
85
|
} else {
|
|
85
86
|
if (link.startsWith("http")) {
|
package/lib/convert/convert.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { basename, dirname, extname, join } from "node:path";
|
|
2
|
+
import { join as posixJoin, dirname as posixDirname } from "node:path/posix";
|
|
2
3
|
import logger from "../logger.mjs";
|
|
3
4
|
import * as iteratorHelpersPolyfill from "iterator-helpers-polyfill";
|
|
4
5
|
iteratorHelpersPolyfill.installIntoGlobal();
|
|
@@ -57,7 +58,9 @@ export class Converter {
|
|
|
57
58
|
);
|
|
58
59
|
const file = structures.find((file2) => file2.id === sectionId);
|
|
59
60
|
if (file) validPath = basename(clearOutpath(file, this.epub.structure.toc).outPath);
|
|
60
|
-
const toId = this.epub.structure.opf.manifest.getItemId(
|
|
61
|
+
const toId = this.epub.structure.opf.manifest.getItemId(
|
|
62
|
+
posixJoin(posixDirname(filepath), url)
|
|
63
|
+
);
|
|
61
64
|
return this.options.shouldMerge ? linkStartSep + toId + (hash ? "#" + hash : "") : linkStartSep + validPath + `${hash ? "#" + hash : ""}`;
|
|
62
65
|
} else {
|
|
63
66
|
if (link.startsWith("http")) {
|
package/lib/epub/parseEpub.cjs
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.Epub = void 0;
|
|
7
7
|
module.exports = parse;
|
|
8
8
|
exports.defaultOptions = void 0;
|
|
9
|
-
var
|
|
9
|
+
var _posix = _interopRequireDefault(require("node:path/posix"));
|
|
10
10
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
11
11
|
var _parseSection = _interopRequireDefault(require("../parseSection.cjs"));
|
|
12
12
|
var _options = require("./options.cjs");
|
|
@@ -29,7 +29,7 @@ class Epub {
|
|
|
29
29
|
sections;
|
|
30
30
|
getFile(filePath) {
|
|
31
31
|
const isAbsolute = filePath.startsWith("/");
|
|
32
|
-
const absolutePath = isAbsolute ? filePath.slice(1) :
|
|
32
|
+
const absolutePath = isAbsolute ? filePath.slice(1) : _posix.default.join(this.structure.contentRoot, filePath);
|
|
33
33
|
const file = this.zip.getFile(absolutePath);
|
|
34
34
|
return file;
|
|
35
35
|
}
|
package/lib/epub/parseEpub.mjs
CHANGED
package/lib/epub/zip.cjs
CHANGED
|
@@ -11,7 +11,17 @@ class Zip {
|
|
|
11
11
|
this.zip = (0, _fflate.unzipSync)(fileContent);
|
|
12
12
|
}
|
|
13
13
|
getFile(path) {
|
|
14
|
-
|
|
14
|
+
let decoded;
|
|
15
|
+
try {
|
|
16
|
+
decoded = decodeURIComponent(path);
|
|
17
|
+
} catch {
|
|
18
|
+
try {
|
|
19
|
+
decoded = decodeURI(path);
|
|
20
|
+
} catch {
|
|
21
|
+
decoded = path;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const normalisedPath = decoded.replace(/\\/g, "/").replace(/^\//, "");
|
|
15
25
|
const file = this.zip[normalisedPath];
|
|
16
26
|
if (!file) throw new Error(`Error in epub. File not found: ${normalisedPath}`);
|
|
17
27
|
return {
|
package/lib/epub/zip.mjs
CHANGED
|
@@ -5,10 +5,19 @@ export class Zip {
|
|
|
5
5
|
this.zip = unzipSync(fileContent);
|
|
6
6
|
}
|
|
7
7
|
getFile(path) {
|
|
8
|
-
|
|
8
|
+
let decoded;
|
|
9
|
+
try {
|
|
10
|
+
decoded = decodeURIComponent(path);
|
|
11
|
+
} catch {
|
|
12
|
+
try {
|
|
13
|
+
decoded = decodeURI(path);
|
|
14
|
+
} catch {
|
|
15
|
+
decoded = path;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const normalisedPath = decoded.replace(/\\/g, "/").replace(/^\//, "");
|
|
9
19
|
const file = this.zip[normalisedPath];
|
|
10
|
-
if (!file)
|
|
11
|
-
throw new Error(`Error in epub. File not found: ${normalisedPath}`);
|
|
20
|
+
if (!file) throw new Error(`Error in epub. File not found: ${normalisedPath}`);
|
|
12
21
|
return {
|
|
13
22
|
asText: () => toString(file),
|
|
14
23
|
asNodeBuffer: () => Buffer.from(file)
|
package/lib/parseLink.cjs
CHANGED
|
@@ -7,7 +7,11 @@ module.exports = parseHref;
|
|
|
7
7
|
var _last2 = _interopRequireDefault(require("lodash/last"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
function parseHref(href, decode = false) {
|
|
10
|
-
if (decode)
|
|
10
|
+
if (decode) {
|
|
11
|
+
try {
|
|
12
|
+
href = decodeURIComponent(href);
|
|
13
|
+
} catch {}
|
|
14
|
+
}
|
|
11
15
|
const hash = href.split("#")[1];
|
|
12
16
|
const url = href.split("#")[0];
|
|
13
17
|
const prefix = url.split("/").slice(0, -1).join("/");
|
package/lib/parseLink.mjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import _last from "lodash/last";
|
|
2
2
|
export default function parseHref(href, decode = false) {
|
|
3
|
-
if (decode)
|
|
3
|
+
if (decode) {
|
|
4
|
+
try {
|
|
5
|
+
href = decodeURIComponent(href);
|
|
6
|
+
} catch {
|
|
7
|
+
}
|
|
8
|
+
}
|
|
4
9
|
const hash = href.split("#")[1];
|
|
5
10
|
const url = href.split("#")[0];
|
|
6
11
|
const prefix = url.split("/").slice(0, -1).join("/");
|
package/lib/xml/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "TocItem", {
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
exports.parseStructure = parseStructure;
|
|
19
|
-
var
|
|
19
|
+
var _posix = _interopRequireDefault(require("node:path/posix"));
|
|
20
20
|
var _metaContainer = require("./meta-container.cjs");
|
|
21
21
|
var _opf = require("./opf.cjs");
|
|
22
22
|
var _toc = require("./toc.cjs");
|
|
@@ -52,7 +52,7 @@ class Parse {
|
|
|
52
52
|
toc(opf, contentRoot) {
|
|
53
53
|
const relativePath = opf.manifest.getById("ncx")?.href;
|
|
54
54
|
if (!relativePath) return;
|
|
55
|
-
const fullPath =
|
|
55
|
+
const fullPath = _posix.default.join(contentRoot, relativePath);
|
|
56
56
|
const string = this.zip.getFile(fullPath).asText();
|
|
57
57
|
return (0, _toc.parseToc)(string, href => opf.manifest.getItemId(href));
|
|
58
58
|
}
|
package/lib/xml/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.parseMetaContainer = parseMetaContainer;
|
|
7
|
-
var
|
|
7
|
+
var _posix = _interopRequireDefault(require("node:path/posix"));
|
|
8
8
|
var _parseXml = require("./parseXml.cjs");
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
function parseMetaContainer(text) {
|
|
@@ -17,7 +17,7 @@ function parseMetaContainer(text) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
function getContentRoot(opfPath) {
|
|
20
|
-
let root =
|
|
20
|
+
let root = _posix.default.dirname(opfPath);
|
|
21
21
|
if (root === ".") return "";
|
|
22
22
|
if (!root.endsWith("/")) root += "/";
|
|
23
23
|
if (root.startsWith("/")) root = root.slice(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epub2md",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "A epub parser that also can convert epub to markdown using the command line",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"ts-node": "^10.9.2",
|
|
76
76
|
"tslint": "^5.19.0",
|
|
77
77
|
"typescript": "^5.9.3",
|
|
78
|
-
"unbuild": "3.
|
|
78
|
+
"unbuild": "^3.6.1",
|
|
79
79
|
"vitest": "^4.0.15",
|
|
80
80
|
"vrsource-tslint-rules": "^6.0.0"
|
|
81
81
|
},
|