3

I'm working on prettify'ing some auto-generated emails that often have code snippets in them. I want to use Google's prettify project to syntax highlight the code snippets.

How can I invoke prettify on the server, before sending out the email, such that users will still see the highlighted syntax when javascript is disabled in their mail viewers (Outlook). I'm thinking I need some sort of browser emulator since prettify is manipulating the browser DOM.

Ross Rogers
  • 23,523
  • 27
  • 108
  • 164

1 Answers1

2

Running the plain JavaScript on the server is possible using Rhino or the Google v8 interpreter, but that would mean you'd have to scan the emails, find all the code blocks, write a special call to prettify so it returns the formatted code instead of replacing it on the DOM... not too practical, plus you'd have to have shell access to your server to get v8 going. If you are interested in that, look here: Running V8 Javascript Engine Standalone

Now, the other way would be to use one of the many server-side highlighters like Hyperlight (http://code.google.com/p/hyperlight/) or Pygments (http://pygments.org/)

Lastly, you'd have to include in the emails all the CSS from the themes used by any of the above methods, which isn't too big of a hassle, but increases the size of the email, even if all what was there to highlight was a variable name, for instance.

Community
  • 1
  • 1
tog000
  • 151
  • 4