smwikipedia
smwikipedia

Reputation: 64433

How to display source code with indent in a web page? HTML? CSS?

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

To be precise, my source code are held in String[], and each String holds the proper indent (space or tab) already. But it seems these kinds of indent are just ignored by the WebBrowser control.

Could someone tell me how to?

Upvotes: 15

Views: 35305

Answers (3)

Bob.
Bob.

Reputation: 1659

You might want to look into this JavaScript library to highlight and format your code. http://code.google.com/p/syntaxhighlighter/

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

Upvotes: 1

ow3n
ow3n

Reputation: 6627

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

If you're going to be doing it often you could try markdown.

Or use a one-off formatter like Syntax Highlighter.

Upvotes: 12

Quentin
Quentin

Reputation: 944444

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

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

Upvotes: 9

Related Questions