有网络小工具或服务或一些开源解决方案可以做到这一点吗?
或者人们只是在 HTML 中手动编码?
我需要向网页添加一些 Ruby 和 Python 代码。
我认为 Stack Overflow 使用这个或非常类似的东西:http://code.google.com/p/syntaxhighlighter/
我认为这个网站使用了 prettify。
如果您使用 Vim 编辑器,那么这非常简单。只需在 GVIM 窗口中打开代码并将其另存为 HTML 文件(另存为...等)..它将为您完成创建保留语法突出显示的 HTML 文件的所有工作。
编辑:它实际上是“语法”菜单上的“转换为 HTML”。 (http://vim.wikia.com/wiki/Pasting_code_with_syntax_coloring_in_emails)
SyntaxHighlighter 2.0 最近发布,这里是一个帮助您入门的基本片段:
<head>
<script type="text/javascript" src="path/to/scripts/shCore.js"></script>
<script type="text/javascript" src="path/to/scripts/shBrushPython.js"></script>
<script type="text/javascript" src="path/to/scripts/shBrushRuby.js"></script>
<link type="text/css" rel="stylesheet" href="path/to/css/shCore.css"/>
<link type="text/css" rel="stylesheet" href="path/to/css/shThemeDefault.css"/>
<script type="text/javascript">
SyntaxHighlighter.config.clipboardSwf = 'path/to/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>
</head>
<pre class="brush: python;">
... code ...
</pre>
<pre class="brush: ruby;">
... code ...
</pre>