找回密码
 注册
关于网站域名变更的通知
查看: 390|回复: 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:
6 U$ f1 j9 N  X2 R" uHTML(这个vim用:TOhtml也可以)
, G, z; b* v( cXHTML% R9 Q; q# \8 J2 f( L' h5 Z: g! T
LATEX
5 f# _7 e* R1 x+ K1 q* `- J5 m3 H4 z- VTEXINFO
8 l( x+ I' ^0 ^, `( C! c; QANSI color escape sequences (可以在水木上彩色显示代码,vim有TOansi插件也可以,
DocBook
These are the input languages (or input formats) already supported (in alphabetical order):
8 S" t$ j+ ], rC/C++) }3 r9 o5 [' A  I% p4 V5 \
C#
7 |# p3 j# u( V, C7 L2 T9 G3 @% q; ^Bib
. r5 {/ L  l- |Bison9 ^% B5 z1 O" h# d+ e
Caml
: }! T% o. y& ~2 Q6 q6 j& \) xChangelog
, [7 n+ E/ m" O4 @) s- hCss             (new)
3 K' m  n7 m9 a  eDiff
& c/ q. i  O2 d6 f# w7 aFlex
* T0 C% `6 z( Z5 b4 T. z* ]Fortran
; }$ L; }$ Z/ S% u5 LHtml
- l( g6 `! b( {* [- p3 g( ^9 s, C& vJava
+ [0 _$ b# _+ O9 {+ U1 k* Y6 \Javascript
+ K! k& w9 ^* l0 m  {" W& qLatex
; E# ~% z/ f- }9 J! P  E7 _! m5 OLogtalk1 j: L1 A, h+ p' G& l1 @8 T4 L
Log files
+ b) i, i1 f& D. D# f; L% hLua
( |& D: x5 {2 k# u1 k4 J1 u+ GMakefile             (new)
; @+ l. E% g! f7 ^+ x  AM4             (new)& e3 ?1 ]# t: U* K
ML1 V/ s3 W# H5 {' v3 m5 H' K
Pascal$ V+ Q9 l; F# T
Perl
" l: M9 D" R; o: s$ ^PHP
3 V, O. E/ b5 |1 {& RPostscript
; J' {; w5 d! B) Z/ k1 q  e5 rProlog
8 T0 r! s6 p& G* e; {Python- W; A5 S1 B9 Z2 u/ E
Ruby! d5 p5 S! n5 K3 o; W. k, }- M
Shell0 S! @' U3 E+ k
Sql9 g( @( t2 ]. j& v1 H: |8 |
Tcl1 Y# R- o# N, @# w+ m+ s! f+ H
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
# R; c' W0 r- Afiles, but this- l3 ]+ s0 D8 u% N' d+ v/ N
is valid also for other source-highlight input languages):3 w- b+ F9 N( ]
source-highlight --src-lang cpp --out-format html \
, G/ T# k7 C5 r5 M. @--input <C++ file> \- k  r% N5 ]' J. ~3 C& \$ G7 d1 }
--output <html file> \
, h/ P, v7 k7 m7 ], B/ T--style-file <style file> \: r- r' ~2 x& c) V$ p
options
. T& E4 ?+ U) ?/ jFor input files, apart from the -i (--input) option and the standard input redirection, you
. ?! }5 D) v" ucan simply specify some files at the command line and also use regular expressions (for instance
. y5 ^6 A/ a% Z‘*.java’). In this case the name for the output files will be formed using the name of the source* F! s- r  R2 e! P
file with a .<ext> appended, where <ext> is the extension chosen according to the output format
8 D7 y5 M; \2 j4 V4 k6 ispecified (in this example it would be .html). The style file (Section 5.1 [Output format style],
8 @9 R) L% G- Npage 8) contains information on how to format specific language parts (e.g., keywords in blue& C8 G1 u. R& k) Y" O" e, |; e: E
and boldface, etc.). If STDOUT string is passed as -o (--output) option, then the output is forced
  r/ `: E9 I; {" p% P4 n  Qto the standard output anyway.
5 A2 R% U  _- ]) L/ ]6 wIf -s (--src-lang) is not specified, the source language is inferred by the extension of the
0 f! D7 l$ t( D8 v; g" Linput file (this, of course, does not work with standard input redirection).
: I* j4 g% `* ]% d( w: l0 \If -f (--out-format) is not specified, the output will be produced in HTML.8 J/ Z+ g8 O2 z( ^6 F+ O* Y3 ~, p
If --style-file is not specified, the ‘default.style’, which is included in6 k( R3 ?4 R& W  [8 T# J: P
the distribution,will be used。
自带文档说的更详细
5 e2 m* W3 r. {) j2 {6 q/ K.style和.outlang都可以改得,比如附带的esc.style(输出成ansi彩色用的色彩配置文件)是
keyword blue b ;
8 I, A1 o' F/ f8 ?+ u% ptype darkgreen ;
/ ~* V4 R/ F! c! l! U+ a; N& O& b' @& @string red ;$ m$ n2 C' W) S8 q! s+ d2 m1 E
comment brown i ;
+ M  B0 Z) [# ]6 Y' knumber purple ;
) h5 r) d4 i) T# u9 c" X: bpreproc darkblue b ;) q8 z6 i$ ^& U) H3 d
symbol darkred ;: @( C8 t0 y7 ]- f2 k* p
function black b;5 u* }7 V# ^3 ^; i0 ]
cbracket red;
// line numbers
* @- r- m4 N: w- l$ O) W9 a" ~, P: zlinenum yellow;
输出出来在term下不是很好看,我把它改成
keyword green b ;  n, W( z6 D) |- i# \# D
type green ;
6 b; h# c. v, m# m, h7 M% |, Kstring yellow ;
9 {# [0 F2 P; vcomment cyan i ;% y) d9 [) [. v" C
number yellow ;
9 o4 j2 e5 p) t0 }. J, D8 q: u4 npreproc blue b ;% T2 @8 s6 C5 L" j9 j6 I* F/ X& h7 O0 R
symbol purple ;
+ T4 J" y3 ~) F" Z2 O; cfunction red b;
3 Y" z2 T0 |. P9 Ocbracket purple;
// line numbers
  |' g1 M8 n& G/ ^; \linenum yellow;
改了之后term上水木的截图

  Z$ h6 P/ |/ `+ ]: S5 k
转成html的用法是
source-highlight.exe -s cpp -f html --input comments.cpp --output xxx.html
就不贴图了,觉得默认style不好看就自己改一改

! P: _* ^( H  R! Q2 t8 Z

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-11-25 18:45 , Processed in 0.203125 second(s), 27 queries , Gzip On.

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

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

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