@joaodotwork/md-2-pdf 1.0.2 → 1.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.
Files changed (3) hide show
  1. package/README.md +45 -65
  2. package/md_to_pdf.py +10 -4
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -1,95 +1,75 @@
1
- # Markdown to PDF Converter with Mermaid Support
1
+ # md-2-pdf
2
2
 
3
- A Python utility to convert Markdown files to PDF while properly rendering Mermaid diagrams.
3
+ A powerful CLI tool to convert Markdown files to PDF with built-in Mermaid diagram support.
4
4
 
5
- ## Features
6
-
7
- - Converts Markdown files to PDF
8
- - Properly renders Mermaid diagrams as images in the PDF
9
- - Processes individual files or entire directories
10
- - Customizable output and temporary directories
11
-
12
- ## Requirements
13
-
14
- - Python 3.6+
15
- - Node.js and npm (for Mermaid CLI)
16
- - Pandoc (for Markdown to PDF conversion)
17
- - LaTeX (XeLaTeX for PDF generation)
5
+ It automatically handles:
6
+ - **Mermaid Diagrams:** Renders `mermaid` code blocks into high-quality vector graphics (PDF) for lossless scaling.
7
+ - **PDF Generation:** Uses `xelatex` (or `weasyprint`/`wkhtmltopdf` as fallbacks) for professional PDF output.
8
+ - **Smart Formatting:** Includes improved defaults for readability (margins, fonts, links) and prevents bad page breaks (widows/orphans).
18
9
 
19
10
  ## Installation
20
11
 
21
- 1. Ensure you have Python 3.6+ installed
22
- 2. Install Node.js and npm
23
- 3. Install Pandoc: https://pandoc.org/installing.html
24
- 4. Install a LaTeX distribution like TeX Live or MiKTeX
25
- 5. Clone this repository or download the script
12
+ ### Prerequisites
26
13
 
27
- The script will automatically install the Mermaid CLI (@mermaid-js/mermaid-cli) if needed.
14
+ 1. **Node.js & npm** (Installed automatically with the package)
15
+ 2. **Python 3** (Required for the core script)
16
+ 3. **PDF Engine** (One of the following):
17
+ * **Recommended:** `xelatex` (Install via [MacTeX](https://tug.org/mactex/) on macOS or `texlive` on Linux)
18
+ * *Fallback:* `weasyprint` (`pip install weasyprint`)
28
19
 
29
- ## Usage
30
-
31
- ### Basic Usage
32
-
33
- Convert a single Markdown file to PDF:
20
+ ### Install via npm
34
21
 
35
22
  ```bash
36
- python md_to_pdf.py path/to/file.md
23
+ npm install -g @joaodotwork/md-2-pdf
37
24
  ```
38
25
 
39
- Convert all Markdown files in a directory:
26
+ ## Usage
27
+
28
+ ### Convert a File
40
29
 
41
30
  ```bash
42
- python md_to_pdf.py path/to/directory
31
+ md-2-pdf input.md
43
32
  ```
33
+ This creates `input.pdf` in the same directory.
44
34
 
45
- ### Advanced Options
35
+ ### Convert a Directory
46
36
 
47
- Specify output file or directory:
37
+ Process all `.md` files in a folder:
48
38
 
49
39
  ```bash
50
- python md_to_pdf.py path/to/input.md -o path/to/output.pdf
51
- python md_to_pdf.py path/to/input_dir -o path/to/output_dir
40
+ md-2-pdf ./docs
52
41
  ```
53
42
 
54
- Specify custom temporary directory:
43
+ ### Options
55
44
 
56
45
  ```bash
57
- python md_to_pdf.py path/to/input.md -t path/to/temp_dir
58
- ```
46
+ # Specify output location
47
+ md-2-pdf input.md -o output.pdf
59
48
 
60
- Check if all dependencies are installed:
61
-
62
- ```bash
63
- python md_to_pdf.py --check-only
49
+ # Check dependencies
50
+ md-2-pdf --check-only
64
51
  ```
65
52
 
66
- ## How It Works
67
-
68
- 1. The script reads the Markdown file and extracts Mermaid diagram code blocks
69
- 2. For each Mermaid diagram, it:
70
- - Saves the diagram code to a temporary file
71
- - Uses Mermaid CLI to render the diagram as an image
72
- - Replaces the Mermaid code block with an image reference
73
- 3. The modified Markdown with image references is saved to a temporary file
74
- 4. Pandoc converts the modified Markdown to PDF using XeLaTeX
75
-
76
- ## Example
53
+ ## Features
77
54
 
78
- Input Markdown:
55
+ - **Mermaid Support:**
56
+ ```mermaid
57
+ graph TD;
58
+ A-->B;
59
+ A-->C;
60
+ B-->D;
61
+ C-->D;
62
+ ```
63
+ Just use standard ````mermaid blocks in your markdown. Now renders as vector graphics (PDF) instead of bitmaps for perfect clarity in your PDF exports.
79
64
 
80
- ````markdown
81
- # Sample Document
65
+ - **Clean Layout:**
66
+ - Standardized font size (11pt) and line spacing (1.2).
67
+ - Blue clickable links.
68
+ - Horizontal rules (`---`) rendered as vertical space instead of lines.
69
+ - Smart page breaking rules to keep headers with content.
82
70
 
83
- Here's a diagram:
71
+ ## License
84
72
 
85
- ```mermaid
86
- flowchart TD
87
- A[Start] --> B{Decision}
88
- B -->|Yes| C[Process 1]
89
- B -->|No| D[Process 2]
90
- C --> E[End]
91
- D --> E
92
- ```
93
- ````
73
+ ISC
94
74
 
95
- This will be converted to a PDF with the diagram properly rendered.
75
+ ```
package/md_to_pdf.py CHANGED
@@ -84,7 +84,7 @@ def replace_mermaid_with_images(
84
84
  updated_content = markdown_content
85
85
 
86
86
  for i, (full_match, mermaid_code) in enumerate(mermaid_blocks):
87
- image_filename = f"{base_filename}_diagram_{i}.png"
87
+ image_filename = f"{base_filename}_diagram_{i}.pdf"
88
88
  image_path = os.path.join(output_dir, image_filename)
89
89
 
90
90
  if render_mermaid_diagram(mermaid_code, image_path):
@@ -122,6 +122,8 @@ def convert_markdown_to_pdf(
122
122
  else:
123
123
  os.makedirs(temp_dir, exist_ok=True)
124
124
 
125
+ print(f"Using temporary directory: {temp_dir}")
126
+
125
127
  # Read the markdown content
126
128
  with open(input_path, 'r') as f:
127
129
  content = f.read()
@@ -171,13 +173,17 @@ def convert_markdown_to_pdf(
171
173
  input_for_pandoc,
172
174
  '-o', output_path,
173
175
  f'--pdf-engine={pdf_engine}',
174
- '-V', 'geometry:margin=0.8in',
176
+ '-V', 'geometry:top=0.75in',
177
+ '-V', 'geometry:bottom=1in',
178
+ '-V', 'geometry:left=0.75in',
179
+ '-V', 'geometry:right=0.75in',
175
180
  '-V', 'fontsize=11pt',
176
- '-V', 'linestretch=1.2',
181
+ '-V', 'linestretch=1.0',
182
+ '-V', 'parskip=6pt',
177
183
  '-V', 'colorlinks=true',
178
184
  '-V', 'linkcolor=blue',
179
185
  '-V', 'urlcolor=blue',
180
- '-V', 'header-includes=\\renewcommand{\\rule}[2]{\\vspace{1em}}'
186
+ '-V', 'header-includes=\\renewcommand{\\rule}[2]{\\vspace{0.5em}} \\widowpenalty=10000 \\clubpenalty=10000 \\brokenpenalty=10000'
181
187
  ]
182
188
 
183
189
  try:
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@joaodotwork/md-2-pdf",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Convert markdown files to PDF with mermaid diagram support",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "md-2-pdf": "./bin/index.js"
8
8
  },
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
9
  "keywords": [
13
10
  "markdown",
14
11
  "pdf",
@@ -24,5 +21,8 @@
24
21
  "md_to_pdf.py",
25
22
  "bin/",
26
23
  "requirements.txt"
27
- ]
24
+ ],
25
+ "scripts": {
26
+ "test": "echo \"Error: no test specified\" && exit 1"
27
+ }
28
28
  }