如何在网页中显示带缩进的源代码? HTML? CSS?

时间:2022-03-01 15:42:33

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.

我想在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 ignored by the WebBrowser control.

确切地说,我的源代码保存在String []中,每个String都包含正确的缩进(空格或制表符)。但似乎WebBrowser控件忽略了这些缩进。

Could someone tell me how to?

有人能告诉我怎么做?

3 个解决方案

#1


7  

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

#2


9  

I like to paste my code in a Gist and 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.

如果你经常这样做,你可以尝试降价。

Or use a one-off formatter like Syntax Highlighter.

或者使用像Syntax Highlighter这样的一次性格式化程序。

#3


1  

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/

#1


7  

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

#2


9  

I like to paste my code in a Gist and 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.

如果你经常这样做,你可以尝试降价。

Or use a one-off formatter like Syntax Highlighter.

或者使用像Syntax Highlighter这样的一次性格式化程序。

#3


1  

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/