A control that renders Markdown text into Avalonia visual elements.
[PseudoClasses(new string[] { ":high-contrast", ":copy-on-hover" })]
public class MarkdownViewer : ContentControl, IAvaloniaObjectDebug, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, INamed, IAvaloniaListItemValidator<ILogical>, IAvaloniaListItemValidator<Visual>, IInputElement, IDataTemplateHost, IVisualBrushInitialize, ISetterValue, IContentControl, IContentPresenterHost, ICustomKeyboardNavigation
kind:method, kind:property, kind:ctor. Press Esc to clear.AreHeadingsFoldablePropertyDefines the AreHeadingsFoldable property.AreTaskListsInteractivePropertyDefines the AreTaskListsInteractive property.AutoScrollToEndPropertyDefines the AutoScrollToEnd property.BaseUriPropertyDefines the BaseUri property.CodeBlockMaxHeightPropertyDefines the CodeBlockMaxHeight property.CopyingToClipboardEventIdentifies the CopyingToClipboard routed event.CurrentFindMatchIndexPropertyDefines the CurrentFindMatchIndex property.DefaultStreamingUpdateIntervalThe update interval of a session started without one: at most one update every 32 milliseconds.DetectTextDirectionPropertyDefines the DetectTextDirection property.FindMatchCountPropertyDefines the FindMatchCount property.HasSelectionPropertyDefines the HasSelection property.HighContrastModePropertyDefines the HighContrastMode property.ImageResizeModePropertyDefines the ImageResizeMode property.InHighContrastPropertyDefines the InHighContrast attached property, which is true on the viewer and inherited by every element of its document while the viewer is in high contrast (IsHighContrast). A control theme matches it on its own control, ^[(mv|MarkdownViewer.InHighContrast)=True], where a :high-contrast style would cost memory on every control of its type.IsHighContrastPropertyDefines the IsHighContrast property.IsHtmlCopyEnabledPropertyDefines the IsHtmlCopyEnabled property.IsImageSaveEnabledPropertyDefines the IsImageSaveEnabled property.IsImageZoomEnabledPropertyDefines the IsImageZoomEnabled property.IsLazyRenderingEnabledPropertyDefines the IsLazyRenderingEnabled property.IsSmoothScrollingEnabledPropertyDefines the IsSmoothScrollingEnabled property.IsStreamingPropertyDefines the IsStreaming property.LinkClickedEventIdentifies the LinkClicked routed event.MarkdownPropertyDefines the Markdown property.PipelinePropertyDefines the Pipeline property.SavingImageEventIdentifies the SavingImage routed event.SelectionChangedEventIdentifies the SelectionChanged routed event.ShowCodeBlockCopyButtonOnHoverPropertyDefines the ShowCodeBlockCopyButtonOnHover property.ShowCodeBlockCopyButtonPropertyDefines the ShowCodeBlockCopyButton property.ShowCodeBlockLanguagePropertyDefines the ShowCodeBlockLanguage property.ShowCodeBlockLineNumbersPropertyDefines the ShowCodeBlockLineNumbers property.SourcePropertyDefines the Source property.TableOfContentsMaxDepthPropertyDefines the TableOfContentsMaxDepth property.TableOfContentsPropertyDefines the TableOfContents property.TaskToggledEventIdentifies the TaskToggled routed event.WrapCodeBlockLinesPropertyDefines the WrapCodeBlockLines property.AreHeadingsFoldableGets or sets whether each heading starts with a fold button that hides or shows its section: the blocks that follow it, up to the next heading of the same or a higher level. Sections start expanded; the button also answers Enter and Space, and is a Tab stop. Navigating to a heading (ScrollToAnchor(String)) or a find match in a collapsed section expands it, and hidden sections are left out of selection and copying. Defaults to false. Can be set from a style, e.g. for every viewer of an application.AreTaskListsInteractiveGets or sets whether task-list items (- [ ] / - [x]) render a checkbox the user can toggle, raising TaskToggled. When false (the default) they render a static check glyph. The viewer never rewrites Markdown itself: the host writes the change back to its source from the event.AutoScrollToEndGets or sets whether, during a streaming session, the viewer keeps the end of the document in view as text arrives. Scrolling away from the bottom pauses following; scrolling back to the bottom resumes it, and each new session starts following. No effect outside a session. Defaults to false.BaseUriGets or sets the base URI for resolving relative URLs in images and links.CodeBlockMaxHeightGets or sets the maximum height of a code block, its toolbar excluded. A taller block keeps this height and scrolls vertically inside itself; once it reaches either end, the mouse wheel scrolls the document again. Defaults to (no limit). Can be set from a style, e.g. for every viewer of an application.CurrentFindMatchIndexGets the zero-based index of the current match of the active search, the one FindNext() and FindPrevious() moved to, or -1 when no match is current.DetectTextDirectionGets or sets whether each block takes the direction of its own text, as HTML's dir="auto" does: a paragraph, heading, list, quote or table whose first letter is Hebrew or Arabic is laid out right to left (lists and quotes mirrored, the first column of a table on the right), one whose first letter is Latin left to right. A block without a letter keeps the viewer's Avalonia.Visual.FlowDirection, code blocks are always left to right, and an HTML dir attribute wins over the text. When false, every block takes the viewer's Avalonia.Visual.FlowDirection. Defaults to true. Can be set from a style, e.g. for every viewer of an application.ExtensionsExtensions that customise the renderer before each render pass. Add entries before setting Markdown or assigning a new Pipeline; each extension's Register(AvaloniaRenderer) is called once per render.FindMatchCountGets the number of matches of the active search (see Find(String, MarkdownFindOptions)) in the rendered document, including those in collapsed content; 0 when there is no active search.HasSelectionGets whether some text is selected. SelectionChanged is raised whenever the selection changes, this property only when it starts or stops being empty.HighContrastModeGets or sets when the viewer uses its high-contrast palette. Defaults to System, which follows the operating system's setting.ImageResizeModeGets or sets how images without an explicit "=WxH" size hint are scaled relative to their container. Defaults to ScaleDownToFit.IsHighContrastGets whether the viewer currently uses its high-contrast palette, i.e. whether it has the :high-contrast pseudo-class and the theme's MarkdownHighContrastPalette in its resources.IsHtmlCopyEnabledGets or sets whether copying the selection also writes it as HTML, next to the plain text, so that pasting into a word processor, a chat or a web editor keeps its formatting. Only on Windows, macOS and Linux; other platforms get the plain text alone. Defaults to true.IsImageSaveEnabledGets or sets whether images and Mermaid diagrams can be saved to a file: from the lightbox's save button or Ctrl+S (Cmd+S on macOS), and from the item "Save image as…" of the context menu opened on one. A diagram, or an image of the Svg package, is saved as SVG or PNG; any other image as PNG. Saving raises SavingImage, then opens the platform's save picker (in a browser without one, the file is downloaded). Defaults to true. Can be set from a style, e.g. for every viewer of an application.IsImageZoomEnabledGets or sets whether clicking an image opens it in a lightbox over the viewer: the image as large as fits, never enlarged past its natural size, on a dimmed backdrop. Clicking anywhere, the close button or Escape closes it, and focus returns to where it was. A zoomable image shows the zoom-in cursor and also opens with Enter or Space while it has focus; an image inside a link opens the link instead. Defaults to false. Can be set from a style, e.g. for every viewer of an application.IsLazyRenderingEnabledGets or sets whether costly content waits until it is about to scroll into view: images start loading, formulas and Mermaid diagrams render, and code blocks, shown as plain text until then, get their syntax colours once they come within one viewport height of the visible area. The content is laid out before it is shown, and an image already loaded by an earlier render shows at once. Turn it off when the viewer is never scrolled into view, e.g. when it is rendered to a bitmap for printing or export, so that everything renders without being seen first. Defaults to true. Can be set from a style, e.g. for every viewer of an application.IsSmoothScrollingEnabledGets or sets whether jumping to an anchor, with a #anchor link, a footnote or ScrollToAnchor(String), scrolls there in a short animation rather than at once. Opening a document at a fragment (Source ending with #anchor) still shows it at once, as a browser does. The animation stops as soon as the user scrolls. Defaults to false. Can be set from a style, e.g. for every viewer of an application, or bound to the application's own reduced-motion setting.IsStreamingGets whether a streaming session is active, from BeginStreaming(Nullable<TimeSpan>, Boolean) until the session completes or the viewer renders something else.MarkdownGets or sets the Markdown text to render.PipelineGets or sets the Markdig pipeline. If null, a default pipeline with supported extensions is used.SelectedTextGets the selected plain text, with lines separated by '\n'; the same as GetSelectedText(). It is built on the first read after the selection changes, and later reads return the same string. It is not a bindable property; bind to HasSelection or handle SelectionChanged instead.ShowCodeBlockCopyButtonGets or sets whether code blocks show a button in a toolbar above the code that copies the code to the clipboard. Display formulas of the MarkView.Avalonia.Math package get one in their top right corner, which copies their TeX source. Defaults to true. Can be set from a style, e.g. for every viewer of an application.ShowCodeBlockCopyButtonOnHoverGets or sets whether the copy buttons of ShowCodeBlockCopyButton only show while the pointer is over their block, while they have keyboard focus, and while they confirm a copy. Hidden, a button keeps its place, its Tab stop and its accessible name. Defaults to false. Switching it restyles the buttons without re-rendering the document; the viewer has the :copy-on-hover pseudo-class while it is on. Can be set from a style, e.g. for every viewer of an application.ShowCodeBlockLanguageGets or sets whether code blocks show their language (the info string of a fenced code block, e.g. csharp) in a toolbar above the code. Defaults to false, as on GitHub. Can be set from a style, e.g. for every viewer of an application.ShowCodeBlockLineNumbersGets or sets whether code blocks show the number of each line in a gutter next to the code. The numbers are not part of the code: text selection and the copy button never include them. Defaults to false. Can be set from a style, e.g. for every viewer of an application.SourceGets or sets a URI that points to a Markdown document to load and render. Supports avares:// embedded resources, file://, and http/https schemes. A #fragment scrolls to the matching anchor once the document has rendered; for avares:// the fragment starts at the first #, so asset paths containing # are not supported. When both Source and Markdown are set, Source takes precedence.TableOfContentsGets the nested heading tree for the current document, filtered by TableOfContentsMaxDepth. Recomputed after every render. Pass an entry's Slug to ScrollToAnchor(String) to navigate to it.TableOfContentsMaxDepthGets or sets the maximum heading level included in TableOfContents. Headings deeper than this level, and their descendants, are excluded. Defaults to 6 (no limit).WrapCodeBlockLinesGets or sets whether code blocks wrap lines longer than the block's width. When false (the default) code lines never wrap and run past the block's right edge, so they can only be read in full when the viewer scrolls horizontally. Can be set from a style, e.g. for every viewer of an application.BeginStreaming(Nullable<TimeSpan>, Boolean)Starts a streaming session that appends to the current Markdown; set it to an empty string (or null) first to stream a new document. Text appended to the session is rendered at most once per updateInterval, re-rendering only the blocks the new text can have changed: the scroll position, the selection in unchanged blocks, the active search and an open image lightbox are kept. After each update Markdown holds the text so far; a null Markdown is treated as empty, so it is "" once a session that appended nothing completes. Must be called on the UI thread.ClearFind()Clears the active search and its highlights.ClearSelection()Clears the current selection.CopyAsMarkdownAsync()Copies the selection as Markdown (see GetSelectedMarkdown()) to the clipboard as plain text, with the platform's line endings, after raising CopyingToClipboard. Does nothing when nothing is selected.CopyToClipboardAsync()Copies the selected text to the clipboard, with the platform's line endings, after raising CopyingToClipboard. While IsHtmlCopyEnabled is true, the selection is also written as HTML. Does nothing when nothing is selected.Find(String, MarkdownFindOptions)Finds every occurrence of text in the rendered document and highlights it, replacing the previous search. Returns the number of matches, also given by FindMatchCount. No match is current yet: FindNext() goes to the first one and FindPrevious() to the last one. An empty text clears the search, as ClearFind() does. A match never spans two blocks (paragraphs, headings, code blocks, table cells...). Text inside collapsed alerts and details blocks is searched too; moving to a match there expands its block. The source of formulas and diagrams, and list markers, are not searched. The search stays active until it is cleared: when the document is rendered again (e.g. Markdown or Source changes), it runs again on the new document, which keeps the current match index when the new document has that many matches (the last match otherwise), without scrolling to it.FindNext()Makes the next match of the active search current, wrapping around from the last match to the first, and scrolls it into view, expanding any collapsed alert, details block or heading section it is in. Returns false when there is no match.FindPrevious()Makes the previous match of the active search current, wrapping around from the first match to the last, and scrolls it into view, expanding any collapsed alert, details block or heading section it is in. Returns false when there is no match.GetInHighContrast(StyledElement)Gets whether element is in a viewer that is in high contrast.GetSelectedMarkdown()Returns the selection as Markdown, with lines separated by '\n'. A top-level block selected whole is copied as its source text, so selecting the whole document gives back the Markdown it was rendered from. A block only partly selected, at either end of the selection, is rebuilt for its selected part: its text with its emphasis, code, links and images, inside its heading, list item, quote or table row, written as normalised Markdown (**bold**, *italic*, - bullets). A selection within a single block copies only its text, with its inline syntax.GetSelectedText()Returns the currently selected plain text, with lines separated by '\n'.ScrollToAnchor(String)Scrolls to the anchor (e.g. a heading's slug) named anchorId, if the document has one. While the viewer itself has the focus, Tab then goes on from that anchor, as in a browser. The scroll is animated while IsSmoothScrollingEnabled is true.SelectAll()Selects all text in the rendered document.CopyingToClipboardRaised before the viewer writes to the clipboard: when the selection is copied (with the copy hotkey, CopyToClipboardAsync() or CopyAsMarkdownAsync()) and when a code block's copy button is clicked. A handler can change Text or set Cancel. Not raised when there is nothing to copy. Bubbles up the visual tree.LinkClickedRaised when a hyperlink in the rendered markdown is clicked. Bubbles up the visual tree; subscribe globally with MarkdownViewer.LinkClickedEvent.AddClassHandler<MarkdownViewer>(...).SavingImageRaised when the user asks to save an image or a diagram, before the save picker opens. A handler can change SuggestedFileName, or set Cancel and save the picture itself with WriteAsync(MarkdownImageFormat, Stream). Bubbles up the visual tree.SelectionChangedRaised when the selected range changes: at each step of a drag that moves its end, on SelectAll() and ClearSelection(), on a click that clears it, when a new document replaces the one it was in, and when a streaming update shortens or clears it. Not raised when the range stays the same, except once more when a drag that changed it ends: the events raised during the drag have IsSelecting set, the last one does not. Bubbles up the visual tree.TaskToggledRaised when the user toggles a task-list checkbox while AreTaskListsInteractive is true. The checkbox already shows the new state; the viewer does not change Markdown. SourceStart and SourceLength locate the item's [ ] / [x] marker in the rendered markdown (the Markdown string as set, or the text loaded from Source). Bubbles up the visual tree.UseAbbreviations(MarkdownViewer)Enables abbreviation tooltip rendering on the viewer.UseAlertBlocks(MarkdownViewer)Enables the alert extras on the viewer: foldable alerts and custom titles. GitHub-style alerts themselves are already part of the default pipeline.UseCitations(MarkdownViewer)Enables citation rendering (""quoted text"") on the viewer.UseFigures(MarkdownViewer)Enables figure block rendering on the viewer.UseFootnotes(MarkdownViewer)Enables footnote rendering on the viewer. Footnotes are already part of the default pipeline, so this only matters to restore the default after another pipeline was set.UseHardlineBreaks(MarkdownViewer)Enables hardline-break rendering on the viewer: every soft line break renders as an explicit line break instead of collapsing to a space.UseMediaLinks(MarkdownViewer)Enables YouTube thumbnail embed rendering on the viewer.UseThinkingBlocks(MarkdownViewer, ThinkingBlockOptions?)Shows a language model's reasoning (<think>…</think>) in a block that folds away, as UseThinkingBlocks(MarkdownPipelineBuilder, ThinkingBlockOptions?) describes.UseFenceRenderer(MarkdownViewer, String, FenceRendererFactory)Renders the viewer's fenced code blocks of language as the control factory returns, replacing a fence renderer the viewer's Extensions already had for that language, and re-renders the document.UseTextMateHighlighting(MarkdownViewer, ThemeName, ThemeName)Adds TextMateExtension to the viewer's Extensions list. The extension automatically selects the appropriate highlighter theme based on the current UseSvg(MarkdownViewer)Adds SvgExtension to the viewer's Extensions list.UseMermaid(MarkdownViewer, MermaidStyle)Adds MermaidExtension to the viewer's Extensions list.UseMath(MarkdownViewer, Boolean)Enables LaTeX math parsing and rendering on the viewer: $...$/$$...$$, and the bracket delimiters \(...\)/\[...\] (see UseMathBracketDelimiters(MarkdownPipelineBuilder)). With bracketDelimiters false, only $...$/$$...$$ are math, and \(/\[ keep their CommonMark meaning of an escaped parenthesis or bracket. Unlike UseMermaid()/UseSvg(), this also rebuilds the pipeline: the syntax needs Markdig's UseMathematics() to even be parsed, not just a renderer.ICustomKeyboardNavigation.GetNext(IInputElement, NavigationDirection)Tab order through the document: the viewer itself, then its links and focusable controls in reading order, then whatever follows the viewer. Shift+Tab walks the same stops backwards, and entering the document backwards lands on its last stop. After a jump to an anchor, Tab from the viewer goes on from that anchor instead of from the top of the document.