Live data from Hacker News

Show HN: Generate high-res images of code samples with Chrome Headless

github.com

61–70 of 92 posts

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#61
post #50
post #35

This is a step backward from my current workflow which uses vector graphics.

I'd love to see your current workflow if you're willing to share!

Sorry, I can't easily do that. But I can say it uses LaTeX under the hood.

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#62
post #53
post #47

Images of code are the worst . Completely unusable.

He's using them for a Keynote presentation. I think it's probably okay.

Not really. For instance, if you put the PDF file of the presentation online, then search engines will not be able to index this code easily, humans will not be able to cut and paste the code easily, etc.

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#63
post #43

Anyone knows a tool which can help us draw simple diagrams like the one that was mentioned in the README?? https://github.com/mplewis/src2png/blob/master/docs/foreach_...

Looks like https://www.websequencediagrams.com/

Close! I started with that tool, but moved to the FOSS version: https://bramp.github.io/js-sequence-diagrams/

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#64
post #10

Wouldn't it be better as a PDF so that it can be selected? But somehow still retain the color / formatting.

My workflow: 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

I use vim for writing out html:

  :TOhtml
I found it to create the prettiest syntax highlighted code. But I'm bias because it produces html using my vim color scheme which I'm partial too :)

You can script vim too by specifying a list of commands in a file then running it:

  $ vim -S myscript some_file

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#66
post #58

Earlier quoted context omitted.

Nah, this is perfect for containers. You could use kubernetes to manage it all.

For true webscale generation use AWS autoscaling. Render tens of screenshots in a matter of minutes!

It's all serverless now

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#67
Vim can do this

1. Open your script/code in vim editor

2. Enable syntax & set the required color scheme

:syntax on :colorscheme darkblue

3. Print the file in PS file format

:hardcopy >/tmp/filename.ps

4. Convert the PS file to PDF format

$ ps2pdf /tmp/filename.ps

5. Now you can open filename.pdf

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#69

What's wrong with pygments? I've been using it to get highlighted code as latex, html, whatever, since forever. I'm all for reinventing deficient wheels, but is there anything wrong with this? pygmentize -f png -l python -o test.png test.py Spinning up a browser for it seems like an odd choice. At least the author acknowledges that.

When the only tool you have is a hammer...
Post reply on HN