This program, given a source file, produces a document with syntax highlighting.
These are the output formats already supported:
HTML(這個vim用:TOhtml也可以)
XHTML
LATEX
TEXINFO
ANSI color escape sequences (可以在水木上彩色顯示代碼,vim有TOansi插件也可以,
DocBook
These are the input languages (or input formats) already supported (in alphabetical order):
C/C++
C#
Bib
Bison
Caml
Changelog
Css (new)
Diff
Flex
Fortran
Html
Java
Javascript
Latex
Logtalk
Log files
Lua
Makefile (new)
M4 (new)
ML
Pascal
Perl
PHP
Postscript
Prolog
Python
Ruby
Shell
Sql
Tcl
XML
自己編譯的話要用到boost::regex庫,win32的有直接下載下傳的
<a href="http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=33223">http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=33223</a>
win32的安裝之後開始菜單裡隻有文檔,用的的時候把GnuWin32\bin\source-highlight.exe複制到GnuWin32\share\source-highlight裡用吧,使用方法是
source-highlight.exe -s cpp -f esc --input comments.cpp --output xxx.txt --style-file esc.style
Here’s how to run source-highlight (for this example we will use C/C++ input
files, but this
is valid also for other source-highlight input languages):
source-highlight --src-lang cpp --out-format html \
--input <C++ file> \
--output <html file> \
--style-file <style file> \
options
For input files, apart from the -i (--input) option and the standard input redirection, you
can simply specify some files at the command line and also use regular expressions (for instance
‘*.java’). In this case the name for the output files will be formed using the name of the source
file with a .<ext> appended, where <ext> is the extension chosen according to the output format
specified (in this example it would be .html). The style file (Section 5.1 [Output format style],
page 8) contains information on how to format specific language parts (e.g., keywords in blue
and boldface, etc.). If STDOUT string is passed as -o (--output) option, then the output is forced
to the standard output anyway.
If -s (--src-lang) is not specified, the source language is inferred by the extension of the
input file (this, of course, does not work with standard input redirection).
If -f (--out-format) is not specified, the output will be produced in HTML.
If --style-file is not specified, the ‘default.style’, which is included in
the distribution,will be used。
自帶文檔說的更詳細
.style和.outlang都可以改得,比如附帶的esc.style(輸出成ansi彩色用的色彩配置檔案)是
keyword blue b ;
type darkgreen ;
string red ;
comment brown i ;
number purple ;
preproc darkblue b ;
symbol darkred ;
function black b;
cbracket red;
// line numbers
linenum yellow;
輸出出來在term下不是很好看,我把它改成
keyword green b ;
type green ;
string yellow ;
comment cyan i ;
number yellow ;
preproc blue b ;
symbol purple ;
function red b;
cbracket purple;
改了之後term上水木的截圖
轉成html的用法是
source-highlight.exe -s cpp -f html --input comments.cpp --output xxx.html
就不貼圖了,覺得預設style不好看就自己改一改
本文轉自feisky部落格園部落格,原文連結:http://www.cnblogs.com/feisky/archive/2011/12/18/2310347.html,如需轉載請自行聯系原作者