msn email google-talk twitter tumblr flickr

关于语法高亮

试用了社区比较流行的语法高亮工具.可以说各有所长,简单记录一下,保证以后在合适的地方用适合的工具.

Syntax (fast), Coderay (very fast), Ultraviolet (slow, but highlights almost any language).

Syntax

Languages supported by Syntax:

  • xml
  • ruby

Coderay

Languages supported by Coderay:

  • C, CSS
  • Delphi, diff
  • HTML, RHTML (Rails), Nitro-XHTML
  • Java, JavaScript, JSON
  • Ruby
  • YAML

Ultraviolet

The ultraviolet gem needs oniguruma regexp library.

On Fedora install the library with:

sudo yum install oniguruma oniguruma-devel

For installation instruction of the oniguruma library from sources, see Carbonica

Now, install the gem:

sudo gem install ultraviolet

See also Ultraviolet themes gallery

Ultraviolet supports almost any language:

Available syntaxes:
   - actionscript
   - active4d
   - active4d_html
   - active4d_ini
   - active4d_library
   - ada
   - antlr
   - apache
   - applescript
   - asp
   - asp_vb.net
   - bibtex
   - blog_html
   - blog_markdown
   - blog_text
   - blog_textile
   - build
   - bulletin_board
   - c
   - c++
   - cake
   - camlp4
   - cm
   - coldfusion
   - context_free
   - cs
   - css
   - css_experimental
   - csv
   - d
   - diff
   - dokuwiki
   - dot
   - doxygen
   - dylan
   - eiffel
   - erlang
   - f-script
   - fortran
   - fxscript
   - greasemonkey
   - gri
   - groovy
   - gtd
   - gtdalt
   - haml
   - haskell
   - html
   - html-asp
   - html_django
   - html_for_asp.net
   - html_mason
   - html_rails
   - html_tcl
   - icalendar
   - inform
   - ini
   - installer_distribution_script
   - io
   - java
   - javaproperties
   - javascript
   - javascript_+_prototype
   - javascript_+_prototype_bracketed
   - jquery_javascript
   - json
   - languagedefinition
   - latex
   - latex_beamer
   - latex_log
   - latex_memoir
   - lexflex
   - lighttpd
   - lilypond
   - lisp
   - literate_haskell
   - logo
   - logtalk
   - lua
   - m
   - macports_portfile
   - mail
   - makefile
   - man
   - markdown
   - mediawiki
   - mel
   - mips
   - mod_perl
   - modula-3
   - moinmoin
   - mootools
   - movable_type
   - multimarkdown
   - objective-c
   - objective-c++
   - ocaml
   - ocamllex
   - ocamlyacc
   - opengl
   - pascal
   - perl
   - php
   - plain_text
   - pmwiki
   - postscript
   - processing
   - prolog
   - property_list
   - python
   - python_django
   - qmake_project
   - qt_c++
   - quake3_config
   - r
   - r_console
   - ragel
   - rd_r_documentation
   - regexp
   - regular_expressions_oniguruma
   - regular_expressions_python
   - release_notes
   - remind
   - restructuredtext
   - rez
   - ruby
   - ruby_experimental
   - ruby_on_rails
   - s5
   - scheme
   - scilab
   - setext
   - shell-unix-generic
   - slate
   - smarty
   - sql
   - sql_rails
   - ssh-config
   - standard_ml
   - strings_file
   - subversion_commit_message
   - sweave
   - swig
   - tcl
   - template_toolkit
   - tex
   - tex_math
   - textile
   - tsv
   - twiki
   - txt2tags
   - vectorscript
   - xhtml_1.0
   - xml
   - xml_strict
   - xsl
   - yaml
   - yui_javascript

有这么多,鼠标滚得累吧 ^ ^ 目前这个blog使用Ultraviolet,让这么迷你的blog引擎(自己定制了些功能也才12k)背一个2MB(还不算oniguruma)的语法高亮包的确是太过分了,主要是为了支持更多的语言,当然也考虑到有很多的主题可选择,而且heroku应该是有装oniguruma的,只要在.gem中配置下UV就好了,引用时候就require 'uv'.btw,uv其实不仅仅是个库,还包含命令行工具的,装上之后就可以使用了,uv --help.

coderay是最适用的,100k+的体积,超级快的速度,还有不错的样式(Ryan Bates在github提供了一份很赞主题).唯一不足就是支持语言少了些,是最适合blog的选择.

Syntax支持语言最少,但是胜在速度及单纯.适用在需求单一的环境,避免一些不必要的麻烦.