Class MarkdownCodeBlock
A read-only view that renders a single Markdown fenced code block with a dimmed background and an optional copy button.
public class MarkdownCodeBlock : View, IDisposable, ISupportInitializeNotification, ISupportInitialize, IDesignable
- Inheritance
-
MarkdownCodeBlock
- Implements
- Inherited Members
- Extension Methods
Remarks
When used inside a Markdown, instances are created automatically during layout and positioned as SubViews at the correct content coordinate so that they scroll naturally with the parent's viewport.
The dimmed background fills the full width of the view (via Width = Dim.Fill()),
so it automatically resizes when the content area width changes.
This view can also be used standalone. Set Text to a fenced code block
(e.g. ```csharp\ncode\n```) or plain text. The language is extracted automatically
from the opening fence.
Constructors
- MarkdownCodeBlock()
Initializes a new MarkdownCodeBlock.
Properties
- CodeLines
Gets or sets the plain-text code lines. Setting this re-creates the internal styled segments. When SyntaxHighlighter and Language are both set, lines are syntax-highlighted; otherwise they use CodeBlock styling.
- Language
Gets or sets the language identifier for syntax highlighting (e.g.
"csharp","python"). Used together with SyntaxHighlighter when setting CodeLines.
- ShowCopyButton
Gets or sets whether the copy button is shown in the top-right corner. Defaults to true.
- SyntaxHighlighter
Gets or sets an optional syntax highlighter. When set together with Language, setting CodeLines re-highlights the content through the highlighter.
- Text
Gets or sets the code block content. The setter accepts fenced code block format (
) and extracts the language automatically. Plain text (without fences) is also accepted and treated as language-less code.lang\ncode\n
- ThemeBackground
Gets or sets an override background color from the syntax highlighting theme. When set, the code block viewport uses this instead of Code.
Methods
- ExtractText()
Extracts the plain text of this code block.
- OnClearingViewport()
Called when the Viewport is to be cleared.
- OnDrawingContent(DrawContext?)
Called when the View's content is to be drawn. The default implementation does nothing.
- OnMouseEvent(Mouse)
Called when a mouse event occurs within the view's Viewport.