如何在网页中用缩进显示源代码?HTML?CSS?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10800723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display source code with indent in a web page? HTML? CSS?
提问by smwikipedia
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 indentproperly.
我想在 winform 上显示一些带有 WebBrowser 控件的源代码。我想用 HTML 标签装饰源代码,例如颜色、字体和大小。但我发现很难正确显示缩进。
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 ignoredby the WebBrowser control.
准确地说,我的源代码保存在 String[] 中,并且每个 String 已经保存了正确的缩进(空格或制表符)。但似乎这些类型的缩进被WebBrowser 控件忽略了。
Could someone tell me how to?
有人能告诉我怎么做吗?
采纳答案by Quentin
The <pre>
element(using <code>
elementswith appropriate class names to mark up the parts you want to syntax highlight)
该<pre>
元素(使用<code>
元素与适当的类名称来标记,以语法高亮显示你想要的部分)
<pre><code class="javascript"><code class="keyword">function</code> <code class="name">foo</code>()…
回答by ow3n
I like to paste my code in a Gistand then display it that way. Github will recognize the code and format it accordingly.
我喜欢将我的代码粘贴到Gist 中,然后以这种方式显示。Github 将识别代码并相应地对其进行格式化。
If you're going to be doing it often you could try markdown.
如果你要经常这样做,你可以试试markdown。
Or use a one-off formatter like Syntax Highlighter.
或者使用一次性格式化程序,如Syntax Highlighter。
回答by Bob.
You might want to look into this JavaScript library to highlight and format your code. http://code.google.com/p/syntaxhighlighter/
您可能需要查看此 JavaScript 库以突出显示和格式化您的代码。http://code.google.com/p/syntaxhighlighter/
Or you can check out a service like this - http://pygments.appspot.com/or this - http://hilite.me/
或者您可以查看这样的服务 - http://pygments.appspot.com/或这个 - http://hilite.me/