views:

174

answers:

4

Is there some clever content-type setting that makes Firefox display highlighted HTML source code instead of rendering it? I have a CMS that generates HTML pages. I get debug info on each generated page by adding "/debug" to the URL. I would like to see the source by using "/source" so I have the source within my Firefox tabs (and not as an extra window).

I toyed with

ob_start()

and

highlight_string(ob_get_contents())

but it didn't work quickly, I find it too complicated and I like to avoid working with buffering when I can.

Maybe there is a simpler way to do this?

Edit: I will be using header("content-type: text/plain") for the time being but that doesn't highlight the code. I am looking for something like "content-type: text/html-source" or similar.)

+1  A: 

Have you looked at installing a third-party syntax highlighter? I'm considering adding one to a project that uses a hand-built CMS system to allow staff to edit HTML content directly.

jkndrkn
A syntax highlighter is certainly the most advanced solution, but if I understand the documentation to PHP's highlight_string() correctly, it does HTML already. I was just hoping for something like the .phps extension in PHP - files with that extension are automatically shown with their source, highlighted.
Pekka
+2  A: 

You could use

<p>
    This very <em>system</em> which <a href="http://stackoverflow.com/"&gt;this
    website</a> uses. It's called Prettify.
</p>

http://code.google.com/p/google-code-prettify/

nickf
Prettify looks nice, but I am looking to output the whole chunk (including everything up to <html>) which will be difficult using a JS approach. Thanks anyway.
Pekka
+2  A: 

Some Browsers already have HTML syntax highlighting built in. In Firefox & Chrome you could link to

<a href="view-source:http://etc"&gt;View Source</a>

or use the (highlighted) source view inside an iframe:

<iframe src="view-source:http://etc"/&gt;

This obviously doesn't really work cross-browser but you might be able to live with that in a custom made CMS.

Josef
That's what I was looking for, shame that it's FF only but works for me right now. Thanks!
Pekka
+1  A: 

You could use something like Geshi It's quite useful, and highlights a lot more languages than just html, in case you ever needed that.

Jeremy Morgan