@joaodotwork/md-2-pdf 1.2.0 → 1.3.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 +1 -0
- package/filters/table-fit.lua +27 -0
- package/md_to_pdf.py +6 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Most markdown-to-pdf converters struggle with diagrams or produce poorly formatt
|
|
|
19
19
|
- Standardized 11pt font and optimized line spacing.
|
|
20
20
|
- Interactive, blue clickable links.
|
|
21
21
|
- Automatic widow/orphan protection (keeps headers with content).
|
|
22
|
+
- Wide tables wrap to fit the page — pipe tables with short separator dashes (`|---|---|`) get equal column widths and wrapping cells instead of overflowing.
|
|
22
23
|
- Customizable margins and geometry.
|
|
23
24
|
- **Multi-Engine Support:** Automatically detects and uses the best available PDF engine (`xelatex`, `pdflatex`, `weasyprint`, or `wkhtmltopdf`).
|
|
24
25
|
- **Batch Processing:** Convert single files or entire directories with one command.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Assign equal column widths to tables that have none set.
|
|
2
|
+
--
|
|
3
|
+
-- Pandoc's pipe-table reader leaves column widths undefined when the
|
|
4
|
+
-- separator-row dashes are short (e.g. `|---|---|`). The LaTeX writer then
|
|
5
|
+
-- emits `l` columns, which do not wrap and overflow the page on wide tables.
|
|
6
|
+
-- Setting equal widths summing to 1.0 makes the writer emit `p{...}` columns
|
|
7
|
+
-- sized to \linewidth, so cells wrap.
|
|
8
|
+
|
|
9
|
+
function Table(tbl)
|
|
10
|
+
local n = #tbl.colspecs
|
|
11
|
+
if n == 0 then return nil end
|
|
12
|
+
|
|
13
|
+
local total = 0
|
|
14
|
+
for _, c in ipairs(tbl.colspecs) do
|
|
15
|
+
local w = c[2]
|
|
16
|
+
if type(w) == "number" then
|
|
17
|
+
total = total + w
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
if total > 0 then return nil end
|
|
21
|
+
|
|
22
|
+
local equal = 1.0 / n
|
|
23
|
+
for i = 1, n do
|
|
24
|
+
tbl.colspecs[i] = { tbl.colspecs[i][1], equal }
|
|
25
|
+
end
|
|
26
|
+
return tbl
|
|
27
|
+
end
|
package/md_to_pdf.py
CHANGED
|
@@ -167,6 +167,10 @@ def convert_markdown_to_pdf(
|
|
|
167
167
|
|
|
168
168
|
print(f"Using PDF engine: {pdf_engine}")
|
|
169
169
|
|
|
170
|
+
# Locate bundled Lua filters
|
|
171
|
+
script_dir = Path(__file__).resolve().parent
|
|
172
|
+
table_fit_filter = script_dir / 'filters' / 'table-fit.lua'
|
|
173
|
+
|
|
170
174
|
# Convert to PDF using pandoc
|
|
171
175
|
cmd = [
|
|
172
176
|
'pandoc',
|
|
@@ -174,6 +178,7 @@ def convert_markdown_to_pdf(
|
|
|
174
178
|
'-o', output_path,
|
|
175
179
|
'--from=gfm',
|
|
176
180
|
f'--pdf-engine={pdf_engine}',
|
|
181
|
+
f'--lua-filter={table_fit_filter}',
|
|
177
182
|
'-V', 'geometry:top=0.75in',
|
|
178
183
|
'-V', 'geometry:bottom=1in',
|
|
179
184
|
'-V', 'geometry:left=0.75in',
|
|
@@ -184,7 +189,7 @@ def convert_markdown_to_pdf(
|
|
|
184
189
|
'-V', 'colorlinks=true',
|
|
185
190
|
'-V', 'linkcolor=blue',
|
|
186
191
|
'-V', 'urlcolor=blue',
|
|
187
|
-
'-V', 'header-includes=\\renewcommand{\\rule}[2]{\\vspace{0.5em}} \\widowpenalty=10000 \\clubpenalty=10000 \\brokenpenalty=10000'
|
|
192
|
+
'-V', 'header-includes=\\renewcommand{\\rule}[2]{\\vspace{0.5em}} \\widowpenalty=10000 \\clubpenalty=10000 \\brokenpenalty=10000 \\setlength{\\emergencystretch}{3em} \\usepackage{newunicodechar} \\newunicodechar{·}{\\textperiodcentered\\allowbreak} \\newunicodechar{•}{\\textbullet\\allowbreak}'
|
|
188
193
|
]
|
|
189
194
|
|
|
190
195
|
try:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joaodotwork/md-2-pdf",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Convert markdown files to PDF with mermaid diagram support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"files": [
|
|
31
31
|
"md_to_pdf.py",
|
|
32
32
|
"bin/",
|
|
33
|
+
"filters/",
|
|
33
34
|
"requirements.txt"
|
|
34
35
|
]
|
|
35
36
|
}
|