找回密码
 注册
关于网站域名变更的通知
查看: 394|回复: 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:
7 R& p) {- l- p2 _HTML(这个vim用:TOhtml也可以)& z1 ]/ ]3 O9 Q% z# N
XHTML0 |0 B# N4 t. _$ Q! N4 x
LATEX
1 L3 j7 t0 |- fTEXINFO
# h+ d! Z" F( c% I; K" UANSI color escape sequences (可以在水木上彩色显示代码,vim有TOansi插件也可以,
DocBook
These are the input languages (or input formats) already supported (in alphabetical order):  q, D1 m) Q9 h# \+ Y- E, N, J& p
C/C++6 r* |2 w& `5 r" k; Y2 r8 @* d9 I
C#! U' f- h" Y$ b9 b5 P8 T! L- d
Bib
' N# v! Z- K& |: M* x& I3 a3 h; UBison
8 C+ a5 t; h) c/ lCaml; l9 ]. T2 R. s0 b
Changelog  R2 n  g! w) w2 y8 J9 C: M
Css             (new)" z% h& |: R7 D
Diff
5 J1 V& u2 {( O) B0 E. vFlex
# O# z1 }& c( h! s+ n$ TFortran; l& y. X: t/ j" v: t/ ~7 _8 z
Html
0 U* b* k; K" i( b: u6 T4 OJava9 d- d8 X$ N) o: {1 J- J
Javascript+ r3 ?  {4 j7 a6 W/ v
Latex
' G" a" l: N4 v6 _3 {Logtalk+ {7 r5 ]6 ~3 D' _& `; t
Log files
$ n* C) L2 U8 y9 X) E! ZLua4 ~2 h- V6 I" M! T8 Q
Makefile             (new)
- i+ q/ J. [. Z; }% kM4             (new)
' J/ |) `0 v- l& z3 e! P8 q. EML$ k. w% T0 h3 |  b- y
Pascal# t# p1 Z: Y+ r+ }* V8 X+ {0 A
Perl; O$ ?# f8 }$ @2 l# d5 |7 C  J$ s* d, _
PHP
4 K  I$ u  M9 ?6 N! c2 |8 o9 hPostscript
, ~2 [, e# R# t8 u- ?Prolog
9 k$ e8 ^" r8 r+ l) {Python
1 p1 d$ \, h4 M3 zRuby
. ~' t( w& J# r1 o. TShell
0 S6 R* u2 V! }; j& y8 X4 hSql2 y) Q4 i7 R$ v% }# ^6 |$ J
Tcl) @! O/ v; n2 G8 `: ~5 }
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: I3 ^0 z) H1 T1 _
files, but this6 m+ V& l" J( q6 w" W% F5 a
is valid also for other source-highlight input languages):7 l& z% L! h" c7 w4 Q) Y
source-highlight --src-lang cpp --out-format html \# l- J0 D; H5 h& ^
--input <C++ file> \! d& W8 u) D4 `- _* M! [9 V
--output <html file> \
: ~% j# `8 {* j. r( s# a--style-file <style file> \
( y* d- i4 \0 R; [& zoptions! r, K4 P( v! V/ ]& D
For input files, apart from the -i (--input) option and the standard input redirection, you
- |5 _( o  W5 i7 ~7 ?can simply specify some files at the command line and also use regular expressions (for instance8 B3 \9 W8 [- Y$ Z( }8 N: e' t
‘*.java’). In this case the name for the output files will be formed using the name of the source* t  A2 A! t* P$ Z
file with a .<ext> appended, where <ext> is the extension chosen according to the output format7 Q, P! x7 A6 X. o3 ^( h6 K( j/ ?
specified (in this example it would be .html). The style file (Section 5.1 [Output format style],
& e3 I5 z0 ]- C2 H# kpage 8) contains information on how to format specific language parts (e.g., keywords in blue
% e7 [/ ~; S, ?: _and boldface, etc.). If STDOUT string is passed as -o (--output) option, then the output is forced- c  C9 S9 R# a+ H; B; ^' e
to the standard output anyway.
  ?0 ], P$ X* ~3 hIf -s (--src-lang) is not specified, the source language is inferred by the extension of the! [4 M# x9 R( j( c
input file (this, of course, does not work with standard input redirection).
$ O" l* L) O) b9 j% ~' h1 OIf -f (--out-format) is not specified, the output will be produced in HTML.: |; ^( U* G4 u2 t0 l, J
If --style-file is not specified, the ‘default.style’, which is included in& U2 X( H4 I. K# T3 H4 Y% |3 l
the distribution,will be used。
自带文档说的更详细' N: `: g& O; c" s0 r
.style和.outlang都可以改得,比如附带的esc.style(输出成ansi彩色用的色彩配置文件)是
keyword blue b ;
6 _7 u; Y8 H5 v- a: l" r7 dtype darkgreen ;
) L! j7 ?( o: |3 e  S5 U: i' }string red ;
$ x. p$ q% Z" z: H( z" i! m1 V. ccomment brown i ;4 F2 S! o7 P' P$ G
number purple ;
5 P" M" ]3 [6 H5 W, F0 vpreproc darkblue b ;
( p+ P' v0 \4 F( f  u/ vsymbol darkred ;+ E9 N+ }1 F- Y4 G
function black b;
: d5 K9 b) Z% Fcbracket red;
// line numbers( S3 y# }' p3 p( b- l: y0 b
linenum yellow;
输出出来在term下不是很好看,我把它改成
keyword green b ;
/ A" M4 S% Z: A' S9 M% j9 a# X' j' itype green ;9 [+ s4 W( T. A; h% d+ p* h* _
string yellow ;
+ b, i0 c( [; }$ h9 h6 ?: K; `& Fcomment cyan i ;9 ?- p7 q' E+ j4 ]7 S" ^' \, r
number yellow ;! x+ M- l& t$ y  Y% Q1 y
preproc blue b ;
/ b# R. i: S2 S  Tsymbol purple ;
& v: E1 U) f2 T3 ^: jfunction red b;
) O+ G7 O) E! Y0 K0 V2 p0 k# O  Mcbracket purple;
// line numbers
3 v+ N" l# q7 B- llinenum yellow;
改了之后term上水木的截图
6 w) l* r# R* h4 v* ~/ N/ d5 Z
转成html的用法是
source-highlight.exe -s cpp -f html --input comments.cpp --output xxx.html
就不贴图了,觉得默认style不好看就自己改一改
3 T8 v' ^, S( }

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-11-25 22:17 , Processed in 0.156250 second(s), 27 queries , Gzip On.

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

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

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