Thursday, July 14, 2011

Pygments to the rescue

I'm finally realized that Pygments is the Answer. I can simply run my code through it and get the output I'm looking for with only a little manual tweaking (see below); I'm sure this can be integrated into Pygments with a bit of hacking. Then, a simple copy and paste retrieves the original source code! Some additional tweaks:
  1. I'm like to hide the comment character (# in Python, // in C) to make it look nicer, by giving it a very small font. I suspect I could edit the output of the lexer, or perhaps play with the formatter, to do this.
  2. I need to disable HTML escaping for comments (this is done in the formatter). Perhaps a quick check for non-HTML < characters and escaping only these would help.
  3. I rely on the code editor to support line wrapping, which isn't always present. I don't see an obvious work-around for this. 

My simple tweak to the HTML style from Pygments to make comments look nice:
body .c { color: #408080; font-family: Sans-serif; white-space: normal; font-size: 90% } /* Comment */

No comments:

Post a Comment