@effortlessmotion/pdf-to-md 0.1.5 → 0.1.6
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/dist/cjs/cli.d.cts +0 -1
- package/dist/cjs/cli.d.ts +0 -1
- package/dist/cjs/cli.js +5 -87
- package/dist/cjs/cli.js.map +1 -1
- package/dist/esm/cli.d.ts +0 -1
- package/dist/esm/cli.js +0 -27
- package/dist/esm/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/cli.d.cts
CHANGED
package/dist/cjs/cli.d.ts
CHANGED
package/dist/cjs/cli.js
CHANGED
|
@@ -4,33 +4,17 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
_export(exports, {
|
|
14
|
-
get // Thrown errors -> exit 1 with the message verbatim; usage errors exit 2.
|
|
15
|
-
default () {
|
|
7
|
+
Object.defineProperty(exports, // Thrown errors -> exit 1 with the message verbatim; usage errors exit 2.
|
|
8
|
+
"default", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
16
11
|
return cli;
|
|
17
|
-
},
|
|
18
|
-
get isBelowNodeFloor () {
|
|
19
|
-
return isBelowNodeFloor;
|
|
20
12
|
}
|
|
21
13
|
});
|
|
22
14
|
var _nodefs = require("node:fs");
|
|
23
15
|
var _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
24
16
|
var _nodeurl = require("node:url");
|
|
25
17
|
var _indexts = require("./cli/index.js");
|
|
26
|
-
function _array_like_to_array(arr, len) {
|
|
27
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
28
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
29
|
-
return arr2;
|
|
30
|
-
}
|
|
31
|
-
function _array_with_holes(arr) {
|
|
32
|
-
if (Array.isArray(arr)) return arr;
|
|
33
|
-
}
|
|
34
18
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
35
19
|
try {
|
|
36
20
|
var info = gen[key](arg);
|
|
@@ -62,36 +46,6 @@ function _interop_require_default(obj) {
|
|
|
62
46
|
default: obj
|
|
63
47
|
};
|
|
64
48
|
}
|
|
65
|
-
function _iterable_to_array_limit(arr, i) {
|
|
66
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
67
|
-
if (_i == null) return;
|
|
68
|
-
var _arr = [];
|
|
69
|
-
var _n = true;
|
|
70
|
-
var _d = false;
|
|
71
|
-
var _s, _e;
|
|
72
|
-
try {
|
|
73
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
74
|
-
_arr.push(_s.value);
|
|
75
|
-
if (i && _arr.length === i) break;
|
|
76
|
-
}
|
|
77
|
-
} catch (err) {
|
|
78
|
-
_d = true;
|
|
79
|
-
_e = err;
|
|
80
|
-
} finally{
|
|
81
|
-
try {
|
|
82
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
83
|
-
} finally{
|
|
84
|
-
if (_d) throw _e;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return _arr;
|
|
88
|
-
}
|
|
89
|
-
function _non_iterable_rest() {
|
|
90
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
91
|
-
}
|
|
92
|
-
function _sliced_to_array(arr, i) {
|
|
93
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
94
|
-
}
|
|
95
49
|
function _ts_generator(thisArg, body) {
|
|
96
50
|
var f, y, t, _ = {
|
|
97
51
|
label: 0,
|
|
@@ -191,14 +145,6 @@ function _ts_generator(thisArg, body) {
|
|
|
191
145
|
};
|
|
192
146
|
}
|
|
193
147
|
}
|
|
194
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
195
|
-
if (!o) return;
|
|
196
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
197
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
198
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
199
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
200
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
201
|
-
}
|
|
202
148
|
// __dirname (CJS) or its ESM equivalent, then two fixed hops up to the
|
|
203
149
|
// package root. NOT `import.meta.resolve('pdf-to-md/package.json')` — Node's self-reference lookup throws ERR_MODULE_NOT_FOUND from a file this deep; a location-relative path is stable across both build targets.
|
|
204
150
|
var __dirname = _nodepath.default.dirname(typeof __filename !== 'undefined' ? __filename : (0, _nodeurl.fileURLToPath)(require("url").pathToFileURL(__filename).toString()));
|
|
@@ -212,43 +158,15 @@ function packageVersion() {
|
|
|
212
158
|
return 'unknown';
|
|
213
159
|
}
|
|
214
160
|
}
|
|
215
|
-
function isBelowNodeFloor(version, floor) {
|
|
216
|
-
var parts = function parts(v) {
|
|
217
|
-
return v.replace(/^v/, '').replace(/^>=/, '').split('.').map(Number);
|
|
218
|
-
};
|
|
219
|
-
var v = parts(version);
|
|
220
|
-
var f = parts(floor);
|
|
221
|
-
if (v.length !== 3 || f.length !== 3 || v.some(Number.isNaN) || f.some(Number.isNaN)) return null;
|
|
222
|
-
var _v = _sliced_to_array(v, 3), rMaj = _v[0], rMin = _v[1], rPat = _v[2];
|
|
223
|
-
var _f = _sliced_to_array(f, 3), fMaj = _f[0], fMin = _f[1], fPat = _f[2];
|
|
224
|
-
return rMaj !== fMaj ? rMaj < fMaj : rMin !== fMin ? rMin < fMin : rPat < fPat;
|
|
225
|
-
}
|
|
226
|
-
// Reads engines.node from package.json (kept as the single source of truth,
|
|
227
|
-
// not hardcoded here) and returns it iff process.version is below it.
|
|
228
|
-
function belowNodeFloor() {
|
|
229
|
-
var version = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.version;
|
|
230
|
-
try {
|
|
231
|
-
var _pkg_engines;
|
|
232
|
-
var pkgPath = _nodepath.default.resolve(__dirname, '..', '..', 'package.json');
|
|
233
|
-
var pkg = JSON.parse((0, _nodefs.readFileSync)(pkgPath, 'utf8'));
|
|
234
|
-
var floor = (_pkg_engines = pkg.engines) === null || _pkg_engines === void 0 ? void 0 : _pkg_engines.node;
|
|
235
|
-
if (!floor) return null;
|
|
236
|
-
return isBelowNodeFloor(version, floor) ? floor.replace(/^>=/, '') : null;
|
|
237
|
-
} catch (unused) {
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
161
|
function usage(name) {
|
|
242
162
|
return "usage: ".concat(name, " <file.pdf> [out.md] [flags...] convert a PDF to markdown\n") + " ".concat(name, " extract <file.pdf> [out.md] [flags...] (same, explicit)\n") + " ".concat(name, " render <file.pdf> <page>[-<page>] [--dpi|-d N (default 288)] [--out|-o DIR (default .)]\n") + " ".concat(name, " audit <words.jsonl> <file.md> severity-1 word-loss check\n") + " ".concat(name, " --version | --help\n") + '\n' + 'extract flags:\n' + ' --ocr force the OCR path (image-only/scanned pages)\n' + ' --no-ocr never fall back to OCR; keep sparse text output\n' + ' --pages N[-M] convert only these 1-based source pages\n' + ' --stdout write markdown to stdout instead of a file\n' + ' --json print the full QA report as JSON\n' + ' --page-markers emit a "### pN" heading per page\n' + ' --format md|txt|raw output format (default md; raw = Analysis JSON incl. the\n' + ' report; txt = reading-order plain text)\n' + ' --words-json=FILE OCR path from a recognized-word dump (offline replay)\n' + ' --debug-words=FILE dump every recognized word as JSON lines to FILE\n' + ' --dpi=N OCR render resolution (default 288; raise for tiny print or\n' + ' chart/label pages, >~400 measured worse on ordinary prose)\n' + '\n' + "extract tuning (measured defaults; see README's tuning table):\n" + ' --float-max-words=N --float-max-width=F --float-margin=F --para-gap=F\n' + ' --heading-scale=F --col-max-width=F --col-split=F --line-y-tol=F\n' + ' --line-height-ratio=F\n' + '\n' + 'examples:\n' + " ".concat(name, " book.pdf # text layer -> book.md (auto-OCR if scanned)\n") + " ".concat(name, " scan.pdf out.md --ocr --json # force OCR, print the QA report\n") + " ".concat(name, " book.pdf --pages 27-31 --stdout # re-extract a page range to stdout\n") + " ".concat(name, " render book.pdf 27 # render p27 to PNG for eyeballing (288 dpi)\n") + " ".concat(name, " audit words.jsonl book.md # check no recognized word was lost");
|
|
243
163
|
}
|
|
244
164
|
function cli(argv, name) {
|
|
245
165
|
return _async_to_generator(function() {
|
|
246
|
-
var
|
|
166
|
+
var ctx, load, err;
|
|
247
167
|
return _ts_generator(this, function(_state) {
|
|
248
168
|
switch(_state.label){
|
|
249
169
|
case 0:
|
|
250
|
-
floor = belowNodeFloor();
|
|
251
|
-
if (floor) console.error("".concat(name, ": Node ").concat(process.version, " is below the required >=").concat(floor, " — the OCR path can silently find no words instead of erroring; upgrade Node."));
|
|
252
170
|
if (argv[0] === '--version' || argv[0] === '-v') {
|
|
253
171
|
console.log(packageVersion());
|
|
254
172
|
return [
|
package/dist/cjs/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli.ts"],"sourcesContent":["// Parsing and dispatch only. Commands live in src/cli/, one file each,\n// lazy-loaded — nothing tree- or dependency-heavy may be imported at the top of this file (`render` must never load the OCR engine, `--version` must load almost nothing).\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { COMMANDS } from './cli/index.ts';\nimport type { Ctx } from './cli/types.ts';\n\n// __dirname (CJS) or its ESM equivalent, then two fixed hops up to the\n// package root. NOT `import.meta.resolve('pdf-to-md/package.json')` — Node's self-reference lookup throws ERR_MODULE_NOT_FOUND from a file this deep; a location-relative path is stable across both build targets.\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url));\n\nfunction packageVersion(): string {\n try {\n const pkgPath = path.resolve(__dirname, '..', '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { version?: string };\n return pkg.version ?? 'unknown';\n } catch {\n return 'unknown';\n }\n}\n\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli.ts"],"sourcesContent":["// Parsing and dispatch only. Commands live in src/cli/, one file each,\n// lazy-loaded — nothing tree- or dependency-heavy may be imported at the top of this file (`render` must never load the OCR engine, `--version` must load almost nothing).\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { COMMANDS } from './cli/index.ts';\nimport type { Ctx } from './cli/types.ts';\n\n// __dirname (CJS) or its ESM equivalent, then two fixed hops up to the\n// package root. NOT `import.meta.resolve('pdf-to-md/package.json')` — Node's self-reference lookup throws ERR_MODULE_NOT_FOUND from a file this deep; a location-relative path is stable across both build targets.\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url));\n\nfunction packageVersion(): string {\n try {\n const pkgPath = path.resolve(__dirname, '..', '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { version?: string };\n return pkg.version ?? 'unknown';\n } catch {\n return 'unknown';\n }\n}\n\nfunction usage(name: string): string {\n return (\n `usage: ${name} <file.pdf> [out.md] [flags...] convert a PDF to markdown\\n` +\n ` ${name} extract <file.pdf> [out.md] [flags...] (same, explicit)\\n` +\n ` ${name} render <file.pdf> <page>[-<page>] [--dpi|-d N (default 288)] [--out|-o DIR (default .)]\\n` +\n ` ${name} audit <words.jsonl> <file.md> severity-1 word-loss check\\n` +\n ` ${name} --version | --help\\n` +\n '\\n' +\n 'extract flags:\\n' +\n ' --ocr force the OCR path (image-only/scanned pages)\\n' +\n ' --no-ocr never fall back to OCR; keep sparse text output\\n' +\n ' --pages N[-M] convert only these 1-based source pages\\n' +\n ' --stdout write markdown to stdout instead of a file\\n' +\n ' --json print the full QA report as JSON\\n' +\n ` --page-markers emit a \"### pN\" heading per page\\n` +\n ' --format md|txt|raw output format (default md; raw = Analysis JSON incl. the\\n' +\n ' report; txt = reading-order plain text)\\n' +\n ' --words-json=FILE OCR path from a recognized-word dump (offline replay)\\n' +\n ' --debug-words=FILE dump every recognized word as JSON lines to FILE\\n' +\n ' --dpi=N OCR render resolution (default 288; raise for tiny print or\\n' +\n ' chart/label pages, >~400 measured worse on ordinary prose)\\n' +\n '\\n' +\n `extract tuning (measured defaults; see README's tuning table):\\n` +\n ' --float-max-words=N --float-max-width=F --float-margin=F --para-gap=F\\n' +\n ' --heading-scale=F --col-max-width=F --col-split=F --line-y-tol=F\\n' +\n ' --line-height-ratio=F\\n' +\n '\\n' +\n 'examples:\\n' +\n ` ${name} book.pdf # text layer -> book.md (auto-OCR if scanned)\\n` +\n ` ${name} scan.pdf out.md --ocr --json # force OCR, print the QA report\\n` +\n ` ${name} book.pdf --pages 27-31 --stdout # re-extract a page range to stdout\\n` +\n ` ${name} render book.pdf 27 # render p27 to PNG for eyeballing (288 dpi)\\n` +\n ` ${name} audit words.jsonl book.md # check no recognized word was lost`\n );\n}\n\n// Thrown errors -> exit 1 with the message verbatim; usage errors exit 2.\nexport default async function cli(argv: string[], name: string): Promise<void> {\n if (argv[0] === '--version' || argv[0] === '-v') {\n console.log(packageVersion());\n return;\n }\n if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {\n // No args is a usage ERROR (bare `pdf-to-md` can't do anything); asking\n // for --help is not.\n if (argv.length === 0) {\n console.error(usage(name));\n process.exit(2);\n }\n console.log(`${name} v${packageVersion()}`);\n console.log('');\n console.log(usage(name));\n return;\n }\n\n const ctx: Ctx = {\n name,\n rest: argv.slice(1),\n usageError(message) {\n console.error(message);\n process.exit(2);\n },\n };\n\n try {\n const load = COMMANDS[argv[0]];\n if (load) {\n await (await load()).default(ctx);\n } else {\n // Compat shim: `pdf-to-md file.pdf [...]` — any first word that isn't\n // a reserved command is extract's own first argument.\n ctx.rest = argv;\n await (await COMMANDS.extract()).default(ctx);\n }\n } catch (err) {\n console.error((err as Error).message);\n process.exit(1);\n }\n}\n"],"names":["cli","__dirname","path","dirname","__filename","fileURLToPath","packageVersion","pkg","pkgPath","resolve","JSON","parse","readFileSync","version","usage","name","argv","ctx","load","err","console","log","length","error","process","exit","rest","slice","usageError","message","COMMANDS","default","extract"],"mappings":"AAAA,uEAAuE;AACvE,2KAA2K;;;;;+BAyD3K,0EAA0E;AAC1E;;;eAA8BA;;;sBAzDD;+DACZ;uBACa;uBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGzB,uEAAuE;AACvE,oNAAoN;AACpN,IAAMC,YAAYC,iBAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,IAAAA,sBAAa,EAAC;AAE9F,SAASC;IACP,IAAI;YAGKC;QAFP,IAAMC,UAAUN,iBAAI,CAACO,OAAO,CAACR,WAAW,MAAM,MAAM;QACpD,IAAMM,MAAMG,KAAKC,KAAK,CAACC,IAAAA,oBAAY,EAACJ,SAAS;QAC7C,QAAOD,eAAAA,IAAIM,OAAO,cAAXN,0BAAAA,eAAe;IACxB,EAAE,eAAM;QACN,OAAO;IACT;AACF;AAEA,SAASO,MAAMC,IAAY;IACzB,OACE,AAAC,UAAc,OAALA,MAAK,wEACf,AAAC,UAAc,OAALA,MAAK,gEACf,AAAC,UAAc,OAALA,MAAK,gGACf,AAAC,UAAc,OAALA,MAAK,0EACf,AAAC,UAAc,OAALA,MAAK,2BACf,OACA,qBACA,2EACA,6EACA,qEACA,wEACA,8DACA,8DACA,sFACA,qEACA,mFACA,8EACA,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AAzC;;;;;;;;oBAEKE;oBACPC,QAAQG,KAAK,CAAC,AAACJ,IAAcU,OAAO;oBACpCL,QAAQC,IAAI,CAAC;;;;;;;;;;;IAEjB"}
|
package/dist/esm/cli.d.ts
CHANGED
package/dist/esm/cli.js
CHANGED
|
@@ -17,38 +17,11 @@ function packageVersion() {
|
|
|
17
17
|
return 'unknown';
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
// Exported so the comparison is unit-testable without spawning a subprocess
|
|
21
|
-
// with a faked Node version. null means unparseable input, not "not below".
|
|
22
|
-
export function isBelowNodeFloor(version, floor) {
|
|
23
|
-
const parts = (v)=>v.replace(/^v/, '').replace(/^>=/, '').split('.').map(Number);
|
|
24
|
-
const v = parts(version);
|
|
25
|
-
const f = parts(floor);
|
|
26
|
-
if (v.length !== 3 || f.length !== 3 || v.some(Number.isNaN) || f.some(Number.isNaN)) return null;
|
|
27
|
-
const [rMaj, rMin, rPat] = v;
|
|
28
|
-
const [fMaj, fMin, fPat] = f;
|
|
29
|
-
return rMaj !== fMaj ? rMaj < fMaj : rMin !== fMin ? rMin < fMin : rPat < fPat;
|
|
30
|
-
}
|
|
31
|
-
// Reads engines.node from package.json (kept as the single source of truth,
|
|
32
|
-
// not hardcoded here) and returns it iff process.version is below it.
|
|
33
|
-
function belowNodeFloor(version = process.version) {
|
|
34
|
-
try {
|
|
35
|
-
var _pkg_engines;
|
|
36
|
-
const pkgPath = path.resolve(__dirname, '..', '..', 'package.json');
|
|
37
|
-
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
38
|
-
const floor = (_pkg_engines = pkg.engines) === null || _pkg_engines === void 0 ? void 0 : _pkg_engines.node;
|
|
39
|
-
if (!floor) return null;
|
|
40
|
-
return isBelowNodeFloor(version, floor) ? floor.replace(/^>=/, '') : null;
|
|
41
|
-
} catch {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
20
|
function usage(name) {
|
|
46
21
|
return `usage: ${name} <file.pdf> [out.md] [flags...] convert a PDF to markdown\n` + ` ${name} extract <file.pdf> [out.md] [flags...] (same, explicit)\n` + ` ${name} render <file.pdf> <page>[-<page>] [--dpi|-d N (default 288)] [--out|-o DIR (default .)]\n` + ` ${name} audit <words.jsonl> <file.md> severity-1 word-loss check\n` + ` ${name} --version | --help\n` + '\n' + 'extract flags:\n' + ' --ocr force the OCR path (image-only/scanned pages)\n' + ' --no-ocr never fall back to OCR; keep sparse text output\n' + ' --pages N[-M] convert only these 1-based source pages\n' + ' --stdout write markdown to stdout instead of a file\n' + ' --json print the full QA report as JSON\n' + ` --page-markers emit a "### pN" heading per page\n` + ' --format md|txt|raw output format (default md; raw = Analysis JSON incl. the\n' + ' report; txt = reading-order plain text)\n' + ' --words-json=FILE OCR path from a recognized-word dump (offline replay)\n' + ' --debug-words=FILE dump every recognized word as JSON lines to FILE\n' + ' --dpi=N OCR render resolution (default 288; raise for tiny print or\n' + ' chart/label pages, >~400 measured worse on ordinary prose)\n' + '\n' + `extract tuning (measured defaults; see README's tuning table):\n` + ' --float-max-words=N --float-max-width=F --float-margin=F --para-gap=F\n' + ' --heading-scale=F --col-max-width=F --col-split=F --line-y-tol=F\n' + ' --line-height-ratio=F\n' + '\n' + 'examples:\n' + ` ${name} book.pdf # text layer -> book.md (auto-OCR if scanned)\n` + ` ${name} scan.pdf out.md --ocr --json # force OCR, print the QA report\n` + ` ${name} book.pdf --pages 27-31 --stdout # re-extract a page range to stdout\n` + ` ${name} render book.pdf 27 # render p27 to PNG for eyeballing (288 dpi)\n` + ` ${name} audit words.jsonl book.md # check no recognized word was lost`;
|
|
47
22
|
}
|
|
48
23
|
// Thrown errors -> exit 1 with the message verbatim; usage errors exit 2.
|
|
49
24
|
export default async function cli(argv, name) {
|
|
50
|
-
const floor = belowNodeFloor();
|
|
51
|
-
if (floor) console.error(`${name}: Node ${process.version} is below the required >=${floor} — the OCR path can silently find no words instead of erroring; upgrade Node.`);
|
|
52
25
|
if (argv[0] === '--version' || argv[0] === '-v') {
|
|
53
26
|
console.log(packageVersion());
|
|
54
27
|
return;
|
package/dist/esm/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli.ts"],"sourcesContent":["// Parsing and dispatch only. Commands live in src/cli/, one file each,\n// lazy-loaded — nothing tree- or dependency-heavy may be imported at the top of this file (`render` must never load the OCR engine, `--version` must load almost nothing).\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { COMMANDS } from './cli/index.ts';\nimport type { Ctx } from './cli/types.ts';\n\n// __dirname (CJS) or its ESM equivalent, then two fixed hops up to the\n// package root. NOT `import.meta.resolve('pdf-to-md/package.json')` — Node's self-reference lookup throws ERR_MODULE_NOT_FOUND from a file this deep; a location-relative path is stable across both build targets.\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url));\n\nfunction packageVersion(): string {\n try {\n const pkgPath = path.resolve(__dirname, '..', '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { version?: string };\n return pkg.version ?? 'unknown';\n } catch {\n return 'unknown';\n }\n}\n\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/cli.ts"],"sourcesContent":["// Parsing and dispatch only. Commands live in src/cli/, one file each,\n// lazy-loaded — nothing tree- or dependency-heavy may be imported at the top of this file (`render` must never load the OCR engine, `--version` must load almost nothing).\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { COMMANDS } from './cli/index.ts';\nimport type { Ctx } from './cli/types.ts';\n\n// __dirname (CJS) or its ESM equivalent, then two fixed hops up to the\n// package root. NOT `import.meta.resolve('pdf-to-md/package.json')` — Node's self-reference lookup throws ERR_MODULE_NOT_FOUND from a file this deep; a location-relative path is stable across both build targets.\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url));\n\nfunction packageVersion(): string {\n try {\n const pkgPath = path.resolve(__dirname, '..', '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { version?: string };\n return pkg.version ?? 'unknown';\n } catch {\n return 'unknown';\n }\n}\n\nfunction usage(name: string): string {\n return (\n `usage: ${name} <file.pdf> [out.md] [flags...] convert a PDF to markdown\\n` +\n ` ${name} extract <file.pdf> [out.md] [flags...] (same, explicit)\\n` +\n ` ${name} render <file.pdf> <page>[-<page>] [--dpi|-d N (default 288)] [--out|-o DIR (default .)]\\n` +\n ` ${name} audit <words.jsonl> <file.md> severity-1 word-loss check\\n` +\n ` ${name} --version | --help\\n` +\n '\\n' +\n 'extract flags:\\n' +\n ' --ocr force the OCR path (image-only/scanned pages)\\n' +\n ' --no-ocr never fall back to OCR; keep sparse text output\\n' +\n ' --pages N[-M] convert only these 1-based source pages\\n' +\n ' --stdout write markdown to stdout instead of a file\\n' +\n ' --json print the full QA report as JSON\\n' +\n ` --page-markers emit a \"### pN\" heading per page\\n` +\n ' --format md|txt|raw output format (default md; raw = Analysis JSON incl. the\\n' +\n ' report; txt = reading-order plain text)\\n' +\n ' --words-json=FILE OCR path from a recognized-word dump (offline replay)\\n' +\n ' --debug-words=FILE dump every recognized word as JSON lines to FILE\\n' +\n ' --dpi=N OCR render resolution (default 288; raise for tiny print or\\n' +\n ' chart/label pages, >~400 measured worse on ordinary prose)\\n' +\n '\\n' +\n `extract tuning (measured defaults; see README's tuning table):\\n` +\n ' --float-max-words=N --float-max-width=F --float-margin=F --para-gap=F\\n' +\n ' --heading-scale=F --col-max-width=F --col-split=F --line-y-tol=F\\n' +\n ' --line-height-ratio=F\\n' +\n '\\n' +\n 'examples:\\n' +\n ` ${name} book.pdf # text layer -> book.md (auto-OCR if scanned)\\n` +\n ` ${name} scan.pdf out.md --ocr --json # force OCR, print the QA report\\n` +\n ` ${name} book.pdf --pages 27-31 --stdout # re-extract a page range to stdout\\n` +\n ` ${name} render book.pdf 27 # render p27 to PNG for eyeballing (288 dpi)\\n` +\n ` ${name} audit words.jsonl book.md # check no recognized word was lost`\n );\n}\n\n// Thrown errors -> exit 1 with the message verbatim; usage errors exit 2.\nexport default async function cli(argv: string[], name: string): Promise<void> {\n if (argv[0] === '--version' || argv[0] === '-v') {\n console.log(packageVersion());\n return;\n }\n if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {\n // No args is a usage ERROR (bare `pdf-to-md` can't do anything); asking\n // for --help is not.\n if (argv.length === 0) {\n console.error(usage(name));\n process.exit(2);\n }\n console.log(`${name} v${packageVersion()}`);\n console.log('');\n console.log(usage(name));\n return;\n }\n\n const ctx: Ctx = {\n name,\n rest: argv.slice(1),\n usageError(message) {\n console.error(message);\n process.exit(2);\n },\n };\n\n try {\n const load = COMMANDS[argv[0]];\n if (load) {\n await (await load()).default(ctx);\n } else {\n // Compat shim: `pdf-to-md file.pdf [...]` — any first word that isn't\n // a reserved command is extract's own first argument.\n ctx.rest = argv;\n await (await COMMANDS.extract()).default(ctx);\n }\n } catch (err) {\n console.error((err as Error).message);\n process.exit(1);\n }\n}\n"],"names":["readFileSync","path","fileURLToPath","COMMANDS","__dirname","dirname","__filename","url","packageVersion","pkg","pkgPath","resolve","JSON","parse","version","usage","name","cli","argv","console","log","length","error","process","exit","ctx","rest","slice","usageError","message","load","default","extract","err"],"mappings":"AAAA,uEAAuE;AACvE,2KAA2K;AAC3K,SAASA,YAAY,QAAQ,UAAU;AACvC,OAAOC,UAAU,YAAY;AAC7B,SAASC,aAAa,QAAQ,WAAW;AACzC,SAASC,QAAQ,QAAQ,iBAAiB;AAG1C,uEAAuE;AACvE,oNAAoN;AACpN,MAAMC,YAAYH,KAAKI,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaJ,cAAc,YAAYK,GAAG;AAE7G,SAASC;IACP,IAAI;YAGKC;QAFP,MAAMC,UAAUT,KAAKU,OAAO,CAACP,WAAW,MAAM,MAA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