Live data from Hacker News

Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

news.ycombinator.com

41–50 of 58 posts

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#41
> I have a very long regular expression (email validation of course)

On a tangentially related note, I guarantee you that your regex is wrong. There is only one way to validate an email address:

Send an email to it and have them respond. Otherwise you will block some valid users.

Now of course you can make a regex that gets most email addresses, and if you're ok with that, then that's fine. But if you don't want to accidentally exclude someone, then sending email is the only way to validate it.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#42
Whoa this is weird timing - just this weekend I did a little exploration of using Svelte to create documents and eventually PDFs.

Its really just a proof of concept at this point, but it might be of interest to you (and others).

Code: https://github.com/dominicdoty/sveltedoc

Rendered: https://sveltedoc.pages.dev/

Writeup: https://www.dominicdoty.com/2025/03/02/sveltedoc/

TLDR - I've been using Asciidoc a lot at work recently and was dissatisfied with it. This was an attempt at using Svelte to generate a document as a webpage that formats well when printed (or printed to PDF). All the power of HTML+CSS+JS when you want it, but the ease of use to just write markdown when you don't.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#43
post #13

Earlier quoted context omitted.

This is what I have done for a couple of books I wrote in Markdown ( https://deanebarker.net/books/ ). Convert to HTML, then use Prince ( https://www.princexml.com/ ) to style and convert to PDF.

Their licenses are pretty expensive. Any good free open source alternatives?

I don't know what the scope of this is, but https://pagedjs.org/ is Javascript that does pagination and page margin styling. It's essentially a polyfill for CSS Paged Media: https://www.w3.org/TR/css-page-3/

Pretty nice to work with, if you can run JS. (The rest is just Puppeteer to print. Though I couldn't use their command line tool, because it force-injects paged.js, and it didn't play well with the Preact components for previewing I had made.)

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#44
> I have a very long regular expression (email validation of course) that doesn't fit on one line but no solutions I have found properly break the lines on page overflow.

Have you considered manually splitting the regular expression into multiple lines in the source document, using something like the `VERBOSE` mode from Python re module [1]?

[1]: https://docs.python.org/3/howto/regex.html#using-re-verbose

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#45
post #41

> I have a very long regular expression (email validation of course) On a tangentially related note, I guarantee you that your regex is wrong. There is only one way to validate an email address: Send an email to it and have them respond. Otherwise you will block some valid users. Now of course you can make a regex that gets most email addresses, and if you're ok with that, then that's fine. But if you don't want to a…

It's very easy to make a regex that allows all, but catches simple errors: /.+@.+/. Maybe narrow down the domain name, but don't forget that trailing dots are valid in DNS names.

Why is everyone trying to check for things they don't have to? If you need a valid email address, of course you have to send an email for confirmation. anna@example.com is perfectly syntactically valid, but isn't useful to anyone for sending emails. If you optionally want your users to enter an email address, don't overcomplicate things.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#46
I wouldn't use Markdown if you want all those features. Use Pandoc to convert your Markdown to Asciidoc, and then use asciidoctor-pdf.

Unfortunately Asciidoctor is written in Ruby which makes it an arse to work with if you need to write any plugins. And the HTML output uses Google Fonts by default, so I don't think much of the authors. But it's probably the best authoring system I've found for programming style content. For scientific content I would use LyX or maybe Typst.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#48
post #13

Earlier quoted context omitted.

This is what I have done for a couple of books I wrote in Markdown ( https://deanebarker.net/books/ ). Convert to HTML, then use Prince ( https://www.princexml.com/ ) to style and convert to PDF.

Their licenses are pretty expensive. Any good free open source alternatives?

I've only ever used a free version? I've never paid for it. I think it's free for personal projects? Or at least it was...

Edit: I see it's $495 now. I don't think it was priced when I used it, but it's been 4-5 years.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#49

Have 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 wonder how the Mdast and pandoc ASTs compare? 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-dimensio…

I am not familiar with Pandoc, but it looks like a command-line tool that can do the same things? (Edit: I suspect this is probably one of those situations where different industries/domains end up developing similar tools in different ecosystems... Pandoc probably makes sense in academia, LaTex workflows, etc.? Mdast is used for web apps. I can see both realms wanting to do Markdown conversions, so I'm not surprised to see similar tools available in both. I'm a web dev, so only familiar with Mdast.)

My guess is that either toolchain could do the job... maybe just depends on personal preference whether someone prefers to pipe together command-line tools in a bash script, vs making use of the npm ecosystem (mdast is all in JS).

Maybe the popularity of JS & npm means there are available mdast plugins & third party packages that can help with whatever niche transformation you might need, and custom node rendering is just a lambda away. It's all in JS for a seamless experience, and there is no separate DSL to learn (just some basic helper functions).

That might be harder to do in Pandoc... (might need a custom Lua filter or another language like your Julia pattern matching?)

As for effectiveness... it probably just depends on the particular implementer :) I'd trust a grizzled old *NIX sysadmin type over your typical bootcamp JS programmer any day, but also... the JS ecosystem is pretty mature and powerful now, and Mdast is pretty amazing. At work we use it to build one of the most important parts of our app, and its power and flexibility never cease to amaze me.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#50
post #41

> I have a very long regular expression (email validation of course) On a tangentially related note, I guarantee you that your regex is wrong. There is only one way to validate an email address: Send an email to it and have them respond. Otherwise you will block some valid users. Now of course you can make a regex that gets most email addresses, and if you're ok with that, then that's fine. But if you don't want to a…

It's very easy to make a regex that allows all, but catches simple errors: /.+@.+/. Maybe narrow down the domain name, but don't forget that trailing dots are valid in DNS names. Why is everyone trying to check for things they don't have to? If you need a valid email address, of course you have to send an email for confirmation. anna@example.com is perfectly syntactically valid, but isn't useful to anyone for sending…

> Why is everyone trying to check for things they don't have to?

I forgot where I read it (maybe something about testing or DDD), but an idea I like much is to not validate stuff coming from an external system other than for your internal constraints. You don't control an email account and how it was created and the specification is messy, so if you want to check for its existence, you query the other system. Same for other identifiers.

Post reply on HN