MarkdownViewer

MarkView.Avalonia.MarkdownViewer is the control that renders a document. This page lists its members by kind; the API reference has their signatures.

Properties

Styled properties can be set in a style for every viewer of an application. The ones marked "re-renders" render the document again when they change.

Property Type Default Description
Markdown string? null The text to render. Re-renders. See Displaying documents.
Source Uri? null A document to load and render (avares://, file://, http, https); wins over Markdown. Re-renders. See Loading a file or a URL.
BaseUri Uri? null Base address of relative links and images; the folder of Source when not set. Re-renders.
Pipeline MarkdownPipeline? null The Markdig pipeline; null falls back to MarkdownViewerDefaults.Pipeline, then to UseGitHubExtensions(). Re-renders. See Markdown and the pipeline.
Extensions IList<IMarkViewExtension> empty The viewer's extensions, registered after MarkdownViewerDefaults.Extensions. Not a styled property. See Choosing packages.
ImageResizeMode ImageResizeMode ScaleDownToFit How images without a size hint scale to the viewer's width. See Sizing.
IsImageZoomEnabled bool false Clicking an image or a diagram opens it in a lightbox. See Lightbox.
IsImageSaveEnabled bool true Images and diagrams can be saved from the lightbox and the context menu. See Saving images and diagrams.
IsLazyRenderingEnabled bool true Images, formulas, diagrams and code colours are built when about to scroll into view. Re-renders. See Lazy rendering.
IsSmoothScrollingEnabled bool false Animates jumps to anchors. See Smooth scrolling.
ShowCodeBlockLanguage bool false Shows each code block's language in its toolbar. Re-renders. See Code blocks.
ShowCodeBlockCopyButton bool true A copy button for each code block, and for each display formula. Re-renders.
ShowCodeBlockCopyButtonOnHover bool false Shows the copy buttons only while the pointer is over their block. See Showing copy buttons on hover.
ShowCodeBlockLineNumbers bool false Numbers the lines of code blocks. Re-renders. See Line numbers, wrapping and height.
WrapCodeBlockLines bool false Wraps long code lines. Re-renders.
CodeBlockMaxHeight double PositiveInfinity Maximum height of a code block, past which it scrolls. Re-renders.
AreTaskListsInteractive bool false Task-list items are checkboxes that raise TaskToggled. Re-renders. See Task lists.
AreHeadingsFoldable bool false Each heading has a button that folds its section. Re-renders. See Folding.
TableOfContents IReadOnlyList<TocEntry> empty Read-only. The headings as a tree, rebuilt after every render. See Table of contents.
TableOfContentsMaxDepth int 6 Deepest heading level in TableOfContents.
DetectTextDirection bool true Each block takes the direction of its text, so Hebrew and Arabic read right to left. Re-renders. See Right-to-left text.
HighContrastMode HighContrastMode System When to use the high-contrast palette: following the OS (System), Enabled or Disabled. See High contrast.
IsHighContrast bool false Read-only. Whether the high-contrast palette is in use; mirrors the :high-contrast pseudo-class.
IsHtmlCopyEnabled bool true Copying also writes the selection as HTML, on the desktop. See HTML on the clipboard.
HasSelection bool false Read-only. Whether text is selected.
SelectedText string Read-only, not bindable. The selected text, lines separated by \n.
FindMatchCount int 0 Read-only. The number of matches of the current search. See Find in document.
CurrentFindMatchIndex int -1 Read-only. The index of the current match, or -1.
IsStreaming bool false Read-only. Whether a streaming session is open. See Streaming.
AutoScrollToEnd bool false During a streaming session, keeps the end of the document in view.

MarkdownViewer.InHighContrast is an inherited attached property, true on every control of a document in high contrast, for control themes (see Themes and presets).

Events

LinkClicked, TaskToggled, SelectionChanged, CopyingToClipboard and SavingImage are routed events that bubble, with a matching …Event field for class handlers.

Event Raised when
LinkClicked A link is clicked, before the viewer opens it; set Handled to open it yourself. See Links.
TaskToggled The reader ticks a task-list checkbox. See Task lists.
SelectionChanged The selection changes. See Selection changes.
CopyingToClipboard The viewer is about to write to the clipboard; the handler can change or cancel the copy. See Changing what is copied.
SavingImage An image or a diagram is about to be saved. See Saving images and diagrams.

Methods

Method Description
ScrollToAnchor(string) Scrolls to a heading or a footnote. See Anchors.
SelectAll(), ClearSelection() Selects the whole document, or nothing.
GetSelectedText() The selection as text.
GetSelectedMarkdown() The selection as Markdown. See Copying as Markdown.
CopyToClipboardAsync(), CopyAsMarkdownAsync() Copies the selection, as text (and HTML) or as Markdown.
Find(string, MarkdownFindOptions) Highlights every match and returns their number. See Find in document.
FindNext(), FindPrevious(), ClearFind() Moves to the next or previous match, or clears the search.
BeginStreaming(TimeSpan?, bool) Starts a streaming session that appends to Markdown. See Streaming.

Extension methods of MarkdownViewer, in the MarkView.Avalonia namespace, set the pipeline or add an extension; each returns the viewer:

Method Does
UseAbbreviations(), UseAlertBlocks(), UseCitations(), UseFigures(), UseFootnotes(), UseHardlineBreaks(), UseMediaLinks(), UseThinkingBlocks(options) Sets Pipeline to UseGitHubExtensions() plus that syntax. See Adding syntax.
UseFenceRenderer(language, factory) Renders the fenced blocks of a language as your own control. See Custom fenced blocks.
UseTextMateHighlighting(dark, light) SyntaxHighlighting package. See Syntax highlighting.
UseSvg() Svg package. See SVG images.
UseMermaid(style) Mermaid package. See Mermaid diagrams.
UseMath(bracketDelimiters) Math package; also sets Pipeline. See Math.

MarkdownViewerDefaults

Static settings for every viewer of the application. See Settings for every viewer.

Member Description
Pipeline The pipeline of viewers without their own.
Extensions Extensions registered on every viewer, before its own. The packages add AddTextMateHighlighting(), AddSvg(), AddMermaid(), AddMath(), and the core AddFenceRenderer().
ImageCacheSize Size of the shared image cache, in bytes (100 MB by default; 0 turns it off). See Image cache.
ClearImageCache() Empties the image cache.