Markdown.Avalonia icon indicating copy to clipboard operation
Markdown.Avalonia copied to clipboard

Markdown code blocks render empty when language is specified

Open LSXAxeller opened this issue 4 months ago • 5 comments

When rendering Markdown code blocks using MarkdownScrollViewer, blocks with a language specifier at the top (e.g., ````csharp`) render as empty rectangles. Code blocks without a language specifier (e.g., `````) render correctly.

Steps to Reproduce:

  1. Create a MarkdownScrollViewer control in an Avalonia application.
  2. Bind the Markdown property to a string containing a Markdown code block with a language specifier, for example:
using System;
                
namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
  1. Run the application.

Expected Behaviour:

The code block should be rendered with syntax highlighting according to the specified language (in this case, C#).

Actual Behaviour:

The code block is rendered as an empty rectangle with a border and padding, but no code content is displayed.

Screenshots:

  • Working code block (no language specifier): {F4721132-2688-4091-B1F5-C63A03B67794}

  • Empty code block (with language specifier): image

Relevant Code:

XAML:

<md:MarkdownScrollViewer Markdown="{Binding Message}" SelectionEnabled="True">
    
    <md:MarkdownScrollViewer.Plugins>
        <md:MdAvPlugins>
            <mdt:ChatAISetup />
        </md:MdAvPlugins>
    </md:MarkdownScrollViewer.Plugins>
    
    <md:MarkdownScrollViewer.Styles>
        <Style Selector="Border.CodeBlock">
            <Style.Setters>
                <Setter Property="BorderBrush"     Value="LightGray"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius"    Value="12"/>
                <Setter Property="Margin"          Value="10"/>
                <Setter Property="Padding"         Value="8"/>
            </Style.Setters>
        </Style>
    </md:MarkdownScrollViewer.Styles>
    
</md:MarkdownScrollViewer>

Additional Information:

  • Avalonia version: 11.1.3
  • Markdown.Avalonia Version: 11.0.3-a1

Any suggestions on this ?

LSXAxeller avatar Oct 01 '24 12:10 LSXAxeller