1
0

Added Markdown renderer

This commit is contained in:
Benjamin Höglinger-Stelzer 2018-10-24 00:32:33 +02:00
parent 7036df995a
commit 897188de47
2 changed files with 53 additions and 5 deletions

View File

@ -60,10 +60,7 @@
</GroupBox> </GroupBox>
<GroupBox Grid.Row="1" Margin="0,15,0,0" Header="Device Driver Compatibility Summary"> <GroupBox Grid.Row="1" Margin="0,15,0,0" Header="Device Driver Compatibility Summary">
<TextBlock Text="{Binding Path=SummaryText}" <FlowDocumentScrollViewer Height="200" VerticalScrollBarVisibility="Auto" Document="{Binding SummaryDocument}"/>
TextAlignment="Justify"
TextWrapping="WrapWithOverflow"
FontSize="14px" />
</GroupBox> </GroupBox>
</Grid> </Grid>
</controls:MetroWindow> </controls:MetroWindow>

View File

@ -1,5 +1,12 @@
using DerpingDrivers.Util; using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Documents;
using System.Xaml;
using DerpingDrivers.Util;
using MahApps.Metro.Controls; using MahApps.Metro.Controls;
using Markdig;
using Markdig.Wpf;
namespace DerpingDrivers namespace DerpingDrivers
{ {
@ -49,5 +56,49 @@ namespace DerpingDrivers
public string SummaryText => public string SummaryText =>
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
public FlowDocument SummaryDocument
{
get
{
var markdown = "*None available*";
// Convert Markdown to XAML
var xaml = Markdig.Wpf.Markdown.ToXaml(markdown, BuildPipeline());
// Render XAML for FlowDocument Control
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xaml)))
{
var reader = new XamlXmlReader(stream, new MyXamlSchemaContext());
if (System.Windows.Markup.XamlReader.Load(reader) is FlowDocument document)
{
return document;
}
}
return null;
}
}
private static MarkdownPipeline BuildPipeline()
{
return new MarkdownPipelineBuilder()
.UseSupportedExtensions()
.Build();
}
}
internal class MyXamlSchemaContext : XamlSchemaContext
{
public override bool TryGetCompatibleXamlNamespace(string xamlNamespace, out string compatibleNamespace)
{
if (xamlNamespace.Equals("clr-namespace:Markdig.Wpf"))
{
compatibleNamespace = $"clr-namespace:Markdig.Wpf;assembly={Assembly.GetAssembly(typeof(Markdig.Wpf.Styles)).FullName}";
return true;
}
return base.TryGetCompatibleXamlNamespace(xamlNamespace, out compatibleNamespace);
}
} }
} }