Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 591
smwikipedia Avatar asked May 29 '12 14:05

smwikipedia


People also ask

How do you indent a code in HTML?

You can indent elements by moving them two spaces to the right. This will make your code more readable by other developers and shows the relationship between the child and parent HTML elements.

Does HTML follow indentation?

For help with indenting text with HTML, see: How to indent or tab text on a web page or in HTML. No. HTML code does not need to be indented, and all browsers and search engines ignore indentation and extra spacing.


1 Answers

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.

like image 171
ow3n Avatar answered Oct 06 '22 15:10

ow3n