如何突出显示HTML中的源代码? [英] How to highlight source code in HTML?

查看:82
本文介绍了如何突出显示HTML中的源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上突出显示C / C ++ / Java / C#等源代码。



我该如何做?

这是一个CPU密集型工作,需要突出显示源代码吗?

解决方案

边或客户端。这不是处理器密集型的,但是如果你在客户端(使用Javascript)做它会有明显的滞后。大多数客户端解决方案围绕Google Code的语法高亮引擎。这似乎是最流行的: SyntaxHighlighter



服务器端解决方案往往更灵活,特别是在定义新语言和配置突出显示方式(例如使用的颜色)方面。我使用GeSHi,这是一个PHP解决方案,带有适合Wordpress的中等插件。还有一些为Java构建的库,甚至一些基于VIM的库(通常需要从CPAN安装Perl模块)。



简而言之:你有很多选择,你的标准是什么?如果不知道您的要求,很难做出可靠的建议。


I want to highlight C/C++/Java/C# etc source codes in my website.

How can I do this?

Is it a CPU intensive job to highlight the source code?

解决方案

You can either do this server-side or client-side. It's not very processor intensive, but if you do it client side (using Javascript) there will be a noticeable lag. Most client side solutions revolve around Google Code's syntax highlighting engine. This seems to be the most popular one: SyntaxHighlighter

Server-side solutions tend to be more flexible, especially in the way of defining new languages and configuring how they are highlighted (e.g. colors used). I use GeSHi, which is a PHP solution with a moderately nice plugin for Wordpress. There are also a few libraries built for Java, and even some that are based upon VIM (usually requiring a Perl module to be installed from CPAN).

In short: you have quite a few options, what are your criteria? It's hard to make a solid recommendation without knowing your requirements.

这篇关于如何突出显示HTML中的源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆