highlight

Highlight text on the command line.

Docs

Documentation Build Status Docs Check Status

Tests

Linux Test Status macOS Test Status Coverage

Activity

GitHub last commit GitHub commits since tagged version Maintenance

QA

CodeFactor Grade Flake8 Status mypy status

Other

License GitHub top language Requirements Status

Installation

python3 -m pip install git+https://github.com/domdfcoding/highlight@master --user

Contents

highlight

Print the content of FILE with syntax highlighting.

With no FILE, or when FILE is -, read standard input.

highlight [OPTIONS] [FILE]

Options

-m, --mime <mime>

The MIME time to use for highlighting.

-l, --lexer <lexer>

The Pygments lexer to use for highlighting.

-T, --show-tabs

Display TAB characters as ^I.

-E, --show-ends

Display $ at the end of each line.

-n, --number

Number all output lines.

-D, --debug

Print the lexer name to stderr.

--version

Show the version and exit.

Arguments

FILE

Optional argument. Default None

Notes

  • --lexer and --mime are mutually exclusive.

  • If no --lexer or --mime option is given, the lexer is determined from FILE. If reading from standard input, of if the file extension is unknown, the lexer is determined by examining the file’s contents.

  • If the --mime option is given but no lexer can be found for that mime type the mime type is ignored.

  • See https://pygments.org/docs/lexers/ for a list of available lexers.

Examples

Highlight a Python source code file.

highlight code.py

Highlight a Ruby source code file with the RubyConsoleLexer.

highlight code.rb --lexer rbcon

Highlight a Rust source code file with line numbers.

highlight main.rs --number

Contributing

highlight uses tox to automate testing and packaging, and pre-commit to maintain code quality.

Install pre-commit with pip and install the git hook:

python -m pip install pre-commit
pre-commit install

Coding style

formate is used for code formatting.

It can be run manually via pre-commit:

pre-commit run formate -a

Or, to run the complete autoformatting suite:

pre-commit run -a

Automated tests

Tests are run with tox and pytest. To run tests for a specific Python version, such as Python 3.6:

tox -e py36

To run tests for all Python versions, simply run:

tox

Type Annotations

Type annotations are checked using mypy. Run mypy using tox:

tox -e mypy

Build documentation locally

The documentation is powered by Sphinx. A local copy of the documentation can be built with tox:

tox -e docs

Downloading source code

The highlight source code is available on GitHub, and can be accessed from the following URL: https://github.com/domdfcoding/highlight

If you have git installed, you can clone the repository with the following command:

git clone https://github.com/domdfcoding/highlight
Cloning into 'highlight'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 173 (delta 16), reused 17 (delta 6), pack-reused 126
Receiving objects: 100% (173/173), 126.56 KiB | 678.00 KiB/s, done.
Resolving deltas: 100% (66/66), done.
Alternatively, the code can be downloaded in a ‘zip’ file by clicking:
Clone or download –> Download Zip
Downloading a 'zip' file of the source code.

Downloading a ‘zip’ file of the source code

Building from source

The recommended way to build highlight is to use tox:

tox -e build

The source and wheel distributions will be in the directory dist.

If you wish, you may also use pep517.build or another PEP 517-compatible build tool.

License

highlight is licensed under the MIT License

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

Permissions Conditions Limitations
  • Commercial use
  • Modification
  • Distribution
  • Private use
  • Liability
  • Warranty

Copyright (c) 2021 Dominic Davis-Foster

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.

View the Function Index or browse the Source Code.

Browse the GitHub Repository