Markdown.Avalonia

repository·master·Indexed 19 days ago

https://github.com/whistyun/markdown.avalonia

A port of MdXaml designed to render Markdown content within Avalonia UI applications. It provides the MarkdownScrollViewer control to display Markdown via XAML, data binding, or AvaloniaResource. The library supports standard Markdown syntax, custom text coloring, paragraph alignment, and images from remote URLs, local paths, or resources. Available as a standard package or a 'Tight' version without the AvaloniaEdit dependency.

Tokens
2.1K
Snippets
7
Records
13
Agent score
62%

What's inside Markdown.Avalonia

  1. What is MdXaml?

    master
    MdXaml is a modified version of Markdown.Xaml. It is a port of the MarkdownSharp processor designed specifically for Avalonia/WPF environments. Unlike standard Markdown processors that render to HTML strings, MdXaml renders Markdown directly into a FlowDocument (or equivalent document structure), making it suitable for embedding directly into Avalonia windows or UserControls.
  2. Install Markdown.Avalonia via NuGet

    master

    You can install Markdown.Avalonia using NuGet. There are two packages available depending on your requirements:

    • Markdown.Avalonia: The standard package.
    • Markdown.Avalonia.Tight: A specialized version.

    Check the NuGet gallery for the latest versions.

    dotnet add package Markdown.Avalonia
  3. Render Markdown using MarkdownScrollViewer

    master

    You can render Markdown in your Avalonia application using the MarkdownScrollViewer control via three different methods:

    1. Load .md from AvaloniaResource

    Use the Source property to point to a Markdown file embedded in your project using the avares:// URI scheme.

    2. Write markdown in XAML

    You can write raw Markdown content directly inside the MarkdownScrollViewer tags in your XAML file.

    3. Use Data Binding

    Bind the Markdown property to a string property in your ViewModel.

    <!-- 1. Load from AvaloniaResource -->
    <md:MarkdownScrollViewer
       Source="avares://YourAssemblyName/Assets/Test.md"/>
    
    <!-- 2. Write markdown in xaml -->
    <md:MarkdownScrollViewer>
      # Heading1
      Hello Markdown.Avalonia!
    </md:MarkdownScrollViewer>
    
    <!-- 3. With binding -->
    <md:MarkdownScrollViewer
       Markdown="{Binding MdText}"/>
  4. Use MarkdownScrollViewer for rendering

    master

    To display rendered Markdown in an Avalonia application, use the MarkdownScrollViewer control. This control handles the display of the Markdown content, typically used in a way that allows for real-time updates or binding to a Markdown source string.

    Review the demo source code to see the implementation details of how MarkdownScrollViewer is integrated and how to apply custom styling to the rendered output.

  5. Display remote and local images in Markdown

    master

    Markdown.Avalonia supports rendering images using standard Markdown syntax. You can display images from remote URLs, local file paths, or application resources.

    Remote Images

    Use standard Markdown image syntax with a URL: ![alt text](URL)

    You can also include titles (tooltips) for images: ![alt text](URL "title")

    Local and Resource Images

    To display images stored within your project or on the local file system, provide the relative or absolute path:

    • Local paths: ![alt text](path/to/image.png)
    • Resource paths: ![alt text](Assets/image.png)
    #### Remote images ####
    ![image1](http://placehold.it/300x25)  
    ![imageleft](http://placehold.it/150x25/0000FF "blue")![imageright](http://placehold.it/150x25/00FFFF "cyan")
    
    #### Local and resource images ####
    ![localimage](Assets2/ResourceImage.png)
    ![ResourceImage](Assets/ResourceImage.png)
  6. MdXaml Markdown Syntax Extensions

    master

    MdXaml supports standard Markdown syntax along with several enhanced features for styling and alignment:

    Text Decoration & Color

    • Standard: *italic*, **bold**, ***bold-italic***, ~~strikethrough~~, __underline__.
    • Color: Use %{color:name}text% to apply color (e.g., %{color:red}color%).

    Text Alignment

    You can apply paragraph alignment by prefixing the paragraph with a specific pattern p[<=>].:

    • p<. text (Left alignment)
    • p>. text (Right alignment)
    • p=. text (Center alignment)

    Lists

    • Unordered (ul): Use * or -.
    • Ordered (ol): Use 1., a., or i. (roman numerals).

    Separators

    • --- (Single line)
    • === (Two lines)
    • *** (Bold line)
    • ___ (Bold with single line)
    ### Text Decoration
    *italic*, **bold**, ***bold-italic***, ~~strikethrough~~, __underline__ and %{color:red}color%
    
    ### Text Alignment
    p<. left alignment text
    p>. right alignment text
    p=. center alignment
    
    ### Separators
    ---
    ===
    ***
    ___
  7. Check AvaloniaUI compatibility for Markdown.Avalonia

    master

    Ensure your version of AvaloniaUI is compatible with the version of Markdown.Avalonia you are using. Use the following compatibility mapping:

    AvaloniaUIMarkdown.Avalonia
    12.0.012.0.0-a1
    11.1.0-beta111.0.3-a1
    11.0.011.0.0~11.0.3-a1
    11.0.0-rc1.111.0.0-d1~d2
    11.0.0-preview811.0.0-c1
    11.0.0-preview711.0.0-b2
    11.0.0-preview611.0.0-a10, b1
    11.0.0-preview511.0.0-a9
    11.0.0-preview411.0.0-a6, a8
    11.0.0-preview311.0.0-a5
    11.0.0-preview1~211.0.0-a1~a4
    0.10.1~0.10.60.10.4
    0.10.00.10.1~0.10.3
    0.9.110.9.0-a1~a7