I am trying to write a blog and I want to display c# code in a neat formatted way. Is there a way to it. I like to do it exactly the way stack overflow does including color. :)
To view only the source code, press Ctrl + U on your computer's keyboard. Right-click a blank part of the web page and select Page source from the pop-up menu that appears.
You can include code examples in your HTML by using the <code> tag. This automatically uses a monospaced font and also semantically labels our code as what it is.
HTML provides many methods for text-formatting but <code> tag is displayed with fixed letter size, font, and spacing. Some points about <code> tag: It is mainly used to display the code snippet into the web browser.
HTML <output> Tag.
You have quite a few options here, but I would recommend against using a JavaScript formatter. If a user has scripts disabled, you still want the code to look good.
If you are using Visual Studio, the Productivity Power Tools add-in has a "copy HTML" option:
http://blogs.msdn.com/b/kirillosenkov/archive/2010/06/07/copy-code-in-html-format-with-visual-studio-2010.aspx
Jon Skeet provides a code formatter for public use:
http://csharpindepth.com/CodeFormatterTool.aspx
If you are using PHP, GeSHi is a good server-side option:
http://qbnz.com/highlighter/
I believe that stack-overflow uses google-code-prettify:
http://code.google.com/p/google-code-prettify/
SyntaxHighlighter is another good client-side solution:
http://alexgorbatchev.com/SyntaxHighlighter/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With