开发者

Display highlighted HTML source code in Firefox?

开发者 https://www.devze.com 2022-12-11 12:18 出处:网络
Is there some clever content-type setting that makes Firefox display highlighted HTML source code instead of rendering it?

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 generat开发者_高级运维ed 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.)


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

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

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

<iframe src="view-source:http://etc"/>

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


You could use

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

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号