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!
Show HN: Generate high-res images of code samples with Chrome Headless
61–70 of 92 posts
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#62Images of code are the worst . Completely unusable.
He's using them for a Keynote presentation. I think it's probably okay.
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#63Anyone 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/
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#64Wouldn'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
: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_fileRe: Show HN: Generate high-res images of code samples with Chrome Headless
#65I'm at a loss here, why do people need images of syntax-highlighted code? Text inside images cannot be easily copied.
Re: Show HN: Generate high-res images of code samples with Chrome Headless
#66Re: Show HN: Generate high-res images of code samples with Chrome Headless
#671. 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
#68Re: Show HN: Generate high-res images of code samples with Chrome Headless
#69What'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.