Pygments in Wordpress

I wanted to have pygments support in wordpress and so I hacked up a small wordpress plugin that enables pygments support in wordpress. Because I was lazy and PHP sucks like hell I just supported the case of a php.ini with magic slashes disabled. Somehow wordpress reinserts some of those annoying things automatically in some places though.

If you want to try it out: pygments.php. Note that I do not support it, it’s released under the BSD license like Pygments itself, it requires an installed pygments with the pygmentize script, no idea which PHP version, disabled magic quotes I guess and that you generate a pygments.css file yourself that matches the style defined in the plugin.

It caches in the text, and has few overhead on rendering Basically all you have to do is typing <pre lang="LANGUAGE">code</pre> instead of using a normal pre tag. Escaping happens automatically.

Example:

# Server: ruby p2p.rb password server server-uri merge-servers
# Sample: ruby p2p.rb foobar server druby://localhost:1337 druby://foo.bar:1337
# Client: ruby p2p.rb password client server-uri download-pattern
# Sample: ruby p2p.rb foobar client druby://localhost:1337 *.rb
require'drb';F,D,C,P,M,U,*O=File,Class,Dir,*ARGV;def s(p)F.split(p[/[^|].*/])[-1
]end;def c(u);DRbObject.new((),u)end;def x(u)[P,u].hash;end;M=="client"&&c(U).f(
x(U)).each{|n|p,c=x(n),c(n);(c.f(p,O[0],0).map{|f|s f}-D["*"]).each{|f|F.open(f,
"w"){|o|o<<c.f(p,f,1)}}}||(DRb.start_service U,C.new{def f(c,a=[],t=2)c==x(U)&&(
t==0&&D[s(a)]||t==1&&F.read(s(a))||p(a))end;def y()(p(U)+p).each{|u|c(u).f(x(u),
p(U))rescue()};self;end;private;def p(x=[]);O.push(*x).uniq!;O;end}.new.y;sleep)

2 Responses to “Pygments in Wordpress”

  1. Just a note: pygments.php uses the function stream_get_contents() which requires at least PHP 5.

    Comment by Lior Gradstein — Tuesday, July 3rd, 2007 @ 9:45 am
  2. […] website of Armin Ronacher (incidentally, a contributor to Pygments). More relevantly, I found the plugin he created to enable Pygments support for Wordpress. Problem is, it doesn’t work for […]

    Comment by from learning import * » Blog Archive » Wordpress, Pygments syntax highlighting, Autohotkey — Thursday, January 24th, 2008 @ 10:25 pm

Leave a Reply

cogitations driven by wordpress