News for hackers. Stuff that matters.
Re:Show HN: Generate high-res images of code samples with Ch... by rposborne on Monday September 11, 2017 @01:35PM (#15220360)
Wouldn't it be better as a PDF so that it can be selected? But somehow still retain the color / formatting.
Re:Show HN: Generate high-res images of code samples with Ch... by sago on Monday September 11, 2017 @01:55PM (#15220554)
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
Re:Show HN: Generate high-res images of code samples with Ch... by hk__2 on Monday September 11, 2017 @02:40PM (#15220966)
Can’t you it directly using Pygments’ ImageFormatter?

http://pygments.org/docs/formatters/#ImageFormatter

Re:Show HN: Generate high-res images of code samples with Ch... by sago on Monday September 11, 2017 @02:52PM (#15221111)
Apparently so! I don't generate images myself, so i didn't know.

    $ pygmentize -o out.png src.py 
Neat.
Re:Show HN: Generate high-res images of code samples with Ch... by ngharo on Monday September 11, 2017 @05:27PM (#15222513)
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 Ch... by mplewis on Monday September 11, 2017 @01:41PM (#15220424)
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 Ch... by tedmiston on Monday September 11, 2017 @01:47PM (#15220482)
Just curious why you'd want to use code screenshots vs text in a presentation. Did it have to do with missing fonts or something like that?
Re:Show HN: Generate high-res images of code samples with Ch... by XaspR8d on Monday September 11, 2017 @01:55PM (#15220556)
Not OP, but syntax highlighting and other niceties are probably going to disappear within most presentation software.
Re:Show HN: Generate high-res images of code samples with Ch... by mplewis on Monday September 11, 2017 @02:00PM (#15220604)
Yep – I can't copy my code out of Atom and keep its highlighting in Keynote, unfortunately.
Re:Show HN: Generate high-res images of code samples with Ch... by zokier on Monday September 11, 2017 @02:28PM (#15220855)
sorry for the minirant

This is something I find really frustrating in computing. We can do and are constantly doing such awesome and incredible things with computers. But at the same time transferring (copy-pasting) text from one application to another remains a challenge. And a reasonable solution for that is to bring in the 600lb gorilla that is a modern web browser to render fixed-width text into a bitmap so that it can be embedded into a presentation. It just feels so wrong, like the whole field is actually rotten inside under the shiny surface, while the state of the art blazes forwards thousand miles away from the real world. I, as a member of this community, feel utterly powerless to actually make the situation noticeably better, partly because of so much relies on interoperability, and partly because of the massive inertia that modern software carries.

I want out.

Re:Show HN: Generate high-res images of code samples with Ch... by yorwba on Monday September 11, 2017 @04:02PM (#15221788)
Clipboards support storing different content for different MIME types at the same time. Atom would have to put text/html (or some other colored markup) in addition to text/plain into the clipboard and then Keynote would have to know what to insert. The infrastructure for interoperability is there, the endpoints just need to actually support it.

EDIT: Apparently, the problem is (or was in 2014) that Keynote doesn't support HTML and Chrome (Atom is Electron-based, right?) doesn't support RTF. Well worth a read: https://apple.stackexchange.com/a/124167

Re:Show HN: Generate high-res images of code samples with Ch... by pjmlp on Tuesday September 12, 2017 @02:23AM (#15225194)
Using Windows or OS X clipboard works perfectly fine, the author just uses applications that don't work as they should together.

I can easily do the same with Notepad++ and Powerpoint, just need to copy-paste in RTF.

Re:Show HN: Generate high-res images of code samples with Ch... by kuschku on Monday September 11, 2017 @04:08PM (#15221827)
There is a simple solution for that, and it exists on Android.

On Android all text formatting is compatible between apps nicely, and can easily be copied between apps.

Re:Show HN: Generate high-res images of code samples with Ch... by jlgosse on Monday September 11, 2017 @02:49PM (#15221084)
Why not just do a screenshot of the code from Atom?
Re:Show HN: Generate high-res images of code samples with Ch... by mcphage on Monday September 11, 2017 @03:10PM (#15221311)
That doesn't scale well beyond doing a handful of them, I would think.
Re:Show HN: Generate high-res images of code samples with Ch... by tedmiston on Monday September 11, 2017 @11:52PM (#15224687)
For code heavy presentations, I've seen a few people use Jupyter notebooks to solve this problem. Then just intermingle the rest of the presentation as markdown cells around the code cells.
Re:Show HN: Generate high-res images of code samples with Ch... by mplewis on Monday September 11, 2017 @04:25PM (#15221960)
Exactly, and to get the screenshot exactly as I want takes a couple minutes of setup – pick a theme, pick a font size, resize window – plus a few more if I have to stitch scrolled pages together.
Re:Show HN: Generate high-res images of code samples with Ch... by adamzegelin on Monday September 11, 2017 @03:40PM (#15221604)
You can embed PDFs in Keynote presentations.
Re:Show HN: Generate high-res images of code samples with Ch... by chungy on Monday September 11, 2017 @02:05PM (#15220650)
You can use source-highlight to go to docbook or latex(color), and from either of those, can directly go to PDF.