Syntax highlighting for prompt_toolkit and HTML with pyparsing.
Project description
Syntax highlighting with pyparsing, supporting both HTML output and prompt_toolkit–style terminal output. The PPHighlighter class can also be used as a lexer for syntax highlighting as you type in prompt_toolkit. It is compatible with existing Pygments styles.
Read the documentation on readthedocs.
Requirements
Python 3.5+
prompt_toolkit 2.0+
Installation
After cloning the repository:
python3 setup.py install
Examples
The following code demonstrates the use of PPHighlighter:
from pp_highlighting import PPHighlighter
import pyparsing as pp
from pyparsing import pyparsing_common as ppc
def parser_factory(styler):
a = styler('class:int', ppc.integer)
return pp.delimitedList(a)
pph = PPHighlighter(parser_factory)
pph.highlight('1, 2, 3')
pph.highlight('1, 2, 3') returns the following:
FormattedText([('class:int', '1'), ('', ', '), ('class:int', '2'), ('', ', '), ('class:int', '3')])
A FormattedText instance can be passed to prompt_toolkit.print_formatted_text(), along with a Style mapping the class names to colors, for display on the terminal. PPHighlighter also has a highlight_html() method which returns the generated HTML as a string.
PPHighlighter can also be passed to a prompt_toolkit.PromptSession as the lexer argument, which will perform syntax highlighting as you type. For an example of this, see pp_highlighting/examples/calc.py and pp_highlighting/examples/repl.py.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyparsing-highlighting-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee4c258ab04bb4db2a262b3abb6105da604aaefd0e06af1d725668714e37a9f9 |
|
MD5 | c7cd8b35e0dc15d7d0d5ae646e75f05a |
|
BLAKE2b-256 | 1cac875d1af915a79a0598a733df0239fbb839db40c8d4252ca118326b6a1b47 |
Hashes for pyparsing_highlighting-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f622ee5e32f6de20a2c8f406564faecd65fd3184dfe11823a6abb1e78fd0c6f |
|
MD5 | f32b28a059ce28ec4ea18f074647b7d1 |
|
BLAKE2b-256 | fbbdfe97b76e9cb748d14ce71ad7741a9a55a592aa9a517721df033f66283176 |