Class TwCodeBlock
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
public class TwCodeBlock : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, IAsyncDisposable
- Inheritance
-
TwCodeBlock
- Implements
- Inherited Members
Constructors
TwCodeBlock()
public TwCodeBlock()
Properties
Content
Gets or sets the code displayed in the block, and the text written to the clipboard by the copy button.
[Parameter]
public string? Content { get; set; }
Property Value
HideTitle
Gets or sets a value indicating whether the header bar is removed. When true the copy button is overlaid on the top end corner of the code panel instead, and Title is ignored.
[Parameter]
public bool HideTitle { get; set; }
Property Value
Inline
Gets or sets a value that has no effect on rendering. Retained for backwards compatibility.
[Parameter]
public bool Inline { get; set; }
Property Value
Language
Gets or sets the highlight.js language identifier applied to the code element as a language-* class.
Defaults to html.
[Parameter]
public string Language { get; set; }
Property Value
PanelClass
Gets or sets additional CSS classes applied to the inset panel (the pre element) that holds the code,
e.g. to adjust its padding. The container's Class is unaffected.
[Parameter]
public string? PanelClass { get; set; }
Property Value
Title
Gets or sets the text shown in the header bar. When null the Language
is shown in upper case instead (e.g. CSHARP).
[Parameter]
public string? Title { get; set; }
Property Value
Methods
BuildRenderTree(RenderTreeBuilder)
Renders the component to the supplied RenderTreeBuilder.
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builderRenderTreeBuilder
DisposeAsync()
Cancels any pending highlight or copy operation and releases the cancellation token source.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that completes once disposal has finished.
OnAfterRenderAsync(bool)
Highlights the code element on first render and again whenever Content changes. Interop failures are suppressed so rendering never fails.
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
firstRenderboolWhether this is the first time the component has rendered.
Returns
- Task
A task that completes once highlighting has finished or been abandoned.