GNU Source-highlight 语法高亮代码

官方主页

http://www.gnu.org/software/src-highlite/

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的有直接下载的

http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=33223

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;

// line numbers
linenum yellow;

改了之后term上水木的截图

GNU Source-highlight 语法高亮代码

转成html的用法是

source-highlight.exe -s cpp -f html --input comments.cpp --output xxx.html

就不贴图了,觉得默认style不好看就自己改一改

作者:feiskyer 发表于2011-12-18 21:45:12 原文链接
阅读:26 评论:0 查看评论

你可能感兴趣的:(source)