epub2md 1.0.5
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/.github/workflows/publish-npm.yml +22 -0
- package/.github/workflows/test.yml +26 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +22 -0
- package/README.md +75 -0
- package/jest.config.js.js +5 -0
- package/lib/bin/cli.d.ts +2 -0
- package/lib/bin/cli.js +58 -0
- package/lib/bin/cli.js.map +1 -0
- package/lib/bin/convert.d.ts +23 -0
- package/lib/bin/convert.js +157 -0
- package/lib/bin/convert.js.map +1 -0
- package/lib/bin/custom.d.ts +1 -0
- package/lib/bin/custom.js +13 -0
- package/lib/bin/custom.js.map +1 -0
- package/lib/converter.d.ts +1 -0
- package/lib/converter.js +9 -0
- package/lib/converter.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/lib/mobi.d.ts +15 -0
- package/lib/mobi.js +170 -0
- package/lib/mobi.js.map +1 -0
- package/lib/parseEpub.d.ts +58 -0
- package/lib/parseEpub.js +281 -0
- package/lib/parseEpub.js.map +1 -0
- package/lib/parseEpub.spec.d.ts +1 -0
- package/lib/parseEpub.spec.js +122 -0
- package/lib/parseEpub.spec.js.map +1 -0
- package/lib/parseHTML.d.ts +7 -0
- package/lib/parseHTML.js +102 -0
- package/lib/parseHTML.js.map +1 -0
- package/lib/parseHTML.spec.d.ts +1 -0
- package/lib/parseHTML.spec.js +13 -0
- package/lib/parseHTML.spec.js.map +1 -0
- package/lib/parseLink.d.ts +7 -0
- package/lib/parseLink.js +20 -0
- package/lib/parseLink.js.map +1 -0
- package/lib/parseSection.d.ts +22 -0
- package/lib/parseSection.js +94 -0
- package/lib/parseSection.js.map +1 -0
- package/lib/types.d.ts +21 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +19 -0
- package/lib/utils.js +108 -0
- package/lib/utils.js.map +1 -0
- package/package.json +71 -0
- package/tsconfig.json +25 -0
- package/tslint.json +73 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: NPM publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish-npm:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v1
|
|
13
|
+
- uses: actions/setup-node@v1
|
|
14
|
+
with:
|
|
15
|
+
node-version: 12
|
|
16
|
+
registry-url: https://registry.npmjs.org/
|
|
17
|
+
- run: yarn
|
|
18
|
+
- run: yarn build
|
|
19
|
+
- run: yarn test
|
|
20
|
+
- run: npm publish
|
|
21
|
+
env:
|
|
22
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
node-version: [12.x]
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v1
|
|
16
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
17
|
+
uses: actions/setup-node@v1
|
|
18
|
+
with:
|
|
19
|
+
node-version: ${{ matrix.node-version }}
|
|
20
|
+
- name: install, build, and test
|
|
21
|
+
run: |
|
|
22
|
+
yarn
|
|
23
|
+
yarn build
|
|
24
|
+
yarn test
|
|
25
|
+
env:
|
|
26
|
+
CI: true
|
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
## [2.0.4](https://github.com/gaoxiaoliangz/epub-parser/compare/v2.0.3...v2.0.4) (2021-07-26)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [2.0.3](https://github.com/gaoxiaoliangz/epub-parser/compare/v2.0.2...v2.0.3) (2020-07-02)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* fix issue [#18](https://github.com/gaoxiaoliangz/epub-parser/issues/18) ([d979ff4](https://github.com/gaoxiaoliangz/epub-parser/commit/d979ff46b4dee8247af2e363f646690316505e43))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# Changelog
|
|
19
|
+
|
|
20
|
+
## v2.0.2 (2019-11-22)
|
|
21
|
+
|
|
22
|
+
- fixed <https://github.com/gaoxiaoliangz/epub-parser/issues/13>
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# 📖 epub2MD
|
|
2
|
+
|
|
3
|
+
A epub parser that also can convert epub to markdown using the command line
|
|
4
|
+
|
|
5
|
+
# Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# npm
|
|
9
|
+
npm install epub2md --save
|
|
10
|
+
# pnpm
|
|
11
|
+
pnpm add epub2md
|
|
12
|
+
# yarn
|
|
13
|
+
yarn add epub2md
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
# CLI
|
|
17
|
+
```bash
|
|
18
|
+
$ epub2md help
|
|
19
|
+
$ epub2md -u ../../fixtures/zhihu.epub
|
|
20
|
+
$ epub2md -m ../../fixtures/zhihu.epub
|
|
21
|
+
$ epub2md -i ../../fixtures/zhihu.epub
|
|
22
|
+
$ epub2md -S ../../fixtures/zhihu.epub
|
|
23
|
+
$ epub2md -s ../../fixtures/zhihu.epub
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
# Usage
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { parseEpub } from 'epub2md'
|
|
30
|
+
|
|
31
|
+
const epubObj = await parseEpub('/path/to/file.epub')
|
|
32
|
+
|
|
33
|
+
console.log('epub content:', epubObj)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## parseEpub(target: string | buffer, options?: ParserOptions): EpubObject
|
|
37
|
+
|
|
38
|
+
### target
|
|
39
|
+
|
|
40
|
+
type: `string` or `buffer`
|
|
41
|
+
|
|
42
|
+
It can be the path to the file or file's binary string or buffer
|
|
43
|
+
|
|
44
|
+
### options: `ParserOptions`
|
|
45
|
+
|
|
46
|
+
#### type(optional): 'binaryString' | 'path' | 'buffer'
|
|
47
|
+
|
|
48
|
+
It forces the parser to treat supplied target as the defined type, if not defined the parser itself will decide how to treat the file (useful when you are not sure if the path is valid).
|
|
49
|
+
|
|
50
|
+
* EpubObject
|
|
51
|
+
|
|
52
|
+
The output is an object which contains `structure`, `sections`, `info`(private property names start with `_`. I don't recommend using them, since they are subscribed to change).
|
|
53
|
+
|
|
54
|
+
`structure` is the parsed `toc` of epub file, they contain information about how the book is constructed.
|
|
55
|
+
|
|
56
|
+
`sections` is an array of chapters or sections under chapters, they are referred in `structure`. Each section object contains the raw html string and a few handy methods.
|
|
57
|
+
|
|
58
|
+
- `Section.prototype.toMarkdown`: convert to markdown object.
|
|
59
|
+
- `Section.prototype.toHtmlObjects`: convert to html object. And a note about `src` and `href`, the `src` and `href` in raw html stay untouched, but the `toHtmlObjects` method resolves `src` to base64 string, and alters `href` so that they make sense in the parsed epub. And the parsed `href` is something like `#{sectionId},{hash}`.
|
|
60
|
+
|
|
61
|
+
#### expand?: boolean
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
#### convertToMarkdown?: (htmlstr: string) => string
|
|
65
|
+
use custom convert function, you can use turndown or node-html-markdown etc.
|
|
66
|
+
|
|
67
|
+
# How to contribute
|
|
68
|
+
|
|
69
|
+
- Raise an issue in the issue section.
|
|
70
|
+
- PRs are the best.
|
|
71
|
+
|
|
72
|
+
❤️
|
|
73
|
+
|
|
74
|
+
# Credit
|
|
75
|
+
[gaoxiaoliangz/epub-parser](https://github.com/gaoxiaoliangz/epub-parser)
|
package/lib/bin/cli.d.ts
ADDED
package/lib/bin/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
var args_1 = __importDefault(require("args"));
|
|
8
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
var beauty_json_1 = require("beauty-json");
|
|
11
|
+
var __1 = require("..");
|
|
12
|
+
var convert_1 = __importDefault(require("./convert"));
|
|
13
|
+
var name = "epub2md";
|
|
14
|
+
var commands = [
|
|
15
|
+
["unzip", 'unzip epub file'],
|
|
16
|
+
['md', 'convert the epub file to markdown'],
|
|
17
|
+
["info", 'get epub file basic info'],
|
|
18
|
+
["structure", 'get epub file structure'],
|
|
19
|
+
["sections", 'get epub file sections']
|
|
20
|
+
];
|
|
21
|
+
// first define options
|
|
22
|
+
commands.forEach(function (cmd) { return args_1.default.option(cmd[0], cmd[1]); });
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
var flags = args_1.default.parse(process.argv, {
|
|
25
|
+
name: name,
|
|
26
|
+
});
|
|
27
|
+
commands.map(function (cmd) { return cmd[0]; }).some(function (cmd, i) {
|
|
28
|
+
if (flags[cmd]) {
|
|
29
|
+
run(cmd);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
i === commands.length - 1 && args_1.default.showHelp();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
function run(cmd) {
|
|
37
|
+
if (flags[cmd] === true) {
|
|
38
|
+
throw new Error(chalk_1.default.red('The command input format is incorrect!'));
|
|
39
|
+
}
|
|
40
|
+
var epubPath = flags['md'] || flags['unzip'];
|
|
41
|
+
if (epubPath) {
|
|
42
|
+
// ====== convertToMarkdown ====
|
|
43
|
+
console.log(chalk_1.default.blueBright("[".concat(name, "]: This book is currently being converted...")));
|
|
44
|
+
(new convert_1.default(epubPath)).run(flags['unzip'] && epubPath).then(function (outDir) {
|
|
45
|
+
console.log(chalk_1.default.yellowBright("[".concat(name, "]: This conversion complete! output folder: ").concat(outDir)));
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
(0, __1.parseEpub)(flags[cmd])
|
|
50
|
+
.then(function (res) {
|
|
51
|
+
console.log(chalk_1.default.greenBright("[".concat(name, "]: This book ").concat(cmd, ":")));
|
|
52
|
+
beauty_json_1.json.log(res[cmd]);
|
|
53
|
+
})
|
|
54
|
+
.catch(function (error) {
|
|
55
|
+
console.log(chalk_1.default.red(error));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":";;;;;;AAEA,8CAAuB;AACvB,gDAAyB;AACzB,aAAa;AACb,2CAAkC;AAClC,wBAA8B;AAC9B,sDAAiC;AAIjC,IAAM,IAAI,GAAG,SAAS,CAAA;AACtB,IAAM,QAAQ,GAAG;IACf,CAAC,OAAO,EAAE,iBAAiB,CAAC;IAC5B,CAAC,IAAI,EAAE,mCAAmC,CAAC;IAC3C,CAAC,MAAM,EAAE,0BAA0B,CAAC;IACpC,CAAC,WAAW,EAAE,yBAAyB,CAAC;IACxC,CAAC,UAAU,EAAE,wBAAwB,CAAC;CACvC,CAAA;AAED,uBAAuB;AACvB,QAAQ,CAAC,OAAO,CAAC,UAAC,GAAG,IAAK,OAAA,cAAI,CAAC,MAAM,CAAC,GAAG,CAAC,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P;IAED,IAAA,aAAS,EAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAClB,IAAI,CAAC,UAAC,GAAG;QACR,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,WAAW,CAAC,WAAI,IAAI,0BAAgB,GAAG,MAAG,CAAC,CAAC,CAAA;QAC9D,kBAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAc,CAAC,CAAC,CAAA;IAC/B,CAAC,CAAC;SACD,KAAK,CAAC,UAAC,KAAK;QACX,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Epub } from '../parseEpub';
|
|
2
|
+
export default class Converter {
|
|
3
|
+
epub: Epub | undefined;
|
|
4
|
+
epubFilePath: string;
|
|
5
|
+
outFileExt: string;
|
|
6
|
+
outDir: string;
|
|
7
|
+
structure: {
|
|
8
|
+
fileOutpath: string;
|
|
9
|
+
filename: string;
|
|
10
|
+
}[];
|
|
11
|
+
constructor(path: string);
|
|
12
|
+
private _checkFileType;
|
|
13
|
+
/**
|
|
14
|
+
* @description Make a path,and fix assets path;markdown maybe dont need those css style files
|
|
15
|
+
*/
|
|
16
|
+
private _makePath;
|
|
17
|
+
getManifest(unzip?: boolean): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Try to obtain a friendly output filename.
|
|
20
|
+
*/
|
|
21
|
+
private _getFileData;
|
|
22
|
+
run(unzip?: boolean): Promise<string>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var write_file_safe_1 = require("write-file-safe");
|
|
43
|
+
var node_path_1 = require("node:path");
|
|
44
|
+
var node_fs_1 = require("node:fs");
|
|
45
|
+
var __1 = require("..");
|
|
46
|
+
var custom_1 = __importDefault(require("./custom"));
|
|
47
|
+
var Converter = /** @class */ (function () {
|
|
48
|
+
function Converter(path) {
|
|
49
|
+
this.outFileExt = '.md'; // out file extname
|
|
50
|
+
this.structure = []; // epub dir structure
|
|
51
|
+
this.epubFilePath = path;
|
|
52
|
+
this.outDir = (0, node_path_1.dirname)(path);
|
|
53
|
+
if (!(0, node_fs_1.existsSync)(this.outDir))
|
|
54
|
+
(0, node_fs_1.mkdirSync)(this.outDir);
|
|
55
|
+
}
|
|
56
|
+
Converter.prototype._checkFileType = function (filepath) {
|
|
57
|
+
var isImage, isCSS, isHTML = false;
|
|
58
|
+
var ext = (0, node_path_1.extname)(filepath);
|
|
59
|
+
if (',.jpg,.jpeg,.png,.gif,.webp,.svg'.indexOf(ext) > 0)
|
|
60
|
+
isImage = true;
|
|
61
|
+
if (',.css'.indexOf(ext) > 0)
|
|
62
|
+
isCSS = true;
|
|
63
|
+
if ('.htm,.html,.xhtml'.indexOf(ext) > 0)
|
|
64
|
+
isHTML = true;
|
|
65
|
+
return {
|
|
66
|
+
isImage: isImage,
|
|
67
|
+
isCSS: isCSS,
|
|
68
|
+
isHTML: isHTML,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* @description Make a path,and fix assets path;markdown maybe dont need those css style files
|
|
73
|
+
*/
|
|
74
|
+
Converter.prototype._makePath = function (filepath) {
|
|
75
|
+
var _a = this._checkFileType(filepath), isImage = _a.isImage, isCSS = _a.isCSS, isHTML = _a.isHTML;
|
|
76
|
+
if (isCSS)
|
|
77
|
+
return;
|
|
78
|
+
var fileName = (0, node_path_1.basename)(filepath);
|
|
79
|
+
return (0, node_path_1.join)(this.outDir, isImage ? 'images' : '', // isCss ? 'styles' :
|
|
80
|
+
isHTML ? fileName.replace(/\.x?html?$/, this.outFileExt) : fileName);
|
|
81
|
+
};
|
|
82
|
+
Converter.prototype.getManifest = function (unzip) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var _a;
|
|
85
|
+
var _this = this;
|
|
86
|
+
return __generator(this, function (_b) {
|
|
87
|
+
switch (_b.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
_a = this;
|
|
90
|
+
return [4 /*yield*/, (0, __1.parseEpub)(this.epubFilePath, {
|
|
91
|
+
convertToMarkdown: custom_1.default
|
|
92
|
+
})];
|
|
93
|
+
case 1:
|
|
94
|
+
_a.epub = _b.sent();
|
|
95
|
+
this.outDir = this.epubFilePath.replace('.epub', '');
|
|
96
|
+
this.epub.getManifest().forEach(function (_a) {
|
|
97
|
+
var filename = _a.href, id = _a.id;
|
|
98
|
+
var fileOutpath;
|
|
99
|
+
if (unzip) {
|
|
100
|
+
fileOutpath = (0, node_path_1.join)(_this.outDir, filename);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
if (id === 'ncx' || id === 'titlepage')
|
|
104
|
+
return;
|
|
105
|
+
fileOutpath = _this._makePath(filename);
|
|
106
|
+
}
|
|
107
|
+
fileOutpath &&
|
|
108
|
+
_this.structure.push({
|
|
109
|
+
fileOutpath: fileOutpath,
|
|
110
|
+
filename: filename,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Try to obtain a friendly output filename.
|
|
120
|
+
*/
|
|
121
|
+
Converter.prototype._getFileData = function (index, filename, outpath) {
|
|
122
|
+
var content = this.epub.resolve(filename).asNodeBuffer();
|
|
123
|
+
if (((0, node_path_1.extname)(outpath) === '.md')) {
|
|
124
|
+
content = this.epub.sections[index].toMarkdown();
|
|
125
|
+
var tempRes = content.match(/#+?\s+(.*?)\n/);
|
|
126
|
+
outpath = (0, node_path_1.join)((0, node_path_1.dirname)(outpath), (tempRes && tempRes[1].replace(/\//g, '_')) + this.outFileExt);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
content: content,
|
|
130
|
+
outFilePath: outpath
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
Converter.prototype.run = function (unzip) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var _this = this;
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0: return [4 /*yield*/, this.getManifest(unzip)];
|
|
139
|
+
case 1:
|
|
140
|
+
_a.sent();
|
|
141
|
+
this.structure.forEach(function (_a, i) {
|
|
142
|
+
var fileOutpath = _a.fileOutpath, filename = _a.filename;
|
|
143
|
+
console.log("...[filename]:".concat(filename, "..."));
|
|
144
|
+
var _b = _this._getFileData(i, filename, fileOutpath), outFilePath = _b.outFilePath, content = _b.content;
|
|
145
|
+
(0, write_file_safe_1.writeFileSync)(outFilePath,
|
|
146
|
+
// @ts-ignore-expect
|
|
147
|
+
content);
|
|
148
|
+
});
|
|
149
|
+
return [2 /*return*/, this.outDir];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
return Converter;
|
|
155
|
+
}());
|
|
156
|
+
exports.default = Converter;
|
|
157
|
+
//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F,sBAAO,IAAI,CAAC,MAAM,EAAA;;;;KACnB;IACH,gBAAC;AAAD,CAAC,AAlGD,IAkGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (htmlString: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var converter_1 = require("../converter");
|
|
4
|
+
function default_1(htmlString) {
|
|
5
|
+
var prunedHtml = htmlString
|
|
6
|
+
.replace(/()/g, '()')
|
|
7
|
+
.replace(/::/g, '::')
|
|
8
|
+
.replace(/<pre class="ziti1">([\s\S]*?)<\/pre>/g, '<pre><code class="language-rust">$1</code></pre>')
|
|
9
|
+
.replace(/<img.*?src="(.*?)"/, '<img src="images/$1"');
|
|
10
|
+
return (0, converter_1.convert)(prunedHtml);
|
|
11
|
+
}
|
|
12
|
+
exports.default = default_1;
|
|
13
|
+
//# sourceMappingURL=custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/bin/custom.ts"],"names":[],"mappings":";;AACA,0CAAsC;AAEtC,mBAAwB,UAAkB;IACxC,IAAM,UAAU,GAAG,UAAU;SAC1B,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC;SACpB,OAAO,CAAC,uCAAuC,EAAE,kDAAkD,CAAC;SACpG,OAAO,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAA;IACxD,OAAO,IAAA,mBAAO,EAAC,UAAU,CAAC,CAAA;AAC5B,CAAC;AAPD,4BAOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convert: (str: string) => string;
|
package/lib/converter.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convert = void 0;
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
// import TurndownService from 'turndown'
|
|
6
|
+
var node_html_markdown_1 = require("node-html-markdown");
|
|
7
|
+
var convert = function (str) { return (new node_html_markdown_1.NodeHtmlMarkdown()).translate(str); };
|
|
8
|
+
exports.convert = convert;
|
|
9
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AACA,aAAa;AACb,yCAAyC;AACzC,yDAAqD;AAE9C,IAAM,OAAO,GAAG,UAAC,GAAW,IAAK,OAAA,CAAC,IAAI,qCAAgB,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EAAvC,CAAuC,CAAA;AAAlE,QAAA,OAAO,WAA2D"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseEpub = exports.parseHTML = exports.parseLink = exports.convertToMarkdown = void 0;
|
|
7
|
+
var converter_1 = require("./converter");
|
|
8
|
+
Object.defineProperty(exports, "convertToMarkdown", { enumerable: true, get: function () { return converter_1.convert; } });
|
|
9
|
+
var parseEpub_1 = __importDefault(require("./parseEpub"));
|
|
10
|
+
exports.parseEpub = parseEpub_1.default;
|
|
11
|
+
var parseLink_1 = __importDefault(require("./parseLink"));
|
|
12
|
+
exports.parseLink = parseLink_1.default;
|
|
13
|
+
var parseHTML_1 = __importDefault(require("./parseHTML"));
|
|
14
|
+
exports.parseHTML = parseHTML_1.default;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAqC;AAKjB,kGALX,mBAAO,OAKqB;AAJrC,0DAAmC;AAI0B,oBAJtD,mBAAS,CAIsD;AAHtE,0DAAmC;AAGI,oBAHhC,mBAAS,CAGgC;AAFhD,0DAAmC;AAEe,oBAF3C,mBAAS,CAE2C"}
|
package/lib/mobi.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export default class Mobi {
|
|
3
|
+
filename: string;
|
|
4
|
+
info: {
|
|
5
|
+
content: string;
|
|
6
|
+
pdbHeader: {
|
|
7
|
+
records: never[];
|
|
8
|
+
};
|
|
9
|
+
mobiHeader: {};
|
|
10
|
+
};
|
|
11
|
+
constructor(filename: string);
|
|
12
|
+
parse(): this;
|
|
13
|
+
trim(data: Buffer, trailers: number, multibyte: number): Buffer;
|
|
14
|
+
palmdocReader(data: Buffer): string;
|
|
15
|
+
}
|