Components
Code
A block of source code: monospaced, scrollable inside its own box, with a language label and a copy button.
Basic
Code is rendered as text, never as markup, so a Razor snippet full of angle brackets displays rather than runs.
<VetoButton Variant="VetoVariant.Filled" OnClick="Save">
Save
</VetoButton><VetoCode Language="razor" Code="@_snippet" />Line numbers and highlighted lines
ShowLineNumbers adds a gutter the reader cannot accidentally copy. HighlightLines takes numbers and ranges. FirstLineNumber is for an excerpt from the middle of a file; highlights follow the numbers shown.
public sealed class GreetingService{ public string Greet(string name) { ArgumentException.ThrowIfNullOrWhiteSpace(name); return $"Hello, {name}!"; }}public sealed class GreetingService{ public string Greet(string name) { ArgumentException.ThrowIfNullOrWhiteSpace(name); return $"Hello, {name}!"; }}<VetoCode Language="csharp" Code="@_service"
ShowLineNumbers="true" HighlightLines="3, 5-6" />
<VetoCode Language="csharp" Code="@_service"
ShowLineNumbers="true" FirstLineNumber="41" HighlightLines="43" />Wrapping and a height cap
Long lines scroll sideways by default. Wrap folds them instead. MaxHeight caps a long listing and scrolls it.
var message = "This line is long enough that it runs past the edge of the listing on any normal screen, which is exactly the case wrapping exists for.";var message = "This line is long enough that it runs past the edge of the listing on any normal screen, which is exactly the case wrapping exists for.";<VetoCode Language="text" Code="@_long" Wrap="true" />
<VetoCode Language="csharp" Code="@_file" MaxHeight="20rem" />Code as content
The code can be the component's content instead of a string. The copy button copies what is shown.
dotnet add package Veto<VetoCode Language="bash">dotnet add package Veto</VetoCode>Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
Code |
string? |
null |
The code to display, as text. |
ChildContent |
RenderFragment? |
null |
Code supplied as content instead of Code. |
Language |
string? |
null |
The label in the bar, e.g. razor. Null hides it. |
Copyable |
bool |
true |
Show a copy button. |
NotifyOnCopy |
bool |
true |
Raise a toast after copying, when toasts are registered. |
CopyToastMessage |
string |
"Code copied to clipboard" |
The toast after a successful copy. |
CopyFailedToastMessage |
string |
"Could not copy to the clipboard" |
The toast when the browser refused the write. |
ShowLineNumbers |
bool |
false |
Number each line in a gutter. Needs Code. |
FirstLineNumber |
int |
1 |
The number of the first line. |
HighlightLines |
string? |
null |
Lines to highlight: "2, 5-7". Needs Code. |
Wrap |
bool |
false |
Wrap long lines instead of scrolling sideways. |
MaxHeight |
string? |
null |
Caps the height and scrolls, e.g. 20rem. |