← 返回命令列表

Linux command

source-highlight 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Highlight a source file

source-highlight -i [file.java] -o [file.html]

Highlight with automatic language detection

source-highlight [file.py]

Specify source language

source-highlight -s [cpp] -i [file.cc]

Output to a different format

source-highlight -f [latex] -i [file.c] -o [file.tex]

Highlight multiple files

source-highlight *.java

List supported languages

source-highlight --lang-list

List supported output formats

source-highlight --outlang-list

Highlight from stdin

cat [file.py] | source-highlight -s python

说明

source-highlight converts source code files to syntax-highlighted documents in various output formats. It reads language specifications dynamically, making it easily extensible for new programming languages without recompilation. The tool supports numerous programming languages including C, C++, Java, Python, Perl, Ruby, Shell, and many more. Output formats include HTML, XHTML, LaTeX, ANSI terminal escape sequences, and others. When processing multiple files using wildcards, output filenames are automatically generated by appending the appropriate extension. The tool can also be used as a CGI script for web-based highlighting or integrated with less for automatic syntax highlighting when viewing source files.

参数

-i, --input _file_
Input file. Default: stdin.
-o, --output _file_
Output file. Default: stdout or input file with appropriate extension.
-s, --src-lang _lang_
Source language. If not specified, guessed from file extension.
-f, --out-format _format_
Output format (html, xhtml, latex, texinfo, ansi, odt, etc.).
--style-file _file_
Style file for highlighting colors and styles.
--lang-list
List all supported source languages.
--outlang-list
List all supported output formats.
--lang-def _file_
Use custom language definition file.
--outlang-def _file_
Use custom output language definition file.
-n, --line-number=_padding_
Add line numbers with optional padding width.
--tab _n_
Set tab width (default: 8).
--title _string_
Set document title.
--css _file_
Use CSS file for HTML output.
-d, --doc
Create a standalone document.
-h, --help
Display help information.
-V, --version
Display version information.

FAQ

What is the source-highlight command used for?

source-highlight converts source code files to syntax-highlighted documents in various output formats. It reads language specifications dynamically, making it easily extensible for new programming languages without recompilation. The tool supports numerous programming languages including C, C++, Java, Python, Perl, Ruby, Shell, and many more. Output formats include HTML, XHTML, LaTeX, ANSI terminal escape sequences, and others. When processing multiple files using wildcards, output filenames are automatically generated by appending the appropriate extension. The tool can also be used as a CGI script for web-based highlighting or integrated with less for automatic syntax highlighting when viewing source files.

How do I run a basic source-highlight example?

Run `source-highlight -i [file.java] -o [file.html]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i, --input _file_ do in source-highlight?

Input file. Default: stdin.