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


相关文章
|
Web App开发 开发工具 git
如何下载Github上的单个文件或者指定目录?
如何下载Github上的单个文件或者指定目录?
5044 0
如何下载Github上的单个文件或者指定目录?
|
2月前
|
缓存 项目管理 开发工具
UV实战教程,我啥要从Anaconda切换到uv来管理包?
本文对比Anaconda“手动挡”与uv“全自动挡”环境管理:uv以“项目即环境”为核心,支持`uv init`一键初始化、自动下载Python、智能依赖管理(`uv add/sync/run`)及PyCharm无缝对接,大幅提升Python开发效率与协作体验。(239字)
914 11
UV实战教程,我啥要从Anaconda切换到uv来管理包?
|
SQL 人工智能 数据可视化
16.1k star! 只需要DDL就能一键生成数据库关系图!开源神器ChartDB让你的数据结构"看得见"
ChartDB是一款开源的数据库可视化神器,通过一句智能查询就能自动生成专业的数据库关系图。无需安装客户端、不用暴露数据库密码,打开网页就能完成从数据建模到迁移的全流程操作,堪称开发者的"数据库透视镜"。
2679 67
|
前端开发 JavaScript API
Webview+Python:用HTML打造跨平台桌面应用的创新方案
本文系统介绍了使用PyWebView库结合HTML/CSS/JavaScript开发跨平台桌面应用的方法。相比传统方案(如PyQt、Tkinter),PyWebView具备开发效率高、界面美观、资源占用低等优势。文章从技术原理、环境搭建、核心功能实现到性能优化与实战案例全面展开,涵盖窗口管理、双向通信、系统集成等功能,并通过“智能文件管理器”案例展示实际应用。适合希望快速构建跨平台桌面应用的Python开发者参考学习。
1679 1
|
存储 设计模式 算法
【C++ 泛型编程 高级篇】 C++ 17 解析std::apply 的多种应用场景(一)
【C++ 泛型编程 高级篇】 C++ 17 解析std::apply 的多种应用场景
1538 0
|
传感器 边缘计算 监控
探索未来网络:物联网技术的革新与挑战
在21世纪的科技浪潮中,物联网(IoT)正迅速成为连接实体世界与数字世界的关键桥梁。本文旨在深入探讨物联网技术的最新进展、面临的主要挑战以及未来的发展趋势。通过分析当前物联网的核心技术,如传感器技术、低功耗广域网(LPWAN)、边缘计算等,本文揭示了这些技术创新如何推动智能城市、智能家居、工业4.0等领域的快速发展。同时,针对数据安全、隐私保护、标准化等关键问题,提出了相应的解决策略和建议。本文最后展望了物联网技术在未来可能带来的社会变革和商业模式创新,强调了跨学科合作的重要性,以实现物联网技术的可持续发展。
|
搜索推荐 安全 API
Matomo用户行为分析 - 安装篇
Matomo用户行为分析 - 安装篇
542 0
vcpkg安装软件包时自定义编译选项
vcpkg安装软件包时自定义编译选项
1327 0
|
监控 物联网 Java
打造高可用系统:深入了解心跳检测机制
本文介绍了分布式系统中**心跳检测**的重要机制,用于监测系统节点的健康状态和通信畅通。心跳检测通过定期发送信号,若节点在预定期限内未响应则视为可能失效。处理机制包括重试、报警和自动修复。文章还提到了**周期检测**和**累计失效检测**两种策略,并给出Java代码示例展示心跳检测实现。此外,列举了心跳检测在分布式数据库、微服务和物联网等场景的应用,以及优化策略如动态调整心跳频率和优化超时机制。最后,强调了心跳检测对系统稳定性和高可用性的关键作用。
2735 2
|
网络协议 Linux
TCP中两种保活方式
【4月更文挑战第7天】两种保活方式:Keep Alive和心跳包

热门文章

最新文章