15

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?

3 Answers 3

12

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.

Sign up to request clarification or add additional context in comments.

Comments

9

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>()…

Comments

1

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.