GNU Source-highlight 文法高亮代碼

來源:互聯網
上載者:User

官方首頁

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

轉成html的用法是

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

就不貼圖了,覺得預設style不好看就自己改一改

作者:feiskyer 發表於2011-12-18 21:45:12 原文連結 閱讀:26 評論:0 查看評論

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.