Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
WpfXamlRenderer.cs
1using SkiaSharp;
2using System;
3using System.Collections.Generic;
4using System.Text;
5using System.Threading.Tasks;
6using System.Xml;
14using Waher.Events;
15using Waher.Script;
18
20{
25 {
29 public readonly XmlWriter XmlOutput;
30
34 public readonly XamlSettings XamlSettings;
35
40
45 : this(new XamlSettings())
46 {
47 }
48
53 public WpfXamlRenderer(XmlWriterSettings XmlSettings)
54 : this(XmlSettings, new XamlSettings())
55 {
56 }
57
63 : this(XML.WriterSettings(false, true), XamlSettings)
64 {
65 }
66
72 public WpfXamlRenderer(XmlWriterSettings XmlSettings, XamlSettings XamlSettings)
73 : base()
74 {
75 this.XamlSettings = XamlSettings;
76 this.XmlOutput = XmlWriter.Create(this.Output, XmlSettings);
77 }
78
85 public WpfXamlRenderer(StringBuilder Output, XmlWriterSettings XmlSettings, XamlSettings XamlSettings)
86 : base(Output)
87 {
88 this.XamlSettings = XamlSettings;
89 this.XmlOutput = XmlWriter.Create(this.Output, XmlSettings);
90 }
91
93 public override void Dispose()
94 {
95 base.Dispose();
96
97 this.XmlOutput.Dispose();
98 }
99
105 public override Task RenderDocument(MarkdownDocument Document, bool Inclusion)
106 {
107 this.Alignment = TextAlignment.Left;
108
109 return base.RenderDocument(Document, Inclusion);
110 }
111
115 public override Task RenderDocumentHeader()
116 {
117 this.XmlOutput.WriteStartElement("StackPanel", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
118 this.XmlOutput.WriteAttributeString("xmlns", "x", null, "http://schemas.microsoft.com/winfx/2006/xaml");
119
120 return Task.CompletedTask;
121 }
122
126 public override async Task RenderFootnotes()
127 {
129 string FootnoteMargin = "0," + this.XamlSettings.ParagraphMarginTop.ToString() + "," +
130 this.XamlSettings.FootnoteSeparator.ToString() + "," +
131 this.XamlSettings.ParagraphMarginBottom.ToString();
132 string Scale = CommonTypes.Encode(this.XamlSettings.SuperscriptScale);
133 string Offset = this.XamlSettings.SuperscriptOffset.ToString();
134 int Nr;
135 int Row = 0;
136
137 this.XmlOutput.WriteElementString("Separator", string.Empty);
138
139 this.XmlOutput.WriteStartElement("Grid");
140 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
141
142 this.XmlOutput.WriteStartElement("ColumnDefinition");
143 this.XmlOutput.WriteAttributeString("Width", "Auto");
144 this.XmlOutput.WriteEndElement();
145
146 this.XmlOutput.WriteStartElement("ColumnDefinition");
147 this.XmlOutput.WriteAttributeString("Width", "*");
148 this.XmlOutput.WriteEndElement();
149
150 this.XmlOutput.WriteEndElement();
151 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
152
153 foreach (string Key in this.Document.FootnoteOrder)
154 {
155 if ((this.Document?.TryGetFootnoteNumber(Key, out Nr) ?? false) &&
156 (this.Document?.TryGetFootnote(Key, out Footnote) ?? false) &&
158 {
159 this.XmlOutput.WriteStartElement("RowDefinition");
160 this.XmlOutput.WriteAttributeString("Height", "Auto");
161 this.XmlOutput.WriteEndElement();
162 }
163 }
164
165 this.XmlOutput.WriteEndElement();
166
167 foreach (string Key in this.Document.FootnoteOrder)
168 {
169 if ((this.Document?.TryGetFootnoteNumber(Key, out Nr) ?? false) &&
170 (this.Document?.TryGetFootnote(Key, out Footnote) ?? false) &&
172 {
173 this.XmlOutput.WriteStartElement("TextBlock");
174 this.XmlOutput.WriteAttributeString("Text", Nr.ToString());
175 this.XmlOutput.WriteAttributeString("Margin", FootnoteMargin);
176 this.XmlOutput.WriteAttributeString("Grid.Column", "0");
177 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
178
179 this.XmlOutput.WriteStartElement("TextBlock.LayoutTransform");
180 this.XmlOutput.WriteStartElement("TransformGroup");
181
182 this.XmlOutput.WriteStartElement("ScaleTransform");
183 this.XmlOutput.WriteAttributeString("ScaleX", Scale);
184 this.XmlOutput.WriteAttributeString("ScaleY", Scale);
185 this.XmlOutput.WriteEndElement();
186
187 this.XmlOutput.WriteStartElement("TranslateTransform");
188 this.XmlOutput.WriteAttributeString("Y", Offset);
189 this.XmlOutput.WriteEndElement();
190
191 this.XmlOutput.WriteEndElement();
192 this.XmlOutput.WriteEndElement();
193 this.XmlOutput.WriteEndElement();
194
196 {
197 this.XmlOutput.WriteStartElement("TextBlock");
198 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
199 }
200 else
201 this.XmlOutput.WriteStartElement("StackPanel");
202
203 this.XmlOutput.WriteAttributeString("Grid.Column", "1");
204 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
205
206 TextAlignment Bak = this.Alignment;
207 this.Alignment = TextAlignment.Left;
208
209 await Footnote.Render(this);
210 this.Alignment = Bak;
211
212 this.XmlOutput.WriteEndElement();
213
214 Row++;
215 }
216 }
217
218 this.XmlOutput.WriteEndElement();
219 }
220
224 public override Task RenderDocumentFooter()
225 {
226 this.XmlOutput.WriteEndElement();
227 this.XmlOutput.Flush();
228
229 return Task.CompletedTask;
230 }
231
232 #region Span Elements
233
238 public override Task Render(Abbreviation Element)
239 {
240 return this.RenderChildren(Element);
241 }
242
247 public override Task Render(AutomaticLinkMail Element)
248 {
249 this.XmlOutput.WriteStartElement("Hyperlink");
250 this.XmlOutput.WriteAttributeString("NavigateUri", "mailto:" + Element.EMail);
251 this.XmlOutput.WriteValue(Element.EMail);
252 this.XmlOutput.WriteEndElement();
253
254 return Task.CompletedTask;
255 }
256
261 public override Task Render(AutomaticLinkUrl Element)
262 {
263 this.XmlOutput.WriteStartElement("Hyperlink");
264 this.XmlOutput.WriteAttributeString("NavigateUri", this.Document.CheckURL(Element.URL, null));
265 this.XmlOutput.WriteValue(Element.URL);
266 this.XmlOutput.WriteEndElement();
267
268 return Task.CompletedTask;
269 }
270
275 public override async Task Render(Delete Element)
276 {
277 this.XmlOutput.WriteStartElement("TextBlock");
278 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
279
280 if (this.Alignment != TextAlignment.Left)
281 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
282
283 this.XmlOutput.WriteStartElement("TextBlock.TextDecorations");
284 this.XmlOutput.WriteStartElement("TextDecoration");
285 this.XmlOutput.WriteAttributeString("Location", "Strikethrough");
286 this.XmlOutput.WriteEndElement();
287 this.XmlOutput.WriteEndElement();
288
289 await this.RenderChildren(Element);
290
291 this.XmlOutput.WriteEndElement();
292 }
293
298 public override Task Render(DetailsReference Element)
299 {
300 if (!(this.Document.Detail is null))
301 return this.RenderDocument(this.Document.Detail, false);
302 else
303 return this.Render((MetaReference)Element);
304 }
305
310 public override async Task Render(EmojiReference Element)
311 {
312 IEmojiSource EmojiSource = this.Document.EmojiSource;
313
314 if (EmojiSource is null)
315 {
316 this.XmlOutput.WriteValue(Element.Delimiter);
317 this.XmlOutput.WriteValue(Element.Emoji.ShortName);
318 this.XmlOutput.WriteValue(Element.Delimiter);
319 }
320 else if (!EmojiSource.EmojiSupported(Element.Emoji))
321 this.XmlOutput.WriteValue(Element.Emoji.Unicode);
322 else
323 {
324 IImageSource Source = await EmojiSource.GetImageSource(Element.Emoji, Element.Level);
325 await Multimedia.ImageContent.OutputWpf(this.XmlOutput, Source, Element.Emoji.Description);
326 }
327 }
328
333 public override async Task Render(Emphasize Element)
334 {
335 this.XmlOutput.WriteStartElement("Italic");
336 await this.RenderChildren(Element);
337 this.XmlOutput.WriteEndElement();
338 }
339
344 public override async Task Render(FootnoteReference Element)
345 {
346 if (!(this.Document?.TryGetFootnote(Element.Key, out Footnote Footnote) ?? false))
347 Footnote = null;
348
349 if (Element.AutoExpand && !(Footnote is null))
350 await this.Render(Footnote);
351 else if (this.Document?.TryGetFootnoteNumber(Element.Key, out int Nr) ?? false)
352 {
353 string s;
354
355 this.XmlOutput.WriteStartElement("TextBlock");
356 this.XmlOutput.WriteAttributeString("Text", Nr.ToString());
357
358 this.XmlOutput.WriteStartElement("TextBlock.LayoutTransform");
359 this.XmlOutput.WriteStartElement("TransformGroup");
360
361 this.XmlOutput.WriteStartElement("ScaleTransform");
362 this.XmlOutput.WriteAttributeString("ScaleX", s = CommonTypes.Encode(this.XamlSettings.SuperscriptScale));
363 this.XmlOutput.WriteAttributeString("ScaleY", s);
364 this.XmlOutput.WriteEndElement();
365
366 this.XmlOutput.WriteStartElement("TranslateTransform");
367 this.XmlOutput.WriteAttributeString("Y", this.XamlSettings.SuperscriptOffset.ToString());
368 this.XmlOutput.WriteEndElement();
369
370 this.XmlOutput.WriteEndElement();
371 this.XmlOutput.WriteEndElement();
372 this.XmlOutput.WriteEndElement();
373
374 if (!(Footnote is null))
375 Footnote.Referenced = true;
376 }
377 }
378
383 public override Task Render(HashTag Element)
384 {
385 this.XmlOutput.WriteValue(Element.Tag);
386
387 return Task.CompletedTask;
388 }
389
394 public override Task Render(HtmlEntity Element)
395 {
396 string s = Html.HtmlEntity.EntityToCharacter(Element.Entity);
397 if (s is null)
398 this.XmlOutput.WriteRaw("&" + Element.Entity + ";");
399 else
400 this.XmlOutput.WriteValue(s);
401
402 return Task.CompletedTask;
403 }
404
409 public override Task Render(HtmlEntityUnicode Element)
410 {
411 this.XmlOutput.WriteValue(new string((char)Element.Code, 1));
412
413 return Task.CompletedTask;
414 }
415
420 public override Task Render(InlineCode Element)
421 {
422 this.XmlOutput.WriteStartElement("TextBlock");
423 this.XmlOutput.WriteAttributeString("xml", "space", null, "preserve");
424 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
425 this.XmlOutput.WriteAttributeString("FontFamily", "Courier New");
426 if (this.Alignment != TextAlignment.Left)
427 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
428
429 this.XmlOutput.WriteValue(Element.Code);
430
431 this.XmlOutput.WriteEndElement();
432
433 return Task.CompletedTask;
434 }
435
440 public override Task Render(InlineHTML Element)
441 {
442 this.XmlOutput.WriteComment(Element.HTML);
443
444 return Task.CompletedTask;
445 }
446
451 public override async Task Render(InlineScript Element)
452 {
453 object Result = await Element.EvaluateExpression();
454 await this.RenderObject(Result, Element.AloneInParagraph, Element.Variables);
455 }
456
463 public async Task RenderObject(object Result, bool AloneInParagraph, Variables Variables)
464 {
465 if (Result is null)
466 return;
467
468 string s;
469
470 if (Result is XmlDocument Xml)
471 Result = await MarkdownDocument.TransformXml(Xml, Variables);
472 else if (Result is IToMatrix ToMatrix)
473 Result = ToMatrix.ToMatrix();
474
475 if (Result is Graph G)
476 {
477 PixelInformation Pixels = G.CreatePixels();
478 byte[] Bin = Pixels.EncodeAsPng();
479
480 s = "data:image/png;base64," + Convert.ToBase64String(Bin, 0, Bin.Length);
481
482 await Multimedia.ImageContent.OutputWpf(this.XmlOutput, new ImageSource()
483 {
484 Url = s,
485 Width = Pixels.Width,
486 Height = Pixels.Height
487 }, string.Empty);
488 }
489 else if (Result is SKImage Img)
490 {
491 using (SKData Data = Img.Encode(SKEncodedImageFormat.Png, 100))
492 {
493 byte[] Bin = Data.ToArray();
494
495 s = "data:image/png;base64," + Convert.ToBase64String(Bin, 0, Bin.Length);
496
497 await Multimedia.ImageContent.OutputWpf(this.XmlOutput, new ImageSource()
498 {
499 Url = s,
500 Width = Img.Width,
501 Height = Img.Height
502 }, string.Empty);
503 }
504 }
505 else if (Result is MarkdownDocument Doc)
506 {
507 await this.RenderDocument(Doc, true); // Does not call ProcessAsyncTasks()
508 Doc.ProcessAsyncTasks();
509 }
510 else if (Result is MarkdownContent Markdown)
511 {
512 Doc = await MarkdownDocument.CreateAsync(Markdown.Markdown, Markdown.Settings ?? new MarkdownSettings());
513 await this.RenderDocument(Doc, true); // Does not call ProcessAsyncTasks()
514 Doc.ProcessAsyncTasks();
515 }
516 else if (Result is Exception ex)
517 {
518 ex = Log.UnnestException(ex);
519
520 if (ex is AggregateException ex2)
521 {
522 foreach (Exception ex3 in ex2.InnerExceptions)
523 {
524 this.XmlOutput.WriteStartElement("TextBlock");
525 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
526 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
527
528 if (this.Alignment != TextAlignment.Left)
529 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
530
531 this.XmlOutput.WriteAttributeString("Foreground", "Red");
532 this.XmlOutput.WriteValue(ex3.Message);
533 this.XmlOutput.WriteEndElement();
534 }
535 }
536 else
537 {
538 if (AloneInParagraph)
539 {
540 this.XmlOutput.WriteStartElement("TextBlock");
541 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
542 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
543 if (this.Alignment != TextAlignment.Left)
544 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
545 }
546 else
547 this.XmlOutput.WriteStartElement("Run");
548
549 this.XmlOutput.WriteAttributeString("Foreground", "Red");
550 this.XmlOutput.WriteValue(ex.Message);
551 this.XmlOutput.WriteEndElement();
552 }
553 }
554 else
555 {
556 if (AloneInParagraph)
557 {
558 this.XmlOutput.WriteStartElement("TextBlock");
559 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
560 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
561 if (this.Alignment != TextAlignment.Left)
562 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
563 }
564
565 this.XmlOutput.WriteValue(Result.ToString());
566
567 if (AloneInParagraph)
568 this.XmlOutput.WriteEndElement();
569 }
570 }
571
576 public override Task Render(InlineText Element)
577 {
578 this.XmlOutput.WriteValue(Element.Value);
579
580 return Task.CompletedTask;
581 }
582
587 public override async Task Render(Insert Element)
588 {
589 this.XmlOutput.WriteStartElement("Underline");
590 await this.RenderChildren(Element);
591 this.XmlOutput.WriteEndElement();
592 }
593
598 public override Task Render(LineBreak Element)
599 {
600 this.XmlOutput.WriteElementString("LineBreak", string.Empty);
601
602 return Task.CompletedTask;
603 }
604
609 public override Task Render(Link Element)
610 {
611 return this.Render(Element.Url, Element.Title, Element.Children, Element.Document);
612 }
613
621 public async Task Render(string Url, string Title, IEnumerable<MarkdownElement> ChildNodes, MarkdownDocument Document)
622 {
623 this.XmlOutput.WriteStartElement("Hyperlink");
624 this.XmlOutput.WriteAttributeString("NavigateUri", Document.CheckURL(Url, null));
625
626 if (!string.IsNullOrEmpty(Title))
627 this.XmlOutput.WriteAttributeString("ToolTip", Title);
628
629 foreach (MarkdownElement E in ChildNodes)
630 await E.Render(this);
631
632 this.XmlOutput.WriteEndElement();
633 }
634
639 public override Task Render(LinkReference Element)
640 {
642
643 if (!(Multimedia is null))
644 return this.Render(Multimedia.Items[0].Url, Multimedia.Items[0].Title, Element.Children, Element.Document);
645 else
646 return this.RenderChildren(Element);
647 }
648
653 public override Task Render(MetaReference Element)
654 {
655 bool FirstOnRow = true;
656
657 if (Element.TryGetMetaData(out KeyValuePair<string, bool>[] Values))
658 {
659 foreach (KeyValuePair<string, bool> P in Values)
660 {
661 if (FirstOnRow)
662 FirstOnRow = false;
663 else
664 this.XmlOutput.WriteValue(' ');
665
666 this.XmlOutput.WriteValue(P.Key);
667 if (P.Value)
668 {
669 this.XmlOutput.WriteElementString("LineBreak", string.Empty);
670 FirstOnRow = true;
671 }
672 }
673 }
674
675 return Task.CompletedTask;
676 }
677
682 public override Task Render(Model.SpanElements.Multimedia Element)
683 {
685 if (Renderer is null)
686 return this.RenderChildren(Element);
687 else
688 return Renderer.RenderWpfXaml(this, Element.Items, Element.Children, Element.AloneInParagraph, Element.Document);
689 }
690
695 public override Task Render(MultimediaReference Element)
696 {
698
699 if (!(Multimedia is null))
700 {
702 if (!(Renderer is null))
703 return Renderer.RenderWpfXaml(this, Multimedia.Items, Element.Children, Element.AloneInParagraph, Element.Document);
704 }
705
706 return this.RenderChildren(Element);
707 }
708
713 public override async Task Render(StrikeThrough Element)
714 {
715 this.XmlOutput.WriteStartElement("TextBlock");
716 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
717 if (this.Alignment != TextAlignment.Left)
718 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
719
720 this.XmlOutput.WriteStartElement("TextBlock.TextDecorations");
721 this.XmlOutput.WriteStartElement("TextDecoration");
722 this.XmlOutput.WriteAttributeString("Location", "Strikethrough");
723 this.XmlOutput.WriteEndElement();
724 this.XmlOutput.WriteEndElement();
725
726 await this.RenderChildren(Element);
727
728 this.XmlOutput.WriteEndElement();
729 }
730
735 public override async Task Render(Strong Element)
736 {
737 this.XmlOutput.WriteStartElement("Bold");
738 await this.RenderChildren(Element);
739 this.XmlOutput.WriteEndElement();
740 }
741
746 public override async Task Render(SubScript Element)
747 {
748 this.XmlOutput.WriteStartElement("Run");
749 this.XmlOutput.WriteAttributeString("Typography.Variants", "Subscript");
750
751 await this.RenderChildren(Element);
752
753 this.XmlOutput.WriteEndElement();
754 }
755
760 public override async Task Render(SuperScript Element)
761 {
762 this.XmlOutput.WriteStartElement("Run");
763 this.XmlOutput.WriteAttributeString("Typography.Variants", "Superscript");
764
765 await this.RenderChildren(Element);
766
767 this.XmlOutput.WriteEndElement();
768 }
769
774 public override async Task Render(Underline Element)
775 {
776 this.XmlOutput.WriteStartElement("Underline");
777 await this.RenderChildren(Element);
778 this.XmlOutput.WriteEndElement();
779 }
780
781 #endregion
782
783 #region Block elements
784
789 public override async Task Render(BlockQuote Element)
790 {
791 this.XmlOutput.WriteStartElement("Border");
792 this.XmlOutput.WriteAttributeString("BorderThickness", this.XamlSettings.BlockQuoteBorderThickness.ToString() + ",0,0,0");
793 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.BlockQuoteMargin.ToString() + "," +
794 this.XamlSettings.ParagraphMarginTop.ToString() + ",0," + this.XamlSettings.ParagraphMarginBottom.ToString());
795 this.XmlOutput.WriteAttributeString("Padding", this.XamlSettings.BlockQuotePadding.ToString() + ",0,0,0");
796 this.XmlOutput.WriteAttributeString("BorderBrush", this.XamlSettings.BlockQuoteBorderColor);
797 this.XmlOutput.WriteStartElement("StackPanel");
798
799 await this.RenderChildren(Element);
800
801 this.XmlOutput.WriteEndElement();
802 this.XmlOutput.WriteEndElement();
803 }
804
809 public override async Task Render(BulletList Element)
810 {
811 int Row = 0;
812 bool ParagraphBullet;
813
814 this.XmlOutput.WriteStartElement("Grid");
815 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
816 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
817
818 this.XmlOutput.WriteStartElement("ColumnDefinition");
819 this.XmlOutput.WriteAttributeString("Width", "Auto");
820 this.XmlOutput.WriteEndElement();
821
822 this.XmlOutput.WriteStartElement("ColumnDefinition");
823 this.XmlOutput.WriteAttributeString("Width", "*");
824 this.XmlOutput.WriteEndElement();
825
826 this.XmlOutput.WriteEndElement();
827 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
828
829 foreach (MarkdownElement _ in Element.Children)
830 {
831 this.XmlOutput.WriteStartElement("RowDefinition");
832 this.XmlOutput.WriteAttributeString("Height", "Auto");
833 this.XmlOutput.WriteEndElement();
834 }
835
836 this.XmlOutput.WriteEndElement();
837
838 foreach (MarkdownElement E in Element.Children)
839 {
840 ParagraphBullet = !E.InlineSpanElement || E.OutsideParagraph;
841 this.GetMargins(E, out int TopMargin, out int BottomMargin);
842
843 this.XmlOutput.WriteStartElement("TextBlock");
844 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
845 this.XmlOutput.WriteAttributeString("Grid.Column", "0");
846 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
847 if (this.Alignment != TextAlignment.Left)
848 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
849
850 this.XmlOutput.WriteAttributeString("Margin", "0," + TopMargin.ToString() + "," +
851 this.XamlSettings.ListContentMargin.ToString() + "," + BottomMargin.ToString());
852
853 this.XmlOutput.WriteValue("•");
854 this.XmlOutput.WriteEndElement();
855
856 this.XmlOutput.WriteStartElement("StackPanel");
857 this.XmlOutput.WriteAttributeString("Grid.Column", "1");
858 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
859
860 if (ParagraphBullet)
861 await E.Render(this);
862 else
863 {
864 this.XmlOutput.WriteStartElement("TextBlock");
865 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
866 if (this.Alignment != TextAlignment.Left)
867 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
868
869 await E.Render(this);
870
871 this.XmlOutput.WriteEndElement();
872 }
873
874 this.XmlOutput.WriteEndElement();
875
876 Row++;
877 }
878
879 this.XmlOutput.WriteEndElement();
880 }
881
888 private void GetMargins(MarkdownElement Element, out int TopMargin, out int BottomMargin)
889 {
890 if (Element.InlineSpanElement && !Element.OutsideParagraph)
891 {
892 TopMargin = 0;
893 BottomMargin = 0;
894 }
895 else if (Element is NestedBlock NestedBlock)
896 {
897 bool First = true;
898
899 TopMargin = BottomMargin = 0;
900
902 {
903 if (First)
904 {
905 First = false;
906 this.GetMargins(E, out TopMargin, out BottomMargin);
907 }
908 else
909 this.GetMargins(E, out int _, out BottomMargin);
910 }
911 }
912 else if (Element is MarkdownElementSingleChild SingleChild)
913 this.GetMargins(SingleChild.Child, out TopMargin, out BottomMargin);
914 else
915 {
916 TopMargin = this.XamlSettings.ParagraphMarginTop;
917 BottomMargin = this.XamlSettings.ParagraphMarginBottom;
918 }
919 }
920
925 public override async Task Render(CenterAligned Element)
926 {
927 this.XmlOutput.WriteStartElement("StackPanel");
928
929 TextAlignment Bak = this.Alignment;
930 this.Alignment = TextAlignment.Center;
931
932 await this.RenderChildren(Element);
933
934 this.Alignment = Bak;
935 this.XmlOutput.WriteEndElement();
936 }
937
942 public override async Task Render(CodeBlock Element)
943 {
945
946 if (!(Renderer is null))
947 {
948 try
949 {
950 if (await Renderer.RenderWpfXaml(this, Element.Rows, Element.Language, Element.Indent, Element.Document))
951 return;
952 }
953 catch (Exception ex)
954 {
955 ex = Log.UnnestException(ex);
956
957 if (ex is AggregateException ex2)
958 {
959 foreach (Exception ex3 in ex2.InnerExceptions)
960 {
961 this.XmlOutput.WriteStartElement("TextBlock");
962 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
963 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
964
965 if (this.Alignment != TextAlignment.Left)
966 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
967
968 this.XmlOutput.WriteAttributeString("Foreground", "Red");
969 this.XmlOutput.WriteValue(ex3.Message);
970 this.XmlOutput.WriteEndElement();
971 }
972 }
973 else
974 {
975 this.XmlOutput.WriteStartElement("TextBlock");
976 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
977 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
978 if (this.Alignment != TextAlignment.Left)
979 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
980
981 this.XmlOutput.WriteAttributeString("Foreground", "Red");
982 this.XmlOutput.WriteValue(ex.Message);
983 this.XmlOutput.WriteEndElement();
984 }
985 }
986 }
987
988 int i;
989 bool First = true;
990
991 this.XmlOutput.WriteStartElement("TextBlock");
992 this.XmlOutput.WriteAttributeString("xml", "space", null, "preserve");
993 this.XmlOutput.WriteAttributeString("TextWrapping", "NoWrap");
994 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
995 this.XmlOutput.WriteAttributeString("FontFamily", "Courier New");
996 if (this.Alignment != TextAlignment.Left)
997 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
998
999 for (i = Element.Start; i <= Element.End; i++)
1000 {
1001 if (First)
1002 First = false;
1003 else
1004 this.XmlOutput.WriteElementString("LineBreak", string.Empty);
1005
1006 this.XmlOutput.WriteValue(Element.Rows[i]);
1007 }
1008
1009 this.XmlOutput.WriteEndElement();
1010 }
1011
1016 public override Task Render(CommentBlock Element)
1017 {
1018 return Task.CompletedTask;
1019 }
1020
1025 public override async Task Render(DefinitionDescriptions Element)
1026 {
1027 MarkdownElement Last = null;
1028
1029 foreach (MarkdownElement Description in Element.Children)
1030 Last = Description;
1031
1032 foreach (MarkdownElement Description in Element.Children)
1033 {
1034 if (Description.InlineSpanElement && !Description.OutsideParagraph)
1035 {
1036 this.XmlOutput.WriteStartElement("TextBlock");
1037 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1038 }
1039 else
1040 this.XmlOutput.WriteStartElement("StackPanel");
1041
1042 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.DefinitionMargin.ToString() + ",0,0," +
1043 (Description == Last ? this.XamlSettings.DefinitionSeparator : 0).ToString());
1044
1045 await Description.Render(this);
1046 this.XmlOutput.WriteEndElement();
1047 }
1048 }
1049
1054 public override Task Render(DefinitionList Element)
1055 {
1056 return this.RenderChildren(Element);
1057 }
1058
1063 public override async Task Render(DefinitionTerms Element)
1064 {
1065 int TopMargin = this.XamlSettings.ParagraphMarginTop;
1066
1067 foreach (MarkdownElement Term in Element.Children)
1068 {
1069 this.XmlOutput.WriteStartElement("TextBlock");
1070 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1071 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMarginLeft.ToString() + "," +
1072 TopMargin.ToString() + "," + this.XamlSettings.ParagraphMarginRight.ToString() + ",0");
1073 this.XmlOutput.WriteAttributeString("FontWeight", "Bold");
1074
1075 await Term.Render(this);
1076
1077 this.XmlOutput.WriteEndElement();
1078 TopMargin = 0;
1079 }
1080 }
1081
1086 public override async Task Render(DeleteBlocks Element)
1087 {
1088 this.XmlOutput.WriteStartElement("Border");
1089 this.XmlOutput.WriteAttributeString("BorderThickness", this.XamlSettings.BlockQuoteBorderThickness.ToString() + ",0,0,0");
1090 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.BlockQuoteMargin.ToString() + "," +
1091 this.XamlSettings.ParagraphMarginTop.ToString() + ",0," + this.XamlSettings.ParagraphMarginBottom.ToString());
1092 this.XmlOutput.WriteAttributeString("Padding", this.XamlSettings.BlockQuotePadding.ToString() + ",0,0,0");
1093 this.XmlOutput.WriteAttributeString("BorderBrush", this.XamlSettings.DeletedBlockQuoteBorderColor);
1094 this.XmlOutput.WriteStartElement("StackPanel");
1095
1096 foreach (MarkdownElement E in Element.Children)
1097 await E.Render(this);
1098
1099 this.XmlOutput.WriteEndElement();
1100 this.XmlOutput.WriteEndElement();
1101 }
1102
1107 public override Task Render(Footnote Element)
1108 {
1109 return this.RenderChildren(Element);
1110 }
1111
1116 public override async Task Render(Header Element)
1117 {
1118 this.XmlOutput.WriteStartElement("TextBlock");
1119 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1120 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1121 if (this.Alignment != TextAlignment.Left)
1122 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1123
1124 if (Element.Level > 0 && Element.Level <= this.XamlSettings.HeaderFontSize.Length)
1125 {
1126 this.XmlOutput.WriteAttributeString("FontSize", this.XamlSettings.HeaderFontSize[Element.Level - 1].ToString());
1127 this.XmlOutput.WriteAttributeString("Foreground", this.XamlSettings.HeaderForegroundColor[Element.Level - 1].ToString());
1128 }
1129
1130 await this.RenderChildren(Element);
1131
1132 this.XmlOutput.WriteEndElement();
1133 }
1134
1139 public override Task Render(HorizontalRule Element)
1140 {
1141 this.XmlOutput.WriteElementString("Separator", string.Empty);
1142
1143 return Task.CompletedTask;
1144 }
1145
1150 public override async Task Render(HtmlBlock Element)
1151 {
1152 this.XmlOutput.WriteStartElement("TextBlock");
1153 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1154 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1155 if (this.Alignment != TextAlignment.Left)
1156 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1157
1158 await this.RenderChildren(Element);
1159
1160 this.XmlOutput.WriteEndElement();
1161 }
1162
1167 public override async Task Render(InsertBlocks Element)
1168 {
1169 this.XmlOutput.WriteStartElement("Border");
1170 this.XmlOutput.WriteAttributeString("BorderThickness", this.XamlSettings.BlockQuoteBorderThickness.ToString() + ",0,0,0");
1171 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.BlockQuoteMargin.ToString() + "," +
1172 this.XamlSettings.ParagraphMarginTop.ToString() + ",0," + this.XamlSettings.ParagraphMarginBottom.ToString());
1173 this.XmlOutput.WriteAttributeString("Padding", this.XamlSettings.BlockQuotePadding.ToString() + ",0,0,0");
1174 this.XmlOutput.WriteAttributeString("BorderBrush", this.XamlSettings.InsertedBlockQuoteBorderColor);
1175 this.XmlOutput.WriteStartElement("StackPanel");
1176
1177 await this.RenderChildren(Element);
1178
1179 this.XmlOutput.WriteEndElement();
1180 this.XmlOutput.WriteEndElement();
1181 }
1182
1187 public override Task Render(InvisibleBreak Element)
1188 {
1189 return Task.CompletedTask;
1190 }
1191
1196 public override async Task Render(LeftAligned Element)
1197 {
1198 this.XmlOutput.WriteStartElement("StackPanel");
1199
1200 TextAlignment Bak = this.Alignment;
1201 this.Alignment = TextAlignment.Left;
1202
1203 await this.RenderChildren(Element);
1204
1205 this.Alignment = Bak;
1206 this.XmlOutput.WriteEndElement();
1207 }
1208
1213 public override async Task Render(MarginAligned Element)
1214 {
1215 this.XmlOutput.WriteStartElement("StackPanel");
1216
1217 TextAlignment Bak = this.Alignment;
1218 this.Alignment = TextAlignment.Left;
1219
1220 await this.RenderChildren(Element);
1221
1222 this.Alignment = Bak;
1223 this.XmlOutput.WriteEndElement();
1224 }
1225
1230 public override async Task Render(NestedBlock Element)
1231 {
1232 if (Element.HasOneChild)
1233 await Element.FirstChild.Render(this);
1234 else
1235 {
1236 bool SpanOpen = false;
1237
1238 foreach (MarkdownElement E in Element.Children)
1239 {
1240 if (E.InlineSpanElement)
1241 {
1242 if (!SpanOpen)
1243 {
1244 this.XmlOutput.WriteStartElement("TextBlock");
1245 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1246 if (this.Alignment != TextAlignment.Left)
1247 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1248 SpanOpen = true;
1249 }
1250 }
1251 else
1252 {
1253 if (SpanOpen)
1254 {
1255 this.XmlOutput.WriteEndElement();
1256 SpanOpen = false;
1257 }
1258 }
1259
1260 await E.Render(this);
1261 }
1262
1263 if (SpanOpen)
1264 this.XmlOutput.WriteEndElement();
1265 }
1266 }
1267
1272 public override Task Render(NumberedItem Element)
1273 {
1274 return this.RenderChild(Element);
1275 }
1276
1281 public override async Task Render(NumberedList Element)
1282 {
1283 NumberedItem Item;
1284 int Expected = 0;
1285 int Row = 0;
1286 bool ParagraphBullet;
1287
1288 this.XmlOutput.WriteStartElement("Grid");
1289 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1290 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
1291
1292 this.XmlOutput.WriteStartElement("ColumnDefinition");
1293 this.XmlOutput.WriteAttributeString("Width", "Auto");
1294 this.XmlOutput.WriteEndElement();
1295
1296 this.XmlOutput.WriteStartElement("ColumnDefinition");
1297 this.XmlOutput.WriteAttributeString("Width", "*");
1298 this.XmlOutput.WriteEndElement();
1299
1300 this.XmlOutput.WriteEndElement();
1301 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
1302
1303 foreach (MarkdownElement _ in Element.Children)
1304 {
1305 this.XmlOutput.WriteStartElement("RowDefinition");
1306 this.XmlOutput.WriteAttributeString("Height", "Auto");
1307 this.XmlOutput.WriteEndElement();
1308 }
1309
1310 this.XmlOutput.WriteEndElement();
1311
1312 foreach (MarkdownElement E in Element.Children)
1313 {
1314 Expected++;
1315 Item = E as NumberedItem;
1316
1317 ParagraphBullet = !E.InlineSpanElement || E.OutsideParagraph;
1318 this.GetMargins(E, out int TopMargin, out int BottomMargin);
1319
1320 this.XmlOutput.WriteStartElement("TextBlock");
1321 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1322 this.XmlOutput.WriteAttributeString("Grid.Column", "0");
1323 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
1324 if (this.Alignment != TextAlignment.Left)
1325 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1326
1327 this.XmlOutput.WriteAttributeString("Margin", "0," + TopMargin.ToString() + "," +
1328 this.XamlSettings.ListContentMargin.ToString() + "," + BottomMargin.ToString());
1329
1330 if (!(Item is null))
1331 this.XmlOutput.WriteValue((Expected = Item.Number).ToString());
1332 else
1333 this.XmlOutput.WriteValue(Expected.ToString());
1334
1335 this.XmlOutput.WriteValue(".");
1336 this.XmlOutput.WriteEndElement();
1337
1338 this.XmlOutput.WriteStartElement("StackPanel");
1339 this.XmlOutput.WriteAttributeString("Grid.Column", "1");
1340 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
1341
1342 if (ParagraphBullet)
1343 await E.Render(this);
1344 else
1345 {
1346 this.XmlOutput.WriteStartElement("TextBlock");
1347 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1348 if (this.Alignment != TextAlignment.Left)
1349 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1350
1351 await E.Render(this);
1352
1353 this.XmlOutput.WriteEndElement();
1354 }
1355
1356 this.XmlOutput.WriteEndElement();
1357
1358 Row++;
1359 }
1360
1361 this.XmlOutput.WriteEndElement();
1362 }
1363
1368 public override async Task Render(Paragraph Element)
1369 {
1371
1372 this.XmlOutput.WriteStartElement("TextBlock");
1373 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1374 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1375 if (this.Alignment != TextAlignment.Left)
1376 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1377
1378 foreach (MarkdownElement E in Element.Children)
1379 {
1380 if ((!E.InlineSpanElement || E.OutsideParagraph) && (s = E.BaselineAlignment) != BaselineAlignment.Baseline)
1381 {
1382 this.XmlOutput.WriteStartElement("InlineUIContainer");
1383 this.XmlOutput.WriteAttributeString("BaselineAlignment", s.ToString());
1384
1385 await E.Render(this);
1386
1387 this.XmlOutput.WriteEndElement();
1388 }
1389 else
1390 await E.Render(this);
1391 }
1392
1393 this.XmlOutput.WriteEndElement();
1394 }
1395
1400 public override async Task Render(RightAligned Element)
1401 {
1402 this.XmlOutput.WriteStartElement("StackPanel");
1403
1404 TextAlignment Bak = this.Alignment;
1405 this.Alignment = TextAlignment.Right;
1406
1407 await this.RenderChildren(Element);
1408
1409 this.Alignment = Bak;
1410 this.XmlOutput.WriteEndElement();
1411 }
1412
1417 public override Task Render(Sections Element)
1418 {
1419 return this.RenderChildren(Element);
1420 }
1421
1426 public override Task Render(SectionSeparator Element)
1427 {
1428 this.XmlOutput.WriteElementString("Separator", string.Empty);
1429
1430 return Task.CompletedTask;
1431 }
1432
1437 public override async Task Render(Table Element)
1438 {
1439 int Column;
1440 int Row, NrRows;
1441 int RowNr = 0;
1442 int NrColumns = Element.Columns;
1443
1444 this.XmlOutput.WriteStartElement("Grid");
1445 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1446 if (!string.IsNullOrEmpty(Element.Caption))
1447 this.XmlOutput.WriteAttributeString("ToolTip", Element.Caption);
1448
1449 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
1450
1451 for (Column = 0; Column < NrColumns; Column++)
1452 {
1453 this.XmlOutput.WriteStartElement("ColumnDefinition");
1454 this.XmlOutput.WriteAttributeString("Width", "Auto");
1455 this.XmlOutput.WriteEndElement();
1456 }
1457
1458 this.XmlOutput.WriteEndElement();
1459 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
1460
1461 for (Row = 0, NrRows = Element.Rows.Length + Element.Headers.Length; Row < NrRows; Row++)
1462 {
1463 this.XmlOutput.WriteStartElement("RowDefinition");
1464 this.XmlOutput.WriteAttributeString("Height", "Auto");
1465 this.XmlOutput.WriteEndElement();
1466 }
1467
1468 this.XmlOutput.WriteEndElement();
1469
1470 for (Row = 0, NrRows = Element.Headers.Length; Row < NrRows; Row++, RowNr++)
1471 await this.Render(Element.Headers[Row], Element.HeaderCellAlignments[Row], RowNr, true, Element);
1472
1473 for (Row = 0, NrRows = Element.Rows.Length; Row < NrRows; Row++, RowNr++)
1474 await this.Render(Element.Rows[Row], Element.RowCellAlignments[Row], RowNr, false, Element);
1475
1476 this.XmlOutput.WriteEndElement();
1477 }
1478
1479 private async Task Render(MarkdownElement[] CurrentRow, TextAlignment?[] CellAlignments, int RowNr, bool Bold, Table Element)
1480 {
1481 TextAlignment Bak = this.Alignment;
1483 int NrColumns = Element.Columns;
1484 int Column;
1485 int ColSpan;
1486
1487 for (Column = 0; Column < NrColumns; Column++)
1488 {
1489 E = CurrentRow[Column];
1490 if (E is null)
1491 continue;
1492
1493 this.Alignment = CellAlignments[Column] ?? Element.ColumnAlignments[Column];
1494 ColSpan = Column + 1;
1495 while (ColSpan < NrColumns && CurrentRow[ColSpan] is null)
1496 ColSpan++;
1497
1498 ColSpan -= Column;
1499
1500 this.XmlOutput.WriteStartElement("Border");
1501 this.XmlOutput.WriteAttributeString("BorderBrush", this.XamlSettings.TableCellBorderColor);
1502 this.XmlOutput.WriteAttributeString("BorderThickness", CommonTypes.Encode(this.XamlSettings.TableCellBorderThickness));
1503
1504 if ((RowNr & 1) == 0)
1505 {
1506 if (!string.IsNullOrEmpty(this.XamlSettings.TableCellRowBackgroundColor1))
1507 this.XmlOutput.WriteAttributeString("Background", this.XamlSettings.TableCellRowBackgroundColor1);
1508 }
1509 else
1510 {
1511 if (!string.IsNullOrEmpty(this.XamlSettings.TableCellRowBackgroundColor2))
1512 this.XmlOutput.WriteAttributeString("Background", this.XamlSettings.TableCellRowBackgroundColor2);
1513 }
1514
1515 this.XmlOutput.WriteAttributeString("Grid.Column", Column.ToString());
1516 this.XmlOutput.WriteAttributeString("Grid.Row", RowNr.ToString());
1517
1518 if (ColSpan > 1)
1519 this.XmlOutput.WriteAttributeString("Grid.ColumnSpan", ColSpan.ToString());
1520
1521 if (E.InlineSpanElement)
1522 {
1523 this.XmlOutput.WriteStartElement("TextBlock");
1524 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1525 this.XmlOutput.WriteAttributeString("Padding", this.XamlSettings.TableCellPadding);
1526
1527 if (Bold)
1528 this.XmlOutput.WriteAttributeString("FontWeight", "Bold");
1529
1530 if (this.Alignment != TextAlignment.Left)
1531 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1532 }
1533 else
1534 {
1535 this.XmlOutput.WriteStartElement("StackPanel");
1536 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.TableCellPadding);
1537 }
1538
1539 await E.Render(this);
1540 this.XmlOutput.WriteEndElement();
1541 this.XmlOutput.WriteEndElement();
1542 }
1543
1544 this.Alignment = Bak;
1545 }
1546
1551 public override Task Render(TaskItem Element)
1552 {
1553 return this.RenderChild(Element);
1554 }
1555
1560 public override async Task Render(TaskList Element)
1561 {
1562 int Row = 0;
1563 bool ParagraphBullet;
1564
1565 this.XmlOutput.WriteStartElement("Grid");
1566 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1567 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
1568
1569 this.XmlOutput.WriteStartElement("ColumnDefinition");
1570 this.XmlOutput.WriteAttributeString("Width", "Auto");
1571 this.XmlOutput.WriteEndElement();
1572
1573 this.XmlOutput.WriteStartElement("ColumnDefinition");
1574 this.XmlOutput.WriteAttributeString("Width", "*");
1575 this.XmlOutput.WriteEndElement();
1576
1577 this.XmlOutput.WriteEndElement();
1578 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
1579
1580 foreach (MarkdownElement _ in Element.Children)
1581 {
1582 this.XmlOutput.WriteStartElement("RowDefinition");
1583 this.XmlOutput.WriteAttributeString("Height", "Auto");
1584 this.XmlOutput.WriteEndElement();
1585 }
1586
1587 this.XmlOutput.WriteEndElement();
1588
1589 foreach (MarkdownElement E in Element.Children)
1590 {
1591 ParagraphBullet = !E.InlineSpanElement || E.OutsideParagraph;
1592 this.GetMargins(E, out int TopMargin, out int BottomMargin);
1593
1594 if (E is TaskItem TaskItem && TaskItem.IsChecked)
1595 {
1596 this.XmlOutput.WriteStartElement("TextBlock");
1597 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1598 this.XmlOutput.WriteAttributeString("Grid.Column", "0");
1599 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
1600 if (this.Alignment != TextAlignment.Left)
1601 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1602
1603 this.XmlOutput.WriteAttributeString("Margin", "0," + TopMargin.ToString() + "," +
1604 this.XamlSettings.ListContentMargin.ToString() + "," + BottomMargin.ToString());
1605
1606 this.XmlOutput.WriteValue("✓");
1607 this.XmlOutput.WriteEndElement();
1608 }
1609
1610 this.XmlOutput.WriteStartElement("StackPanel");
1611 this.XmlOutput.WriteAttributeString("Grid.Column", "1");
1612 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
1613
1614 if (ParagraphBullet)
1615 await E.Render(this);
1616 else
1617 {
1618 this.XmlOutput.WriteStartElement("TextBlock");
1619 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1620 if (this.Alignment != TextAlignment.Left)
1621 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1622
1623 await E.Render(this);
1624
1625 this.XmlOutput.WriteEndElement();
1626 }
1627
1628 this.XmlOutput.WriteEndElement();
1629
1630 Row++;
1631 }
1632
1633 this.XmlOutput.WriteEndElement();
1634 }
1635
1640 public override Task Render(UnnumberedItem Element)
1641 {
1642 return this.RenderChild(Element);
1643 }
1644
1645 #endregion
1646
1647 }
1648}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:594
string ShortName
Emoji short name.
string Unicode
Unicode representation of emoji.
string Description
Short description of emoji.
Contains information about an emoji image.
Definition: ImageSource.cs:9
int? Width
Width of image, if available.
Definition: ImageSource.cs:18
Class that can be used to encapsulate Markdown to be returned from a Web Service, bypassing any encod...
Contains a markdown document. This markdown document class supports original markdown,...
static async Task< object > TransformXml(XmlDocument Xml, Variables Variables)
Transforms XML to an object that is easier to visualize.
string CheckURL(string Url, string URL)
Checks the URL if it needs redirection to a proxy.
IEnumerable< string > FootnoteOrder
Order of footnotes.
IEmojiSource EmojiSource
Source for emojis in the document.
MarkdownDocument Detail
Detail document of a master document.
Multimedia GetReference(string Label)
Gets the multimedia information referenced by a label.
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Contains settings that the Markdown parser uses to customize its behavior.
Represents a block quote in a markdown document.
Definition: BlockQuote.cs:11
Represents a bullet list in a markdown document.
Definition: BulletList.cs:11
Represents a center-aligned set of blocks in a markdown document.
Represents a code block in a markdown document.
Definition: CodeBlock.cs:16
Represents a comment block in a markdown document.
Definition: CommentBlock.cs:10
Represents a definition list in a markdown document.
Represents inserted blocks in a markdown document.
Definition: DeleteBlocks.cs:11
override Task Render(IRenderer Output)
Renders the element.
bool Referenced
If the Footnote has been referenced during rendering, and therefore needs to be shown at the end of t...
Definition: Footnote.cs:51
override bool InlineSpanElement
If the element is an inline span element.
Definition: Footnote.cs:90
Represents a header in a markdown document.
Definition: Header.cs:15
Represents a block of HTML in a markdown document.
Definition: HtmlBlock.cs:11
Represents inserted blocks in a markdown document.
Definition: InsertBlocks.cs:11
Represents a left-aligned set of blocks in a markdown document.
Definition: LeftAligned.cs:11
Represents a margin-aligned set of blocks in a markdown document.
Represents a nested block with no special formatting rules in a markdown document.
Definition: NestedBlock.cs:11
Represents a numbered item in an ordered list.
Definition: NumberedItem.cs:10
Represents a numbered list in a markdown document.
Definition: NumberedList.cs:11
Represents a paragraph in a markdown document.
Definition: Paragraph.cs:11
Represents a right-aligned set of blocks in a markdown document.
Definition: RightAligned.cs:11
Represents a sequence of sections.
Definition: Sections.cs:11
Represents a table in a markdown document.
Definition: Table.cs:11
TextAlignment[] ColumnAlignments
Table column alignments.
Definition: Table.cs:64
override IEnumerable< MarkdownElement > Children
Any children of the element.
Definition: Table.cs:100
MarkdownElement[][] Headers
Headers in table.
Definition: Table.cs:54
TextAlignment?[][] RowCellAlignments
Row cell alignments in table.
Definition: Table.cs:79
TextAlignment?[][] HeaderCellAlignments
Header cell alignments in table.
Definition: Table.cs:74
MarkdownElement[][] Rows
Rows in table.
Definition: Table.cs:59
Represents a task item in a task list.
Definition: TaskItem.cs:10
bool IsChecked
If the item is checked or not.
Definition: TaskItem.cs:31
Represents a task list in a markdown document.
Definition: TaskList.cs:11
Represents an unnumbered item in an ordered list.
override IEnumerable< MarkdownElement > Children
Any children of the element.
bool HasOneChild
If the element has only one child.
MarkdownElement FirstChild
First child, or null if none.
Abstract base class for all markdown elements.
abstract Task Render(IRenderer Output)
Renders the element.
virtual IEnumerable< MarkdownElement > Children
Any children of the element.
abstract bool InlineSpanElement
If the element is an inline span element.
virtual bool OutsideParagraph
If element, parsed as a span element, can stand outside of a paragraph if alone in it.
MarkdownDocument Document
Markdown document.
virtual BaselineAlignment BaselineAlignment
Baseline alignment
Abstract base class for all markdown elements with one child element.
string Delimiter
Delimiter string used to identify emoji.
int Level
Level (number of colons used to define the emoji)
bool AutoExpand
If the footnote should automatically be expanded when rendered, if format supports auto-expansion.
Represents an HTML entity in Unicode format.
bool AloneInParagraph
If the element is alone in a paragraph.
Definition: InlineScript.cs:55
async Task< object > EvaluateExpression()
Evaluates the script expression.
Definition: InlineScript.cs:71
bool TryGetMetaData(out KeyValuePair< string, bool >[] Values)
Tries to get meta-data from the document.
MultimediaItem[] Items
Multimedia items.
Definition: Multimedia.cs:40
bool AloneInParagraph
If the element is alone in a paragraph.
Abstract base class for Markdown renderers.
Definition: Renderer.cs:14
readonly StringBuilder Output
Renderer output.
Definition: Renderer.cs:18
Task RenderChild(MarkdownElementSingleChild Element)
Renders the child of Element .
Definition: Renderer.cs:175
async Task RenderChildren(MarkdownElementChildren Element)
Renders the children of Element .
Definition: Renderer.cs:147
MarkdownDocument Document
Reference to Markdown document being processed.
Definition: Renderer.cs:23
Renders XAML (WPF flavour) from a Markdown document.
override async Task Render(HtmlBlock Element)
Renders Element .
async Task RenderObject(object Result, bool AloneInParagraph, Variables Variables)
Generates WPF XAML from Script output.
override Task Render(InvisibleBreak Element)
Renders Element .
override async Task Render(Insert Element)
Renders Element .
override Task Render(SectionSeparator Element)
Renders Element .
override async Task RenderFootnotes()
Renders footnotes.
TextAlignment Alignment
Current text-alignment.
override void Dispose()
Disposes of the renderer.
override Task Render(HorizontalRule Element)
Renders Element .
override async Task Render(BulletList Element)
Renders Element .
override async Task Render(DefinitionTerms Element)
Renders Element .
WpfXamlRenderer(XmlWriterSettings XmlSettings)
Renders XAML (WPF flavour) from a Markdown document.
override async Task Render(CodeBlock Element)
Renders Element .
override Task Render(Sections Element)
Renders Element .
override async Task Render(SuperScript Element)
Renders Element .
WpfXamlRenderer(XamlSettings XamlSettings)
Renders XAML (WPF flavour) from a Markdown document.
override async Task Render(Table Element)
Renders Element .
override Task RenderDocumentHeader()
Renders the document header.
override Task Render(Link Element)
Renders Element .
WpfXamlRenderer()
Renders XAML (WPF flavour) from a Markdown document.
override async Task Render(Underline Element)
Renders Element .
override async Task Render(RightAligned Element)
Renders Element .
override async Task Render(BlockQuote Element)
Renders Element .
readonly XmlWriter XmlOutput
XML output
override async Task Render(StrikeThrough Element)
Renders Element .
WpfXamlRenderer(StringBuilder Output, XmlWriterSettings XmlSettings, XamlSettings XamlSettings)
Renders XAML (WPF flavour) from a Markdown document.
override Task Render(Footnote Element)
Renders Element .
override async Task Render(FootnoteReference Element)
Renders Element .
override async Task Render(InlineScript Element)
Renders Element .
override async Task Render(DeleteBlocks Element)
Renders Element .
override Task Render(LinkReference Element)
Renders Element .
override Task Render(MultimediaReference Element)
Renders Element .
override Task Render(Abbreviation Element)
Renders Element .
override Task Render(UnnumberedItem Element)
Renders Element .
override Task Render(Model.SpanElements.Multimedia Element)
Renders Element .
override Task Render(HashTag Element)
Renders Element .
override async Task Render(NestedBlock Element)
Renders Element .
override async Task Render(SubScript Element)
Renders Element .
readonly XamlSettings XamlSettings
XAML settings.
override async Task Render(CenterAligned Element)
Renders Element .
override Task Render(TaskItem Element)
Renders Element .
override Task Render(NumberedItem Element)
Renders Element .
async Task Render(string Url, string Title, IEnumerable< MarkdownElement > ChildNodes, MarkdownDocument Document)
Generates XAML for a link.
override async Task Render(TaskList Element)
Renders Element .
override Task Render(HtmlEntity Element)
Renders Element .
override Task Render(AutomaticLinkUrl Element)
Renders Element .
override Task Render(LineBreak Element)
Renders Element .
override async Task Render(Paragraph Element)
Renders Element .
override async Task Render(MarginAligned Element)
Renders Element .
override Task Render(MetaReference Element)
Renders Element .
override async Task Render(Emphasize Element)
Renders Element .
override Task RenderDocumentFooter()
Renders the document header.
override async Task Render(NumberedList Element)
Renders Element .
override Task Render(InlineCode Element)
Renders Element .
override async Task Render(InsertBlocks Element)
Renders Element .
override async Task Render(DefinitionDescriptions Element)
Renders Element .
override async Task Render(Delete Element)
Renders Element .
override Task Render(AutomaticLinkMail Element)
Renders Element .
override Task Render(InlineHTML Element)
Renders Element .
override Task Render(HtmlEntityUnicode Element)
Renders Element .
WpfXamlRenderer(XmlWriterSettings XmlSettings, XamlSettings XamlSettings)
Renders XAML (WPF flavour) from a Markdown document.
override Task Render(DefinitionList Element)
Renders Element .
override Task Render(InlineText Element)
Renders Element .
override async Task Render(LeftAligned Element)
Renders Element .
override async Task Render(EmojiReference Element)
Renders Element .
override async Task Render(Strong Element)
Renders Element .
override async Task Render(Header Element)
Renders Element .
override Task Render(DetailsReference Element)
Renders Element .
override Task Render(CommentBlock Element)
Renders Element .
override Task RenderDocument(MarkdownDocument Document, bool Inclusion)
Renders a document.
Contains settings that the XAML export uses to customize XAML output.
Definition: XamlSettings.cs:10
Helps with common XML-related tasks.
Definition: XML.cs:19
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Definition: Log.cs:818
Base class for graphs.
Definition: Graph.cs:79
Contains pixel information
virtual byte[] EncodeAsPng()
Encodes the pixels into a binary PNG image.
ToMatrix(ScriptNode Operand, bool NullCheck, int Start, int Length, Expression Expression)
To-Matrix operator.
Definition: ToMatrix.cs:22
Collection of variables.
Definition: Variables.cs:25
Interface for Emoji sources. Emoji sources provide emojis to content providers.
Definition: IEmojiSource.cs:12
Task< IImageSource > GetImageSource(EmojiInfo Emoji)
Gets the image source of an emoji.
bool EmojiSupported(EmojiInfo Emoji)
If the emoji is supported by the emoji source.
Contains information about an emoji image.
Definition: IImageSource.cs:9
Interface for code content WPF XAML renderers.
Interface for multimedia content WPF XAML renderers.
Interface for objects that can be converted into matrices.
Definition: IToMatrix.cs:9
TextAlignment
Text alignment of contents.
BaselineAlignment
Where baselign of horizontally organized elements are rendered.