找回密码
 注册
关于网站域名变更的通知
查看: 396|回复: 1
打印 上一主题 下一主题

GNU Source-highlight 语法高亮代码

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-3-16 09:33 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
官方主页
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:
2 M; n( ?4 `' y3 `HTML(这个vim用:TOhtml也可以)+ l7 L) p) K3 A. C; O( B- K  d5 a# w
XHTML" ?8 U; f" X3 N/ X& K9 |8 \
LATEX5 l# Q7 ?. g" u
TEXINFO% p% P" ]; ?, x# R" h+ A; W
ANSI color escape sequences (可以在水木上彩色显示代码,vim有TOansi插件也可以,
DocBook
These are the input languages (or input formats) already supported (in alphabetical order):# Q1 o6 ?) P4 `* x9 \
C/C++
$ [2 c9 R7 }2 @, ?, q5 AC#
& [, s! c  z) m. F9 f- z, ?' y* wBib
# L( I8 O% K1 i# OBison; `- g3 d- e8 l; j$ X9 L- S; b* T$ d0 {
Caml
( g* a0 w0 P2 Y, W+ ]. E2 K& vChangelog6 B  h' }+ u% S8 b9 C4 U$ n. |* R3 t
Css             (new)
$ g7 P9 P# ?" X: P& SDiff
3 q7 ?+ }, X0 d2 h$ j6 B# u& iFlex
3 D8 h$ c$ a! w% z, |" f" [4 eFortran
: g6 [1 [: M' T: ~; THtml
' |4 f1 `& w. S' N( ^  FJava
) N: v  Z  u. h- EJavascript+ Z: U9 W" S* S! h
Latex
& _0 C. S; F/ Q7 l) Z3 tLogtalk
, _# N" U9 W  V' h0 _" C8 J: @0 {" \Log files6 U/ ~6 a2 l9 Z
Lua
: D" m, h0 M5 f. V" qMakefile             (new)) [- h& ]0 y# C7 ]4 D
M4             (new)
2 ?& C) e; U. @2 ?ML  z" q4 m8 g( f3 _
Pascal, ~/ }8 C; g6 o7 ~. S& ?+ u% p
Perl
; w( P7 G2 y' e" ?9 Z) ?! \PHP  V: S) z0 p! d+ O9 @
Postscript  \' ]; L. P* X0 ~% C7 w: ?
Prolog
! N* X+ P* y1 r& n, H7 x/ ]Python' F% R! t$ B$ _
Ruby
; I: r( m# [" M( E" |) P+ YShell; o$ U( L8 F, L! f6 Y: T, Z
Sql
5 c- a. }+ B. D( @' `3 G: v+ PTcl
, M9 ?9 o$ ]. {% ]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+ z/ o( m4 t+ F" |
files, but this* f7 K% D5 j2 `- N
is valid also for other source-highlight input languages):& L5 A* {4 D- L
source-highlight --src-lang cpp --out-format html \
* B* u, z4 f* w0 l0 k--input <C++ file> \
& {4 M5 x( w' Z--output <html file> \
& s0 z( R% N" \+ K7 ]& x--style-file <style file> \
; b/ `. G0 W( a& f& [! H( Roptions
" I. L- U) O4 i; s& V6 BFor input files, apart from the -i (--input) option and the standard input redirection, you
& u% g% F" o: u4 H! _( u, Xcan simply specify some files at the command line and also use regular expressions (for instance
/ t  }7 i. ~" t; Y: R6 {' n‘*.java’). In this case the name for the output files will be formed using the name of the source8 u* K. N% l1 v" {, Y" x2 _" \9 b$ o
file with a .<ext> appended, where <ext> is the extension chosen according to the output format  o: ^9 Y$ o# ~6 T3 ]- C
specified (in this example it would be .html). The style file (Section 5.1 [Output format style],5 }' U$ p. d0 h+ \) K7 v; `
page 8) contains information on how to format specific language parts (e.g., keywords in blue
, M% u" H2 Y2 J+ ]7 O  uand boldface, etc.). If STDOUT string is passed as -o (--output) option, then the output is forced2 U* _. l5 _6 v2 e$ ]  W( A: c
to the standard output anyway.; X) F; r6 X' V& _4 K( {5 i
If -s (--src-lang) is not specified, the source language is inferred by the extension of the
, F% i$ o+ ?, ~$ [- s8 f1 }: Iinput file (this, of course, does not work with standard input redirection).- l! I1 [3 k3 Y1 c
If -f (--out-format) is not specified, the output will be produced in HTML." ~" w, B& p* z* V
If --style-file is not specified, the ‘default.style’, which is included in4 \0 C4 v! P1 [* u
the distribution,will be used。
自带文档说的更详细
  V! F; U7 O6 L4 Z.style和.outlang都可以改得,比如附带的esc.style(输出成ansi彩色用的色彩配置文件)是
keyword blue b ;
: k+ P* _$ ]3 u6 c. Jtype darkgreen ;% N2 l5 ~1 V: F; @: Y% v- f+ t+ H1 ?, C
string red ;
' U' P  S4 v1 e) }* X( Scomment brown i ;/ h7 c- V% w) \9 M  k: W
number purple ;
! Z! p+ U4 L& H0 O0 o" _preproc darkblue b ;5 |7 z. [, i' G2 I
symbol darkred ;% P4 I3 Y: Y. c" A+ m
function black b;
; e5 F5 t' `0 Qcbracket red;
// line numbers! r0 Y, R+ W8 s8 d% z: T- ~# v; E4 Q
linenum yellow;
输出出来在term下不是很好看,我把它改成
keyword green b ;
' i: j  V; |+ w7 I, [. `! h8 x  @type green ;
5 v/ G9 `! w+ H& h" xstring yellow ;
8 F% R( d; h) L+ \: kcomment cyan i ;4 d2 e$ G3 q) X
number yellow ;; v  t5 X7 Z, O3 Z7 A7 ]8 L
preproc blue b ;( m5 g+ x! G6 T4 C; o
symbol purple ;+ }9 `3 o3 P2 b$ {, T/ ~0 X
function red b;
4 \: H8 G3 p- @8 N2 b9 x/ X( [' E' ocbracket purple;
// line numbers
3 ]2 W# {% ?1 p+ B+ I/ E- _linenum yellow;
改了之后term上水木的截图
7 f: v$ h* u/ K  E
转成html的用法是
source-highlight.exe -s cpp -f html --input comments.cpp --output xxx.html
就不贴图了,觉得默认style不好看就自己改一改

9 q% m* L$ U/ e: e. f. m* ?

该用户从未签到

2#
发表于 2020-3-16 16:01 | 只看该作者
GNU Source-highlight 语法高亮代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-11-26 01:32 , Processed in 0.140625 second(s), 26 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表