pub struct Syntax { /* private fields */ }Expand description
A block of syntax-highlighted source code. Mirrors rich.syntax.Syntax.
Implementations§
Source§impl Syntax
impl Syntax
Sourcepub fn word_wrap(self, wrap: bool) -> Self
pub fn word_wrap(self, wrap: bool) -> Self
Wrap lines wider than the render width instead of cropping them.
Off by default, matching upstream’s Syntax(word_wrap=False): a long
line is cut at the width. Upstream’s CLI turns this on, which is why
rich --syntax does too — cropping a source file silently loses code.
Sourcepub fn new(code: impl Into<String>, language: impl Into<String>) -> Self
pub fn new(code: impl Into<String>, language: impl Into<String>) -> Self
Highlight code as language (a name or file extension, e.g. "rust"
or "rs"). Pass an empty/unknown language to render as plain text.
Sourcepub fn tab_size(self, tab_size: usize) -> Self
pub fn tab_size(self, tab_size: usize) -> Self
How far a tab advances the column, in characters. Upstream’s
Syntax(tab_size=…), default 4.
Tabs are expanded to spaces before highlighting (upstream’s
code.expandtabs(self.tab_size)), so this is the only tab handling in
play — the rendered code contains no U+0009 at all.
Sourcepub fn padding(self, padding: usize) -> Self
pub fn padding(self, padding: usize) -> Self
Surround the code with padding cells of background on every side.
Upstream’s Markdown renders a fenced block as Syntax(..., padding=1),
which is what gives a code block its blank inset row above and below and
its one-column gutter. Without it the code sat flush against the
surrounding text and every document containing a fence diverged.
Trait Implementations§
Source§impl Renderable for Syntax
impl Renderable for Syntax
fn rich_render( &self, _console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
(minimum, maximum) cell width this renderable wants. The default
assumes the renderable fills the available width (e.g. Panel, Table);
Text overrides it with its content width so the top-level print path can
shrink to fit. Port of __rich_measure__ / Measurement.get.