@mdxport/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -0
- package/bin/mdxport +46 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# mdxport
|
|
2
|
+
|
|
3
|
+
Markdown to PDF via [Typst](https://typst.app). Single binary, no dependencies.
|
|
4
|
+
|
|
5
|
+
- LaTeX math support (`$E = mc^2$`, `\frac{a}{b}`)
|
|
6
|
+
- Built-in templates or bring your own `.typ`
|
|
7
|
+
- YAML frontmatter (title, author, language, TOC)
|
|
8
|
+
- Watch mode — recompile on file change
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
# npm (recommended)
|
|
14
|
+
npm install -g @mdxport/cli
|
|
15
|
+
|
|
16
|
+
# or via npx (no install)
|
|
17
|
+
npx @mdxport/cli input.md -o output.pdf
|
|
18
|
+
|
|
19
|
+
# or cargo
|
|
20
|
+
cargo install mdxport
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## CLI Usage
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
# Basic conversion
|
|
27
|
+
mdxport input.md -o output.pdf
|
|
28
|
+
|
|
29
|
+
# Choose a style
|
|
30
|
+
mdxport input.md -s classic-editorial
|
|
31
|
+
|
|
32
|
+
# Custom template
|
|
33
|
+
mdxport input.md --template my_style.typ
|
|
34
|
+
|
|
35
|
+
# Override metadata
|
|
36
|
+
mdxport input.md -t "My Title" -a "Author Name" --lang zh
|
|
37
|
+
|
|
38
|
+
# Watch mode
|
|
39
|
+
mdxport input.md -w
|
|
40
|
+
|
|
41
|
+
# Multiple files
|
|
42
|
+
mdxport chapter1.md chapter2.md -o output_dir/
|
|
43
|
+
|
|
44
|
+
# From stdin
|
|
45
|
+
cat input.md | mdxport -o output.pdf
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Frontmatter
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
---
|
|
52
|
+
title: "Document Title"
|
|
53
|
+
author: "Single Author"
|
|
54
|
+
# or multiple:
|
|
55
|
+
authors:
|
|
56
|
+
- Alice
|
|
57
|
+
- Bob
|
|
58
|
+
lang: zh # auto-detected if omitted
|
|
59
|
+
toc: true
|
|
60
|
+
---
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Custom Templates
|
|
64
|
+
|
|
65
|
+
Templates are Typst files that define an `#article` function:
|
|
66
|
+
|
|
67
|
+
```typst
|
|
68
|
+
#let article(
|
|
69
|
+
title: none,
|
|
70
|
+
authors: (),
|
|
71
|
+
lang: "en",
|
|
72
|
+
toc: false,
|
|
73
|
+
body,
|
|
74
|
+
) = {
|
|
75
|
+
// your styling here
|
|
76
|
+
body
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
See `src/template/modern_tech.typ` and `src/template/classic_editorial.typ` for examples.
|
|
81
|
+
|
|
82
|
+
## Architecture
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
Markdown ──comrak──→ AST ──convert──→ Typst markup
|
|
86
|
+
│
|
|
87
|
+
LaTeX math ──tex2typst-rs──→ Typst math
|
|
88
|
+
│
|
|
89
|
+
template ──compose──→ full .typ source
|
|
90
|
+
│
|
|
91
|
+
typst crate ──compile──→ PDF bytes
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|
package/bin/mdxport
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const PLATFORMS = {
|
|
8
|
+
"darwin-arm64": "@mdxport/darwin-arm64",
|
|
9
|
+
"darwin-x64": "@mdxport/darwin-x64",
|
|
10
|
+
"linux-x64": "@mdxport/linux-x64",
|
|
11
|
+
"linux-arm64": "@mdxport/linux-arm64",
|
|
12
|
+
"win32-x64": "@mdxport/win32-x64",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function getBinary() {
|
|
16
|
+
const platform = `${process.platform}-${process.arch}`;
|
|
17
|
+
const pkg = PLATFORMS[platform];
|
|
18
|
+
|
|
19
|
+
if (!pkg) {
|
|
20
|
+
console.error(
|
|
21
|
+
`mdxport: unsupported platform ${platform}\n` +
|
|
22
|
+
`Supported: ${Object.keys(PLATFORMS).join(", ")}\n` +
|
|
23
|
+
`Try: cargo install mdxport`
|
|
24
|
+
);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const pkgDir = path.dirname(require.resolve(`${pkg}/package.json`));
|
|
30
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
31
|
+
const bin = path.join(pkgDir, `mdxport${ext}`);
|
|
32
|
+
if (fs.existsSync(bin)) return bin;
|
|
33
|
+
} catch {}
|
|
34
|
+
|
|
35
|
+
console.error(
|
|
36
|
+
`mdxport: platform package ${pkg} not installed.\n` +
|
|
37
|
+
`Try reinstalling: npm install -g mdxport\n` +
|
|
38
|
+
`Or use cargo: cargo install mdxport`
|
|
39
|
+
);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const result = spawnSync(getBinary(), process.argv.slice(2), {
|
|
44
|
+
stdio: "inherit",
|
|
45
|
+
});
|
|
46
|
+
process.exit(result.status ?? 1);
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdxport/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Markdown to PDF via Typst — single binary, LaTeX math support, beautiful templates",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/cosformula/mdxport"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/cosformula/mdxport",
|
|
11
|
+
"bin": {
|
|
12
|
+
"mdxport": "bin/mdxport"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"optionalDependencies": {
|
|
19
|
+
"@mdxport/darwin-arm64": "0.1.0",
|
|
20
|
+
"@mdxport/darwin-x64": "0.1.0",
|
|
21
|
+
"@mdxport/linux-x64": "0.1.0",
|
|
22
|
+
"@mdxport/linux-arm64": "0.1.0",
|
|
23
|
+
"@mdxport/win32-x64": "0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"markdown",
|
|
27
|
+
"pdf",
|
|
28
|
+
"typst",
|
|
29
|
+
"converter",
|
|
30
|
+
"latex",
|
|
31
|
+
"md2pdf",
|
|
32
|
+
"markdown-to-pdf"
|
|
33
|
+
]
|
|
34
|
+
}
|