Skip to content

Commit 39d4126

Browse files
committed
Added demo build of pdf and removed console outputs etc.
1 parent 9224820 commit 39d4126

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules
22
*.tgz
3-
README.pdf
3+
output

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ A collection of small handy tools for improving and converting markdown.
1313
<!-- toc -->
1414

1515
- [markdown-github-toc](#markdown-github-toc)
16+
- [markdown-to-pdf](#markdown-to-pdf)
1617

1718
<!-- tocstop -->
1819

@@ -50,3 +51,36 @@ This tools uses [markdown-toc](https://github.com/jonschlinkert/markdown-toc) in
5051
Convert markdown to PDF (and also HTML) with optional table of content.
5152

5253
Inspired by [MDPDF](https://www.npmjs.com/package/mdpdf) and [markdown-pdf](https://www.npmjs.com/package/markdown-pdf). With the improvement that you can generate a table of content (ToC) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc), and the ToC document links works correctly in the PDF even if non-latin-letter like åäö are used. Another improvement that is made compared to MDPDF is that the intermediate temporary HTML is never stored as a file unless you want it to be saved. If you choose to store the HTML it is minified before stored to disk.
54+
55+
## CLI
56+
57+
```
58+
Usage:
59+
$ markdown-to-pdf <source> [<destination>] [<options>]
60+
61+
<source> must be a markdown file, with the extension '.md'.
62+
<destination> must be a PDF file, with the extension '.pdf'
63+
if ommitted it will be named <source>.pdf
64+
65+
66+
Examples:
67+
$ markdown-to-pdf README.md
68+
$ markdown-to-pdf in.md out.pdf --toc
69+
$ markdown-to-pdf in.md out.pdf --toc --save-html out.html
70+
71+
Options:
72+
--border=<size> Border (top, left, bottom, right; default: 20mm)
73+
--border-top=<size> Top border (default: 20mm)
74+
--border-left=<size> Left border (default: 20mm)
75+
--border-bottom=<size> Bottom border (default: 20mm)
76+
--border-right=<size> Right border (default: 20mm)
77+
--format=<format> PDF size format: A0-A6, Legal, Ledger, Letter, Tabloid (Default: A4)
78+
79+
--toc Add table of content where a "toc" html comment is.
80+
--maxdepth=<depth> TOC: Use headings whose depth is at most maxdepth (default: 6)
81+
82+
--save-html=<file> Save intermediate HTML to file. if no filename is given use <source>.pdf
83+
84+
--help Display this menu
85+
--version Display the application version
86+
```

bin/markdown-to-pdf.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,40 +139,34 @@ const saveHtml = cli.flags.saveHtml !== undefined
139139

140140
const htmlFile = cli.flags.saveHtml || destination.replace(/\.pdf/, '.html')
141141

142-
console.log(htmlFile)
143-
144142
if (!isHtml(htmlFile)) {
145143
showErrorAndHelp('html file must be end with .html')
146144
}
147145

148-
// TODO: no print
149-
const cliOptions = {
150-
source,
151-
destination,
152-
maxdepth,
153-
margin,
154-
format,
155-
addToc,
156-
saveHtml,
157-
htmlFile,
158-
}
159-
160-
console.log(cliOptions)
161-
162-
// TODO: move to be separate lib file
146+
// const cliOptions = {
147+
// source,
148+
// destination,
149+
// maxdepth,
150+
// margin,
151+
// format,
152+
// addToc,
153+
// saveHtml,
154+
// htmlFile,
155+
// }
156+
//
157+
// console.log(cliOptions)
163158

164159
//
165-
// TODO: do stuff
160+
// Convert to HTML/PDF
166161
//
167162
const { Remarkable } = require('remarkable')
168163
const path = require('path')
169164
const puppeteer = require('puppeteer')
170165
const toc = require('markdown-toc')
171-
//
172166
const hljs = require('highlight.js')
173167

174168
function addTocToMarkdown(markdown, tocOptions) {
175-
return toc.insert(markdown, tocOptions) //{open: '', close: ''});
169+
return toc.insert(markdown, tocOptions)
176170
}
177171

178172
function markdownToHtml(markdown) {
@@ -235,8 +229,6 @@ function createPdf(html, pdfPath, options) {
235229
format: options.format,
236230
}
237231

238-
console.log('pdfOptions', pdfOptions)
239-
240232
return page.pdf(pdfOptions)
241233
})
242234
.then(() => {

docs/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ cd "$(dirname "$0")/.."
44

55
markdown-github-toc README.md --insert --maxdepth 1
66
markdown-github-toc docs/toc-test.md --insert
7+
8+
# Demo of markdown-to-pdf
9+
mkdir -p output
10+
markdown-to-pdf README.md output/README.pdf --save-html output/README.html --toc --maxdepth 2

0 commit comments

Comments
 (0)