using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Markdig.Syntax;
namespace MarkdownEditor.Views.Renderers;
///
/// Renders markdown thematic breaks (horizontal rules).
///
public class ThematicBreakRenderer : IMarkdownBlockRenderer
{
private readonly bool _isDarkMode;
///
/// Initializes a new instance of the class.
///
/// Whether the current theme is dark mode.
public ThematicBreakRenderer(bool isDarkMode = true)
{
_isDarkMode = isDarkMode;
}
///
public bool CanRender(Block block) => block is ThematicBreakBlock;
///
public Control? Render(Block block)
{
if (block is not ThematicBreakBlock)
{
return null;
}
return new Border
{
BorderBrush = new SolidColorBrush(Color.Parse(_isDarkMode ? "#555555" : "#CCCCCC")),
BorderThickness = new Thickness(0, 1, 0, 0),
Margin = new Thickness(0, 10, 0, 10),
Height = 1
};
}
}