How to display indented source code on a web page? HTML? CSS?

I want to show some source code using a WebBrowser control on winform. And I want to decorate the source code with HTML tags such as color, font, and size. But it was difficult for me to display the indent .

To be precise, my source code is stored in String [], and each line contains an existing indent (space or tab). But it looks like this indentation is only ignored by the WebBrowser control.

Can anyone tell me how?

+8
html css browser winforms
source share
3 answers

<pre> element (using <code> elements with appropriate class names to mark the parts that you want to highlight with syntax)

 <pre><code class="javascript"><code class="keyword">function</code> <code class="name">foo</code>()… 
+7
source share

I like to embed my code in a Gist and then display it that way. Github will recognize the code and format it accordingly.

If you are going to do this often, you can try markdown .

Or use a disposable formatter, such as a Syntax shortcut .

+7
source share

You might want to explore this JavaScript library to highlight and format the code. http://code.google.com/p/syntaxhighlighter/

Or you can check such a service - http://pygments.appspot.com/ or this - http://hilite.me/

+1
source share

All Articles