Show HN: Generate high-res images of code samples with Chrome Headless
1–10 of 92 posts
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#2Re: Show HN: Generate high-res images of code samples with Chrome Headless
#3Nice work. But I'm not looking forward to trying to select text only to drag an image
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#4Re: Show HN: Generate high-res images of code samples with Chrome Headless
#5Wouldn't it be better as a PDF so that it can be selected? But somehow still retain the color / formatting.
It seems like it should be pretty easy to print a PDF from Puppeteer though – they expose a #pdf method.
https://github.com/GoogleChrome/puppeteer/blob/master/docs/a...
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#6Nice work. But I'm not looking forward to trying to select text only to drag an image
If you're posting code on a website, you're right – you should prefer
and prism.js or highlight.js :)Re: Show HN: Generate high-res images of code samples with Chrome Headless
#7Wouldn't it be better as a PDF so that it can be selected? But somehow still retain the color / formatting.
I built this to generate PNGs to drop into a Keynote presentation, so PDFs don't quite work for my use case. It seems like it should be pretty easy to print a PDF from Puppeteer though – they expose a #pdf method. https://github.com/GoogleChrome/puppeteer/blob/master/docs/a...
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#8However, congrats on assembling your "Lovecraftian amalgamation of software." :)
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#9Also, ever try this technique? https://gist.github.com/jimbojsb/1630790
I've used it with success before.
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#10Wouldn't it be better as a PDF so that it can be selected? But somehow still retain the color / formatting.
One time setup
$ python -m venv ve
$ source ve/bin/activate
$ pip install pygments WeasyPrint
Then $ pygmentize -f html src.py | weasyprint - out.pdf
Both pygmentize and weasyprint have many options to play with. I find a set and create a shell script.This also does pngs, etc:
$ pygmentize -f html src.py | weasyprint - out.png