Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
31–40 of 58 posts
Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
#32Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
#33I've worked on PAIP, Paradigms of Artificial Intelligence Programming, and I might be able to help you a bit. It's around 1k pages long. I used Pandoc to generate an epub file, and then Calibre to turn that into a PDF file. I just tried using Pandoc to generate the PDF file directly, and it/LaTeX choked on some Unicode characters.
For internal ebook links, there's a Lua script. You'll have to keep anchors unique across the book for this:
* good: "chapter1#section1_1" and "chapter2#section2_1"
* bad: a "chapter1#section1" and a "chapter2#section1"
WIP: https://github.com/norvig/paip-lisp/pull/195
For line wrapping of code, there's CSS. I first used it over on "Writing an Operating System in 1,000 Lines"; here's the PR: https://github.com/nuta/operating-system-in-1000-lines/pull/...
Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
#34Have you explored the AST (abstract syntax tree) tools yet, like Mdast and the related remark and micromark? https://github.com/syntax-tree/mdast-util-from-markdown It might work better if you parse it into an intermediary Mdast format first, do whatever processing you need to implement "pages" (not a part of any Markdown dialect I'm familiar with?" but it shouldn't be hard to write a custom parser for that in Mdast)…
I did a customized-MD pipeline which normalized to pandoc (extra features got encoded to pass through pandoc), obtained the pandoc JSON ast, and emitted html/latex/etc using Julia pattern matching. The code was small, and the yak shave and husbandry was worth escaping the struggle with sea of crufty candidate tools, each with assorted one-chosen-point in a high-dimensional design space, and missing features, misfeatures, gotchas, and mazes ("maybe if I combine this unmaintained plugin with that one and add a postprocess massage step over there and then maybe..." - blech).
Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
#35Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
#36Use this and add sed lines for any required non-breakyness per normal CSS, rules can be specific to @media print as required.
$ cat ~/bin/mdview
#!/bin/bash
# markdown viewer
tmpfile=.mdview.tmp-`uuidgen`.html
# start html
echo "img{margin:20px;max-width:100%}@media print{img{max-height:90%;max-width:90%;page-break-after:always}}body{margin:6em;font-family:sans}pre,code{font-weight:bold;font-size:110%;font-family:Ubuntu Mono}" >${tmpfile}
# duplicate markdown for modification
cp ${1} ${1}.mdtmp
# add extra newline after trailing :
sed -i -e 's/: \*$/:\r\r\n\n/' ${1}.mdtmp
# generate HTML from markdown
# note the --html-no-skiphtml --html-no-escapehtml allows the preservation
# of anchors within text to allow [link][#anchorname]
lowdown --html-no-skiphtml --html-no-escapehtml -thtml ${1}.mdtmp >>${tmpfile}
# remove the temporary markdown file
rm ${1}.mdtmp
# add newline before images
sed -i -e 's/Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
#37It's not marketed as a markdown-to-pdf tool, but I've found that Obsidian ( https://obsidian.md ) does an excellent job. Just create a new "vault", paste your markdown into a new note, and export to PDF.
Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
#38If you’re on a Mac or iOS you could try creating a Shortcut where you input Markdown, convert to rich text, then output as a PDF. I use Shortcuts regularly. It’s pretty easy to set up. I haven’t tried it on something as larger as 500 pages, though. YMMV
Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?
#39I would love to read your feedback how it works with MonsterWriter. 1. Download the app [01] 2. Create a new empty document 3. Insert a markdown section type 4. past your markdown code into the markdown section 5. click on "Preview & Export" 6. Configure your PDF I'm the creator of MonsterWriter. For complex markdown it probably has some shortcomings but I would love to hear what is missing for your use case. [01] ht…