美化代码的15个代码语法高亮工具
本文作者是Gavin McLeod,一个被困在《电子世界争霸战》里的骨灰级Web极客。在文中列举了15个帮助开发者快速编码、优化代码的语法高亮工具,每个高亮工具都有其功能特色。(以下是编译内容)
开发者和顽固的代码极客深知Code Syntax Highlighter(以下简称“代码语法高亮工具”)作为二级符号的一种形式,便于在一个结构化语言或标记语言里书写代码。有些代码高亮编辑器里融合了多个语法高亮功能,例如拼写检查、代码折叠。语法高亮工具可以在总体策略的使用上起到较大的作用:改善文本的可读性和上下文语境,尤其是在代码页数较多的情况下。另外还能帮助开发者快速在编程过程中定位bug源头。
不管你是一个代码极客还是一个吊儿郎当的码农,下面为你提供的代码语法高亮工具保证能让你写的代码焕然一新。
1. Prism
Prism是一个只有1.5KB大小的压缩版轻量级工具,能够简单方便的整合到CSS和JavaScript文件里,运行速度很快。已经使用在Dabblet里(一个交互式的CSS场地)美化了很多代码,所以说Prism很稳定。新的编程语言也可以加入进来,在使用这个插件架构的前提下,新加入的语言功能性将不断提升;外观风格和使用感觉都可以通过CSS来设计。
2. Rainbows
Rainbow是一款用JavaScript脚本编写的只有1.4KB的轻量级工具。它只需要在有必要高亮显示的语言上使用JavaScript模型来保持事情简单化就可以了。同样,颜色和字体可以通过CSS主题支持来完全自定义。
3. Snippet
Snippet是一个jQuery插件,建立在SHJS脚本的顶部以此来高亮显示HTML文件里的源代码。它支持很多种类的脚本语言:JavaScript、SQL、PHP和Ruby等等。其包含39个内置的独一无二的配色图案,可以不断的变换调试。
4. Geshi
这是一个高度自定义的语法高亮显示工具,可以在网页里用来更好的展示代码片段。Geshi经过开发后来应用在phpBB论坛软件上,但在功能特性上仍然是分开使用的。此外,这个语法高亮工具支持几乎所有的流行编程语言,像ActionScript、ASP、C、JAVA、PHP、Ruby和SQL等等。
Syntax Highlighter帮助一个开发者/码农轻松在线公布代码片段,而且代码的外观看上去也很不错。说白了,它就是一个100%建立在JavaScript基础上的高亮显示工具,不用考虑服务器上有什么其他东西。支持多款编程语言,压缩后的核心库只有11KB大小。然而,Syntax Highlighter并不具备编写高亮代码的能力,也不为用户提供编写源代码的能力。
这是在GoogleCode网站使用的脚本。这个脚本能够自动查出正在使用的编程语言,进行相应的美化。同时也可以通过CSS来自定义。
Hightlight.js基本上不需要采用复杂的步骤就可以使用了,因为它的自动化程度很高:找出代码块,检测语言,高亮显示一下就行了。它已经开始支持第三方应用程序,并提供Firefox扩展程序用于查看代码,但是没有语法高亮显示。
8. SHJS:Syntax Highlighting inJavaScript
SHJS是一个JavaScript程序,它可以高亮显示在HTML文档里的源代码段落。文件使用SHJS将会通过web浏览器高亮显示在客户端。这就赋予了SHJS一项功能,那就是能够高亮显示源代码是使用不同的语言编写的。
这个在线高亮工具提供许多编码语言,你可以选择多个选项将这些编码语言集体高亮显示。在高亮显示代码、Combine Style、HTML Code、Highlight内置关键词、数据类型、Strict Mode和Wrap过剩文本之前你可以选择检查或者不检查代码。
10. Ultraviolet
Ultraviolet是一个运行在Ruby上的语法高亮引擎,支持50种以上的编程语言和20种以上的主题。
11. Pygments:Python Syntax Highlighter
这款语法高亮工具是用Python构建的,支持大部分的编程语言、多种输出格式,它还可以被当作是一个命令行工具或者是一个类库来使用。
Lighter是一个免费的语法高亮工具,专门为MooTools而开发的。MooTools开发者在创建Lighter之初运用了许多框架结构上的功能特点。它运用起来就像是在网页上添加一个单独的脚本那样简单,选择你想要高亮显示的元素,Lighter会自动处理其余部分。
13. CodePress
CodePress是一个基于网络的源代码编辑器,带有用JavaScript编写的语法高亮工具,随着在浏览器里连续打字,文本的颜色会实时发生变化。除此以外,它还有代码片段、自动完成、快捷方式和多窗口功能。
14. Beauty of Code
这个jQuery语法高亮插件使用的是Alex Gorbatchev里的语法高亮显示,但有一点不一样:它能够产生更多的xhtml兼容的代码。
15. Jush JavaScript Syntax Highlighter
JavaScript SyntaxHighlighter可以用在客户端的语法高亮程序里,支持的语言有HTML、CSS、JavaScript、PHP、SQL、HTTP、SMTP协议、php.ini和Apache配置。
原文:CodeGeekz
15Code Syntax Highlighters To Prettify Your Code
· BY GAVIN
· IN DEVELOPMENT · RESOURCES
· — 3SEP, 2013
Developers and die-hard Code Geeks are well aware that SyntaxHighlighters are a form of secondary notation, which facilitate the writing upof code within a structured language or a markup language. Several Code Highlighting editorsintegrate syntax highlighting which are packed with other features, such asspell checking or code folding, as aids to editing that are external to thelanguage.Using a Syntax highlighter can serve as an overall strategic method bywhich to improve the readability and context of the text; especially for codewhich can end up spanning several pages; as well as enable Developers to locateerrors within their program.
Whether you’re and avid CodeGeekz buried on the frontend or yousimply want to fiddle around with the code, the following Syntax Highlighterswill enable you to display your code within a ‘prettified’ manner. MostSyntax Highlighters are now packed with an unlimited amount ofoptions, extensions and integrations to work with other programs and platforms,however we want to offer you our Top 15 Code Syntax Highlighters which will speed up your work flow andprettify your code !
Enjoy!
1. Prism
Prism is lightweight (1.5KB minified & gzipped), can be integrated soeasily (just insert a CSS and JS file) and works fast. It is already used tobeautify lots of code in Dabblet (an interactive CSS playground) so its prettystable. New languages can be added and the functionality can be improved withthe plug-in architecture and the look/feel can be completely styled via CSS.
2. Rainbows
Rainbow is a fresh lightweight only 1.4kb written in JavaScript. It is onlyneeded to use the JS module for the language to be highlighted for keepingthings small. Also, the colors and fonts used can be completely customized withCSS theming support.
3. Snippet
Snippet is a jQuery plugin that is built on top of the SHJS script forhighlighting source codes in HTML documents. It supports many scriptinglanguages from JavaScript to SQL and PHP to Ruby. There are 39 built-in andunique color schemes that you can switch in-between dynamically.
4. Geshi
GeSHi is a highly customizable syntax highlighter that can be used to betterpresent code snippets in websites. It is developed to be used in phpBB forumsoftware but is also presented for separated use. This syntax highlightersupports almost every popular language like ActionScript, ASP, C, JAVA, PHP,Ruby, SQL & more (even robots.txt).
5. Syntax Highlighter
SyntaxHighlighter helps a developer/coder to post code snippets online withease and have it look pretty. It’s 100% Javascript based and it doesn’t carewhat you have on your server. It supports multiple languages and is verylightweight, compressed core library is 11kb plus whatever brushes you need.However, SyntaxHighlighter isn’t for those looking for ability to edithighlighted code. SyntaxHighlighter doesn’t allow users to edit the source.
6. Google Code Prettify
This is the script used by the Google Code website. The script auto-detects thelanguage used and highlights the code accordingly. It is also customizable viaCSS.
7. Hightlight.js
Highlight.js is very easy to use because it works automatically: finds blocksof code, detects a language, highlights it. It has support for 3rd partyapplications and provides a Firefox extension for viewing code that doesn’thave syntax highlighting.
8. SHJS : Syntax Highlighting inJavaScript
SHJS is a JavaScript program which highlights source code passages in HTMLdocuments. Documents using SHJS are highlighted on the client side by the webbrowser. SHJS uses language definitions from GNU Source-highlight. This givesSHJS the ability to highlight source code written in many different languages.
9. Quick Highlighter
This online highlighter tool offers many coding languages you can choose tohighlight together with several options, you can check/uncheck beforehighlighting code, Combine Style and HTML Code, Highlight inbuilt keywords,data types etc., Strict Mode, and Wrap overflowing text.
10. Ultraviolet
Ultraviolet is a syntax highlighting engine that runs on Ruby. It has supportfor 50+ languages & 20+ themes.
11. Pygments : Python SyntaxHighlighter
It is a syntax highlighter that is built with Python. Pygments supports a widerange of languages, various output formats & it is usable as a command-linetool or as a library.
12. Lighter for MooTools
Lighter is a free syntax highlighting class developed for MooTools. It wascreated with the MooTools developer in mind and takes advantage of many of theFramework’s features. Using it can be as simple as adding a single script toyour webpage, selecting the elements you wish to highlight, and Lighter takescare of the rest.
13. CodePress
CodePress is web-based source code editor with syntax highlighting written inJavaScript that colors text in real time while it’s being typed in the browser.It has code snippets, auto completion, shortcuts, and multiple windowsfeatures.
14. Beauty of Code
This jQuery syntax highlighter plugin uses Alex Gorbatchev’sSyntaxHighlighterbut with a twist: produces more xhtml-compliant codes.
15. Jush JavaScript SyntaxHighlighter
JavaScript Syntax Highlighter can be used for client-side syntax highlightingof following languages: HTML, CSS, JavaScript, PHP, SQL, HTTP andSMTP protocol,php.ini and Apache config