GNU Source-highlight 语法高亮代码

简介:

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上水木的截图

转成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,如需转载请自行联系原作者


相关文章
|
11月前
Sublime Text3 Emmet用法
Sublime Text3 Emmet用法
|
C++
Visual Studio Code 设置 doxygen 格式注释
vs code 使用 cschlosser.doxdocgen 插件,设置 doxygen 注释格式
849 0
Visual Studio Code 设置 doxygen 格式注释
|
机器人 Linux 编译器
替代notepad++,notepad--介绍及插件cmake编译
替代notepad++,notepad--介绍及插件cmake编译
|
C++
VS Code注释插件doxygen documentation generator
VS Code注释插件doxygen documentation generator
703 0
VS Code注释插件doxygen documentation generator
vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
602 0
vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
|
编译器 C语言
CodeBlocks出现Can‘t find compiler executable in your search path for GNU GCC Compier错误
CodeBlocks出现Can‘t find compiler executable in your search path for GNU GCC Compier错误
346 0
CodeBlocks出现Can‘t find compiler executable in your search path for GNU GCC Compier错误
Sublime Text自定义代码片段Code Snippets
Sublime Text自定义代码片段Code Snippets
267 0
|
前端开发 程序员
sublime_text 3安装Emmet时出现PyV8警告
使用Emmet是需要在PyV8依赖下才可以的。
sublime_text 3安装Emmet时出现PyV8警告
|
Python
【错误记录】PyCharm 运行 Python 程序报错 ( PEP 8: E305 expected 2 blank lines after class or function definiti )
【错误记录】PyCharm 运行 Python 程序报错 ( PEP 8: E305 expected 2 blank lines after class or function definiti )
849 0
【错误记录】PyCharm 运行 Python 程序报错 ( PEP 8: E305 expected 2 blank lines after class or function definiti )