Syntax Reference¶
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
|
Optional[Sequence[ColorType]]
|
Foreground gradient color stops. |
None
|
bg_colors
|
Optional[Sequence[ColorType]]
|
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
|
Scale factor controlling gradient repeats. |
2.0
|
expand
|
bool
|
Whether the gradient frame expands. |
True
|
justify
|
AlignMethod
|
Horizontal alignment. |
'left'
|
vertical_justify
|
VerticalAlignMethod
|
Vertical alignment. |
'middle'
|
console
|
Optional[Console]
|
Optional Rich console. |
None
|
highlight_words
|
Optional[HighlightWordsType]
|
Word highlight configuration. |
None
|
highlight_regex
|
Optional[HighlightRegexType]
|
Regex highlight configuration. |
None
|
Source code in src/rich_gradient/syntax.py
17 18 19 20 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 | |
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=2.0, expand=True, justify='left', vertical_justify='middle', console=None, highlight_words=None, highlight_regex=None)
¶
Initialize gradient-enabled Rich syntax highlighting.