Syntax Reference¶
See the Syntax guide for usage examples.
Bases: Gradient
A Rich syntax-highlighting convenience constructor with gradient rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Source code to highlight. |
required |
lexer
|
str | Lexer
|
Lexer name or Pygments lexer instance. |
required |
theme
|
str
|
Pygments style theme. |
'monokai'
|
dedent
|
bool
|
Whether to strip initial indentation. |
False
|
line_numbers
|
bool
|
Whether to render line numbers. |
False
|
start_line
|
int
|
Starting line number. |
1
|
line_range
|
tuple[int | None, int | None] | None
|
Optional start/end line range. |
None
|
highlight_lines
|
set[int] | None
|
Optional line numbers to highlight. |
None
|
code_width
|
int | None
|
Optional code width. |
None
|
tab_size
|
int
|
Spaces per tab. |
4
|
word_wrap
|
bool
|
Whether to wrap long lines. |
False
|
background_color
|
str | None
|
Optional background color. |
None
|
indent_guides
|
bool
|
Whether to show indentation guides. |
False
|
padding
|
PaddingDimensions
|
Padding around syntax output. |
0
|
colors
|
Sequence[ColorType] | None
|
Foreground gradient color stops. |
None
|
bg_colors
|
Sequence[ColorType] | None
|
Background gradient color stops. |
None
|
rainbow
|
bool
|
Whether to generate a rainbow palette. |
False
|
hues
|
int
|
Number of auto-generated hues. |
5
|
repeat_scale
|
float | None
|
Scale factor controlling gradient repeats. Defaults to None, which derives it from the color stops. |
None
|
expand
|
bool
|
Whether the gradient frame expands. |
True
|
justify
|
AlignMethod
|
Horizontal alignment. |
'left'
|
vertical_justify
|
VerticalAlignMethod
|
Vertical alignment. |
'middle'
|
console
|
Console | None
|
Optional Rich console. |
None
|
highlight_words
|
HighlightWordsType | None
|
Word highlight configuration. |
None
|
highlight_regex
|
HighlightRegexType | None
|
Regex highlight configuration. |
None
|
keep_token_colors
|
bool
|
Keep the theme's colors for highlighted tokens
(keywords, strings, comments, ...). Only plain code, line numbers
and whitespace take the gradient. Set to |
True
|
Source code in src/rich_gradient/syntax.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
syntax
property
¶
Return the underlying Rich Syntax renderable.
__init__(code, lexer, *, theme='monokai', dedent=False, line_numbers=False, start_line=1, line_range=None, highlight_lines=None, code_width=None, tab_size=4, word_wrap=False, background_color=None, indent_guides=False, padding=0, colors=None, bg_colors=None, rainbow=False, hues=5, repeat_scale=None, expand=True, justify='left', vertical_justify='middle', console=None, highlight_words=None, highlight_regex=None, keep_token_colors=True)
¶
Initialize gradient-enabled Rich syntax highlighting.