5 ms·
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
by cjbillington 9y ago
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.
- sago 9y ago100% agreed. Just fwiw, apparently (i.e., I discovered in the last 10 mins) pygmentize detects file extensions, so $ pygmentize -o test.png test.py is equivalent.
- iandanforth 9y agoThe interesting bit here would be to tie pygmentize into git. I want to be able to generate all the code samples for a deck in one go even as I make changes to the underlying files. At some point this breaks down but managing line numbers for simple changes shouldn't be required.
- carlmr 9y agoCouldn't you just write a script that does the pygmentize, and alias a git command to it?
- mplewis 9y agoHey, thanks for the suggestion. I've used Pygments in the past and didn't even think to check if it had a PNG output mode. Here's an example of Pygments C++ output: http://imgur.com/a/7TbMb http://imgur.com/a/7TbMb And the same file through Prism.js + Puppeteer: https://github.com/mplewis/src2png/blob/master/docs/arduino.cpp.png https://github.com/mplewis/src2png/blob/master/docs/arduino.... Pygments does a great job of generating detailed PNGs. The default settings aren't quite what I'm looking for, but they look like they could be tweaked to increase the resolution and change the color scheme. I'm embedding my examples in a Keynote deck, so I'm picky about font family, size, resolution, etc. I bet I could get similar results by writing a custom script for Pygments. Thanks for sharing!
- adambrenecki 9y agoIf you're copying code into a Keynote presentation, you can use Pygments' RTF output mode, copy it to the clipboard, and just paste it into a text box in Keynote. That way, because it's actual text, it's smooth regardless of output resolution. Here's an example I just pulled from my shell history: pygmentize -f rtf -O "fontface=Fira Code,fontsize=26" -l prolog familyinteract.pl | pbcopy (That was for pasting code into Pages; for Keynote you'll probably want a bigger font size.)
- jackblack8989 9y agoSo it's not a "slide" deck, it's a keynote deck? Ok Mr "Hacker". I get the entire point of your useless project now. lol
- ssalazar 9y agoWhen the only tool you have is a hammer...