I decided to use Pygments for a website I’m working on, but my lack of terminal knowledge is amazing.
I want to use pygmentize to highlight syntax in blog posts, but as they are stored in database I can’t just pass filename to it. Is there any way I can pass string into it?
If not, I will have to save post contents in a temp file, pygmentize it and load into database but this adds overhead that I would really like to avoid if at all possible.
I don’t see CLI documentation saying anything about it.
The man page says it reads from stdin if infile is omitted and it writes to stdout if outfile is omitted.
So on the cmdline you would type:
pymentize would output:
If you’ll run this with from PHP you’ll have to start pygmentize using
proc_open()as you’ll have to write to stdin of it. Here comes a short example how to do it:Btw, pygmentize is pretty cool stuff! I’m using it too 🙂