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;
4using System.Text;
5using System.Threading.Tasks;
6using System.Xml;
13using 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
427 if (this.Alignment != TextAlignment.Left)
428 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
429
430 if (!string.IsNullOrEmpty(this.XamlSettings.CodeBlockBackgroundColor))
431 this.XmlOutput.WriteAttributeString("Background", this.XamlSettings.CodeBlockBackgroundColor);
432
433 this.XmlOutput.WriteValue(Element.Code);
434
435 this.XmlOutput.WriteEndElement();
436
437 return Task.CompletedTask;
438 }
439
444 public override Task Render(InlineHTML Element)
445 {
446 this.XmlOutput.WriteComment(Element.HTML);
447
448 return Task.CompletedTask;
449 }
450
455 public override async Task Render(InlineScript Element)
456 {
457 object Result = await Element.EvaluateExpression();
458 await this.RenderObject(Result, Element.AloneInParagraph, Element.Variables);
459 }
460
467 public async Task RenderObject(object Result, bool AloneInParagraph, Variables Variables)
468 {
469 if (Result is null)
470 return;
471
472 string s;
473
474 if (Result is XmlDocument Xml)
475 Result = await MarkdownDocument.TransformXml(Xml, Variables);
476 else if (Result is IToMatrix ToMatrix)
477 Result = ToMatrix.ToMatrix();
478
479 if (Result is Graph G)
480 {
481 PixelInformation Pixels = G.CreatePixels();
482 byte[] Bin = Pixels.EncodeAsPng();
483
484 s = "data:image/png;base64," + Convert.ToBase64String(Bin, 0, Bin.Length);
485
486 await Multimedia.ImageContent.OutputWpf(this.XmlOutput, new ImageSource()
487 {
488 Url = s,
489 Width = Pixels.Width,
490 Height = Pixels.Height
491 }, string.Empty);
492 }
493 else if (Result is SKImage Img)
494 {
495 using (SKData Data = Img.Encode(SKEncodedImageFormat.Png, 100))
496 {
497 byte[] Bin = Data.ToArray();
498
499 s = "data:image/png;base64," + Convert.ToBase64String(Bin, 0, Bin.Length);
500
501 await Multimedia.ImageContent.OutputWpf(this.XmlOutput, new ImageSource()
502 {
503 Url = s,
504 Width = Img.Width,
505 Height = Img.Height
506 }, string.Empty);
507 }
508 }
509 else if (Result is MarkdownDocument Doc)
510 {
511 await this.RenderDocument(Doc, true); // Does not call ProcessAsyncTasks()
512 Doc.ProcessAsyncTasks();
513 }
514 else if (Result is MarkdownContent Markdown)
515 {
516 Doc = await MarkdownDocument.CreateAsync(Markdown.Markdown, Markdown.Settings ?? new MarkdownSettings());
517 await this.RenderDocument(Doc, true); // Does not call ProcessAsyncTasks()
518 Doc.ProcessAsyncTasks();
519 }
520 else if (Result is Exception ex)
521 {
522 ex = Log.UnnestException(ex);
523
524 if (ex is AggregateException ex2)
525 {
526 foreach (Exception ex3 in ex2.InnerExceptions)
527 {
528 this.XmlOutput.WriteStartElement("TextBlock");
529 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
530 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
531
532 if (this.Alignment != TextAlignment.Left)
533 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
534
535 this.XmlOutput.WriteAttributeString("Foreground", "Red");
536 this.XmlOutput.WriteValue(ex3.Message);
537 this.XmlOutput.WriteEndElement();
538 }
539 }
540 else
541 {
542 if (AloneInParagraph)
543 {
544 this.XmlOutput.WriteStartElement("TextBlock");
545 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
546 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
547 if (this.Alignment != TextAlignment.Left)
548 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
549 }
550 else
551 this.XmlOutput.WriteStartElement("Run");
552
553 this.XmlOutput.WriteAttributeString("Foreground", "Red");
554 this.XmlOutput.WriteValue(ex.Message);
555 this.XmlOutput.WriteEndElement();
556 }
557 }
558 else
559 {
560 if (AloneInParagraph)
561 {
562 this.XmlOutput.WriteStartElement("TextBlock");
563 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
564 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
565 if (this.Alignment != TextAlignment.Left)
566 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
567 }
568
569 this.XmlOutput.WriteValue(Result.ToString());
570
571 if (AloneInParagraph)
572 this.XmlOutput.WriteEndElement();
573 }
574 }
575
580 public override Task Render(InlineText Element)
581 {
582 this.XmlOutput.WriteValue(Element.Value);
583
584 return Task.CompletedTask;
585 }
586
591 public override async Task Render(Insert Element)
592 {
593 this.XmlOutput.WriteStartElement("Underline");
594 await this.RenderChildren(Element);
595 this.XmlOutput.WriteEndElement();
596 }
597
602 public override Task Render(LineBreak Element)
603 {
604 this.XmlOutput.WriteElementString("LineBreak", string.Empty);
605
606 return Task.CompletedTask;
607 }
608
613 public override Task Render(Link Element)
614 {
615 return this.Render(Element.Url, Element.Title, Element.Children, Element.Document);
616 }
617
625 public async Task Render(string Url, string Title, ChunkedList<MarkdownElement> ChildNodes, MarkdownDocument Document)
626 {
627 this.XmlOutput.WriteStartElement("Hyperlink");
628 this.XmlOutput.WriteAttributeString("NavigateUri", Document.CheckURL(Url, null));
629
630 if (!string.IsNullOrEmpty(Title))
631 this.XmlOutput.WriteAttributeString("ToolTip", Title);
632
633 await this.Render(ChildNodes);
634
635 this.XmlOutput.WriteEndElement();
636 }
637
642 public override Task Render(LinkReference Element)
643 {
645
646 if (!(Multimedia is null))
647 return this.Render(Multimedia.Items[0].Url, Multimedia.Items[0].Title, Element.Children, Element.Document);
648 else
649 return this.RenderChildren(Element);
650 }
651
656 public override Task Render(MetaReference Element)
657 {
658 bool FirstOnRow = true;
659
660 if (Element.TryGetMetaData(out KeyValuePair<string, bool>[] Values))
661 {
662 foreach (KeyValuePair<string, bool> P in Values)
663 {
664 if (FirstOnRow)
665 FirstOnRow = false;
666 else
667 this.XmlOutput.WriteValue(' ');
668
669 this.XmlOutput.WriteValue(P.Key);
670 if (P.Value)
671 {
672 this.XmlOutput.WriteElementString("LineBreak", string.Empty);
673 FirstOnRow = true;
674 }
675 }
676 }
677
678 return Task.CompletedTask;
679 }
680
685 public override Task Render(Model.SpanElements.Multimedia Element)
686 {
688 if (Renderer is null)
689 return this.RenderChildren(Element);
690 else
691 return Renderer.RenderWpfXaml(this, Element.Items, Element.Children, Element.AloneInParagraph, Element.Document);
692 }
693
698 public override Task Render(MultimediaReference Element)
699 {
701
702 if (!(Multimedia is null))
703 {
705 if (!(Renderer is null))
706 return Renderer.RenderWpfXaml(this, Multimedia.Items, Element.Children, Element.AloneInParagraph, Element.Document);
707 }
708
709 return this.RenderChildren(Element);
710 }
711
716 public override async Task Render(StrikeThrough Element)
717 {
718 this.XmlOutput.WriteStartElement("TextBlock");
719 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
720 if (this.Alignment != TextAlignment.Left)
721 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
722
723 this.XmlOutput.WriteStartElement("TextBlock.TextDecorations");
724 this.XmlOutput.WriteStartElement("TextDecoration");
725 this.XmlOutput.WriteAttributeString("Location", "Strikethrough");
726 this.XmlOutput.WriteEndElement();
727 this.XmlOutput.WriteEndElement();
728
729 await this.RenderChildren(Element);
730
731 this.XmlOutput.WriteEndElement();
732 }
733
738 public override async Task Render(Strong Element)
739 {
740 this.XmlOutput.WriteStartElement("Bold");
741 await this.RenderChildren(Element);
742 this.XmlOutput.WriteEndElement();
743 }
744
749 public override async Task Render(SubScript Element)
750 {
751 this.XmlOutput.WriteStartElement("Run");
752 this.XmlOutput.WriteAttributeString("Typography.Variants", "Subscript");
753
754 await this.RenderChildren(Element);
755
756 this.XmlOutput.WriteEndElement();
757 }
758
763 public override async Task Render(SuperScript Element)
764 {
765 this.XmlOutput.WriteStartElement("Run");
766 this.XmlOutput.WriteAttributeString("Typography.Variants", "Superscript");
767
768 await this.RenderChildren(Element);
769
770 this.XmlOutput.WriteEndElement();
771 }
772
777 public override async Task Render(Underline Element)
778 {
779 this.XmlOutput.WriteStartElement("Underline");
780 await this.RenderChildren(Element);
781 this.XmlOutput.WriteEndElement();
782 }
783
784 #endregion
785
786 #region Block elements
787
792 public override async Task Render(BlockQuote Element)
793 {
794 this.XmlOutput.WriteStartElement("Border");
795 this.XmlOutput.WriteAttributeString("BorderThickness", this.XamlSettings.BlockQuoteBorderThickness.ToString() + ",0,0,0");
796 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.BlockQuoteMargin.ToString() + "," +
797 this.XamlSettings.ParagraphMarginTop.ToString() + ",0," + this.XamlSettings.ParagraphMarginBottom.ToString());
798 this.XmlOutput.WriteAttributeString("Padding", this.XamlSettings.BlockQuotePadding.ToString() + ",0,0,0");
799 this.XmlOutput.WriteAttributeString("BorderBrush", this.XamlSettings.BlockQuoteBorderColor);
800 this.XmlOutput.WriteStartElement("StackPanel");
801
802 await this.RenderChildren(Element);
803
804 this.XmlOutput.WriteEndElement();
805 this.XmlOutput.WriteEndElement();
806 }
807
812 public override async Task Render(BulletList Element)
813 {
814 int Row = 0;
815 bool ParagraphBullet;
816 int i, c;
817
818 this.XmlOutput.WriteStartElement("Grid");
819 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
820 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
821
822 this.XmlOutput.WriteStartElement("ColumnDefinition");
823 this.XmlOutput.WriteAttributeString("Width", "Auto");
824 this.XmlOutput.WriteEndElement();
825
826 this.XmlOutput.WriteStartElement("ColumnDefinition");
827 this.XmlOutput.WriteAttributeString("Width", "*");
828 this.XmlOutput.WriteEndElement();
829
830 this.XmlOutput.WriteEndElement();
831 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
832
833 for (i = 0, c = Element.Children.Count; i < c; i++)
834 {
835 this.XmlOutput.WriteStartElement("RowDefinition");
836 this.XmlOutput.WriteAttributeString("Height", "Auto");
837 this.XmlOutput.WriteEndElement();
838 }
839
840 this.XmlOutput.WriteEndElement();
841
844
845 while (!(Loop is null))
846 {
847 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
848 {
849 E = Loop[i];
850
851 ParagraphBullet = !E.InlineSpanElement || E.OutsideParagraph;
852 this.GetMargins(E, out int TopMargin, out int BottomMargin);
853
854 this.XmlOutput.WriteStartElement("TextBlock");
855 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
856 this.XmlOutput.WriteAttributeString("Grid.Column", "0");
857 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
858 if (this.Alignment != TextAlignment.Left)
859 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
860
861 this.XmlOutput.WriteAttributeString("Margin", "0," + TopMargin.ToString() + "," +
862 this.XamlSettings.ListContentMargin.ToString() + "," + BottomMargin.ToString());
863
864 this.XmlOutput.WriteValue("•");
865 this.XmlOutput.WriteEndElement();
866
867 this.XmlOutput.WriteStartElement("StackPanel");
868 this.XmlOutput.WriteAttributeString("Grid.Column", "1");
869 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
870
871 if (ParagraphBullet)
872 await E.Render(this);
873 else
874 {
875 this.XmlOutput.WriteStartElement("TextBlock");
876 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
877 if (this.Alignment != TextAlignment.Left)
878 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
879
880 await E.Render(this);
881
882 this.XmlOutput.WriteEndElement();
883 }
884
885 this.XmlOutput.WriteEndElement();
886
887 Row++;
888 }
889
890 Loop = Loop.Next;
891 }
892
893 this.XmlOutput.WriteEndElement();
894 }
895
902 private void GetMargins(MarkdownElement Element, out int TopMargin, out int BottomMargin)
903 {
904 if (Element.InlineSpanElement && !Element.OutsideParagraph)
905 {
906 TopMargin = 0;
907 BottomMargin = 0;
908 }
909 else if (Element is NestedBlock)
910 {
913 int i, c;
914 bool First = true;
915
916 TopMargin = BottomMargin = 0;
917
918 while (!(Loop is null))
919 {
920 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
921 {
922 E = Loop[i];
923
924 if (First)
925 {
926 First = false;
927 this.GetMargins(E, out TopMargin, out BottomMargin);
928 }
929 else
930 this.GetMargins(E, out int _, out BottomMargin);
931 }
932
933 Loop = Loop.Next;
934 }
935 }
936 else if (Element is MarkdownElementSingleChild SingleChild)
937 this.GetMargins(SingleChild.Child, out TopMargin, out BottomMargin);
938 else
939 {
940 TopMargin = this.XamlSettings.ParagraphMarginTop;
941 BottomMargin = this.XamlSettings.ParagraphMarginBottom;
942 }
943 }
944
949 public override async Task Render(CenterAligned Element)
950 {
951 this.XmlOutput.WriteStartElement("StackPanel");
952
953 TextAlignment Bak = this.Alignment;
954 this.Alignment = TextAlignment.Center;
955
956 await this.RenderChildren(Element);
957
958 this.Alignment = Bak;
959 this.XmlOutput.WriteEndElement();
960 }
961
966 public override async Task Render(CodeBlock Element)
967 {
969
970 if (!(Renderer is null))
971 {
972 try
973 {
974 if (await Renderer.RenderWpfXaml(this, Element.Rows, Element.Language, Element.Indent, Element.Document))
975 return;
976 }
977 catch (Exception ex)
978 {
979 ex = Log.UnnestException(ex);
980
981 if (ex is AggregateException ex2)
982 {
983 foreach (Exception ex3 in ex2.InnerExceptions)
984 {
985 this.XmlOutput.WriteStartElement("TextBlock");
986 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
987 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
988
989 if (this.Alignment != TextAlignment.Left)
990 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
991
992 this.XmlOutput.WriteAttributeString("Foreground", "Red");
993 this.XmlOutput.WriteValue(ex3.Message);
994 this.XmlOutput.WriteEndElement();
995 }
996 }
997 else
998 {
999 this.XmlOutput.WriteStartElement("TextBlock");
1000 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1001 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1002 if (this.Alignment != TextAlignment.Left)
1003 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1004
1005 this.XmlOutput.WriteAttributeString("Foreground", "Red");
1006 this.XmlOutput.WriteValue(ex.Message);
1007 this.XmlOutput.WriteEndElement();
1008 }
1009 }
1010 }
1011
1012 int i;
1013 bool First = true;
1014
1015 this.XmlOutput.WriteStartElement("TextBlock");
1016 this.XmlOutput.WriteAttributeString("xml", "space", null, "preserve");
1017 this.XmlOutput.WriteAttributeString("TextWrapping", "NoWrap");
1018 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1019 this.XmlOutput.WriteAttributeString("FontFamily", "Courier New");
1020
1021 if (this.Alignment != TextAlignment.Left)
1022 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1023
1024 if (!string.IsNullOrEmpty(this.XamlSettings.CodeBlockBackgroundColor))
1025 this.XmlOutput.WriteAttributeString("Background", this.XamlSettings.CodeBlockBackgroundColor);
1026
1027 for (i = Element.Start; i <= Element.End; i++)
1028 {
1029 if (First)
1030 First = false;
1031 else
1032 this.XmlOutput.WriteElementString("LineBreak", string.Empty);
1033
1034 this.XmlOutput.WriteValue(Element.Rows[i]);
1035 }
1036
1037 this.XmlOutput.WriteEndElement();
1038 }
1039
1044 public override Task Render(CommentBlock Element)
1045 {
1046 return Task.CompletedTask;
1047 }
1048
1053 public override async Task Render(DefinitionDescriptions Element)
1054 {
1055 MarkdownElement Last = Element.Children.HasLastItem ? Element.Children.LastItem : null;
1058 int i, c;
1059
1060 while (!(Loop is null))
1061 {
1062 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
1063 {
1064 E = Loop[i];
1065
1067 {
1068 this.XmlOutput.WriteStartElement("TextBlock");
1069 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1070 }
1071 else
1072 this.XmlOutput.WriteStartElement("StackPanel");
1073
1074 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.DefinitionMargin.ToString() + ",0,0," +
1075 (E == Last ? this.XamlSettings.DefinitionSeparator : 0).ToString());
1076
1077 await E.Render(this);
1078 this.XmlOutput.WriteEndElement();
1079 }
1080
1081 Loop = Loop.Next;
1082 }
1083 }
1084
1089 public override Task Render(DefinitionList Element)
1090 {
1091 return this.RenderChildren(Element);
1092 }
1093
1098 public override async Task Render(DefinitionTerms Element)
1099 {
1100 int TopMargin = this.XamlSettings.ParagraphMarginTop;
1102 int i, c;
1103
1104 while (!(Loop is null))
1105 {
1106 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
1107 {
1108 this.XmlOutput.WriteStartElement("TextBlock");
1109 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1110 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMarginLeft.ToString() + "," +
1111 TopMargin.ToString() + "," + this.XamlSettings.ParagraphMarginRight.ToString() + ",0");
1112 this.XmlOutput.WriteAttributeString("FontWeight", "Bold");
1113
1114 await Loop[i].Render(this);
1115
1116 this.XmlOutput.WriteEndElement();
1117 TopMargin = 0;
1118 }
1119
1120 Loop = Loop.Next;
1121 }
1122 }
1123
1128 public override async Task Render(DeleteBlocks Element)
1129 {
1130 this.XmlOutput.WriteStartElement("Border");
1131 this.XmlOutput.WriteAttributeString("BorderThickness", this.XamlSettings.BlockQuoteBorderThickness.ToString() + ",0,0,0");
1132 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.BlockQuoteMargin.ToString() + "," +
1133 this.XamlSettings.ParagraphMarginTop.ToString() + ",0," + this.XamlSettings.ParagraphMarginBottom.ToString());
1134 this.XmlOutput.WriteAttributeString("Padding", this.XamlSettings.BlockQuotePadding.ToString() + ",0,0,0");
1135 this.XmlOutput.WriteAttributeString("BorderBrush", this.XamlSettings.DeletedBlockQuoteBorderColor);
1136 this.XmlOutput.WriteStartElement("StackPanel");
1137
1138 await this.RenderChildren(Element);
1139
1140 this.XmlOutput.WriteEndElement();
1141 this.XmlOutput.WriteEndElement();
1142 }
1143
1148 public override Task Render(Footnote Element)
1149 {
1150 return this.RenderChildren(Element);
1151 }
1152
1157 public override async Task Render(Header Element)
1158 {
1159 this.XmlOutput.WriteStartElement("TextBlock");
1160 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1161 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1162 if (this.Alignment != TextAlignment.Left)
1163 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1164
1165 if (Element.Level > 0 && Element.Level <= this.XamlSettings.HeaderFontSize.Length)
1166 {
1167 this.XmlOutput.WriteAttributeString("FontSize", this.XamlSettings.HeaderFontSize[Element.Level - 1].ToString());
1168 this.XmlOutput.WriteAttributeString("Foreground", this.XamlSettings.HeaderForegroundColor[Element.Level - 1].ToString());
1169 }
1170
1171 await this.RenderChildren(Element);
1172
1173 this.XmlOutput.WriteEndElement();
1174 }
1175
1180 public override Task Render(HorizontalRule Element)
1181 {
1182 this.XmlOutput.WriteElementString("Separator", string.Empty);
1183
1184 return Task.CompletedTask;
1185 }
1186
1191 public override async Task Render(HtmlBlock Element)
1192 {
1193 this.XmlOutput.WriteStartElement("TextBlock");
1194 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1195 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1196 if (this.Alignment != TextAlignment.Left)
1197 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1198
1199 await this.RenderChildren(Element);
1200
1201 this.XmlOutput.WriteEndElement();
1202 }
1203
1208 public override async Task Render(InsertBlocks Element)
1209 {
1210 this.XmlOutput.WriteStartElement("Border");
1211 this.XmlOutput.WriteAttributeString("BorderThickness", this.XamlSettings.BlockQuoteBorderThickness.ToString() + ",0,0,0");
1212 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.BlockQuoteMargin.ToString() + "," +
1213 this.XamlSettings.ParagraphMarginTop.ToString() + ",0," + this.XamlSettings.ParagraphMarginBottom.ToString());
1214 this.XmlOutput.WriteAttributeString("Padding", this.XamlSettings.BlockQuotePadding.ToString() + ",0,0,0");
1215 this.XmlOutput.WriteAttributeString("BorderBrush", this.XamlSettings.InsertedBlockQuoteBorderColor);
1216 this.XmlOutput.WriteStartElement("StackPanel");
1217
1218 await this.RenderChildren(Element);
1219
1220 this.XmlOutput.WriteEndElement();
1221 this.XmlOutput.WriteEndElement();
1222 }
1223
1228 public override Task Render(InvisibleBreak Element)
1229 {
1230 return Task.CompletedTask;
1231 }
1232
1237 public override async Task Render(LeftAligned Element)
1238 {
1239 this.XmlOutput.WriteStartElement("StackPanel");
1240
1241 TextAlignment Bak = this.Alignment;
1242 this.Alignment = TextAlignment.Left;
1243
1244 await this.RenderChildren(Element);
1245
1246 this.Alignment = Bak;
1247 this.XmlOutput.WriteEndElement();
1248 }
1249
1254 public override async Task Render(MarginAligned Element)
1255 {
1256 this.XmlOutput.WriteStartElement("StackPanel");
1257
1258 TextAlignment Bak = this.Alignment;
1259 this.Alignment = TextAlignment.Left;
1260
1261 await this.RenderChildren(Element);
1262
1263 this.Alignment = Bak;
1264 this.XmlOutput.WriteEndElement();
1265 }
1266
1271 public override async Task Render(NestedBlock Element)
1272 {
1273 if (Element.HasOneChild)
1274 await Element.FirstChild.Render(this);
1275 else
1276 {
1277 bool SpanOpen = false;
1280 int i, c;
1281
1282 while (!(Loop is null))
1283 {
1284 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
1285 {
1286 E = Loop[i];
1287
1288 if (E.InlineSpanElement)
1289 {
1290 if (!SpanOpen)
1291 {
1292 this.XmlOutput.WriteStartElement("TextBlock");
1293 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1294 if (this.Alignment != TextAlignment.Left)
1295 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1296 SpanOpen = true;
1297 }
1298 }
1299 else if (SpanOpen)
1300 {
1301 this.XmlOutput.WriteEndElement();
1302 SpanOpen = false;
1303 }
1304
1305 await E.Render(this);
1306 }
1307
1308 Loop = Loop.Next;
1309 }
1310
1311 if (SpanOpen)
1312 this.XmlOutput.WriteEndElement();
1313 }
1314 }
1315
1320 public override Task Render(NumberedItem Element)
1321 {
1322 return this.RenderChild(Element);
1323 }
1324
1329 public override async Task Render(NumberedList Element)
1330 {
1331 NumberedItem Item;
1332 int Expected = 0;
1333 int Row = 0;
1334 bool ParagraphBullet;
1335 int i, c;
1336
1337 this.XmlOutput.WriteStartElement("Grid");
1338 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1339 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
1340
1341 this.XmlOutput.WriteStartElement("ColumnDefinition");
1342 this.XmlOutput.WriteAttributeString("Width", "Auto");
1343 this.XmlOutput.WriteEndElement();
1344
1345 this.XmlOutput.WriteStartElement("ColumnDefinition");
1346 this.XmlOutput.WriteAttributeString("Width", "*");
1347 this.XmlOutput.WriteEndElement();
1348
1349 this.XmlOutput.WriteEndElement();
1350 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
1351
1352 for (i = 0, c = Element.Children.Count; i < c; i++)
1353 {
1354 this.XmlOutput.WriteStartElement("RowDefinition");
1355 this.XmlOutput.WriteAttributeString("Height", "Auto");
1356 this.XmlOutput.WriteEndElement();
1357 }
1358
1359 this.XmlOutput.WriteEndElement();
1360
1363
1364 while (!(Loop is null))
1365 {
1366 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
1367 {
1368 E = Loop[i];
1369 Expected++;
1370 Item = E as NumberedItem;
1371
1372 ParagraphBullet = !E.InlineSpanElement || E.OutsideParagraph;
1373 this.GetMargins(E, out int TopMargin, out int BottomMargin);
1374
1375 this.XmlOutput.WriteStartElement("TextBlock");
1376 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1377 this.XmlOutput.WriteAttributeString("Grid.Column", "0");
1378 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
1379 if (this.Alignment != TextAlignment.Left)
1380 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1381
1382 this.XmlOutput.WriteAttributeString("Margin", "0," + TopMargin.ToString() + "," +
1383 this.XamlSettings.ListContentMargin.ToString() + "," + BottomMargin.ToString());
1384
1385 if (!(Item is null))
1386 this.XmlOutput.WriteValue((Expected = Item.Number).ToString());
1387 else
1388 this.XmlOutput.WriteValue(Expected.ToString());
1389
1390 this.XmlOutput.WriteValue(".");
1391 this.XmlOutput.WriteEndElement();
1392
1393 this.XmlOutput.WriteStartElement("StackPanel");
1394 this.XmlOutput.WriteAttributeString("Grid.Column", "1");
1395 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
1396
1397 if (ParagraphBullet)
1398 await E.Render(this);
1399 else
1400 {
1401 this.XmlOutput.WriteStartElement("TextBlock");
1402 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1403 if (this.Alignment != TextAlignment.Left)
1404 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1405
1406 await E.Render(this);
1407
1408 this.XmlOutput.WriteEndElement();
1409 }
1410
1411 this.XmlOutput.WriteEndElement();
1412
1413 Row++;
1414 }
1415
1416 Loop = Loop.Next;
1417 }
1418
1419 this.XmlOutput.WriteEndElement();
1420 }
1421
1426 public override async Task Render(Paragraph Element)
1427 {
1429
1430 this.XmlOutput.WriteStartElement("TextBlock");
1431 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1432 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1433 if (this.Alignment != TextAlignment.Left)
1434 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1435
1438 int i, c;
1439
1440 while (!(Loop is null))
1441 {
1442 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
1443 {
1444 E = Loop[i];
1445
1446 if ((!E.InlineSpanElement || E.OutsideParagraph) && (s = E.BaselineAlignment) != BaselineAlignment.Baseline)
1447 {
1448 this.XmlOutput.WriteStartElement("InlineUIContainer");
1449 this.XmlOutput.WriteAttributeString("BaselineAlignment", s.ToString());
1450
1451 await E.Render(this);
1452
1453 this.XmlOutput.WriteEndElement();
1454 }
1455 else
1456 await E.Render(this);
1457 }
1458
1459 Loop = Loop.Next;
1460 }
1461
1462 this.XmlOutput.WriteEndElement();
1463 }
1464
1469 public override async Task Render(RightAligned Element)
1470 {
1471 this.XmlOutput.WriteStartElement("StackPanel");
1472
1473 TextAlignment Bak = this.Alignment;
1474 this.Alignment = TextAlignment.Right;
1475
1476 await this.RenderChildren(Element);
1477
1478 this.Alignment = Bak;
1479 this.XmlOutput.WriteEndElement();
1480 }
1481
1486 public override Task Render(Sections Element)
1487 {
1488 return this.RenderChildren(Element);
1489 }
1490
1495 public override Task Render(SectionSeparator Element)
1496 {
1497 this.XmlOutput.WriteElementString("Separator", string.Empty);
1498
1499 return Task.CompletedTask;
1500 }
1501
1506 public override async Task Render(Table Element)
1507 {
1508 int Column;
1509 int Row, NrRows;
1510 int RowNr = 0;
1511 int NrColumns = Element.Columns;
1512
1513 this.XmlOutput.WriteStartElement("Grid");
1514 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1515 if (!string.IsNullOrEmpty(Element.Caption))
1516 this.XmlOutput.WriteAttributeString("ToolTip", Element.Caption);
1517
1518 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
1519
1520 for (Column = 0; Column < NrColumns; Column++)
1521 {
1522 this.XmlOutput.WriteStartElement("ColumnDefinition");
1523 this.XmlOutput.WriteAttributeString("Width", "Auto");
1524 this.XmlOutput.WriteEndElement();
1525 }
1526
1527 this.XmlOutput.WriteEndElement();
1528 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
1529
1530 for (Row = 0, NrRows = Element.Rows.Length + Element.Headers.Length; Row < NrRows; Row++)
1531 {
1532 this.XmlOutput.WriteStartElement("RowDefinition");
1533 this.XmlOutput.WriteAttributeString("Height", "Auto");
1534 this.XmlOutput.WriteEndElement();
1535 }
1536
1537 this.XmlOutput.WriteEndElement();
1538
1539 for (Row = 0, NrRows = Element.Headers.Length; Row < NrRows; Row++, RowNr++)
1540 await this.Render(Element.Headers[Row], Element.HeaderCellAlignments[Row], RowNr, true, Element);
1541
1542 for (Row = 0, NrRows = Element.Rows.Length; Row < NrRows; Row++, RowNr++)
1543 await this.Render(Element.Rows[Row], Element.RowCellAlignments[Row], RowNr, false, Element);
1544
1545 this.XmlOutput.WriteEndElement();
1546 }
1547
1548 private async Task Render(MarkdownElement[] CurrentRow, TextAlignment?[] CellAlignments, int RowNr, bool Bold, Table Element)
1549 {
1550 TextAlignment Bak = this.Alignment;
1552 int NrColumns = Element.Columns;
1553 int Column;
1554 int ColSpan;
1555
1556 for (Column = 0; Column < NrColumns; Column++)
1557 {
1558 E = CurrentRow[Column];
1559 if (E is null)
1560 continue;
1561
1562 this.Alignment = CellAlignments[Column] ?? Element.ColumnAlignments[Column];
1563 ColSpan = Column + 1;
1564 while (ColSpan < NrColumns && CurrentRow[ColSpan] is null)
1565 ColSpan++;
1566
1567 ColSpan -= Column;
1568
1569 this.XmlOutput.WriteStartElement("Border");
1570 this.XmlOutput.WriteAttributeString("BorderBrush", this.XamlSettings.TableCellBorderColor);
1571 this.XmlOutput.WriteAttributeString("BorderThickness", CommonTypes.Encode(this.XamlSettings.TableCellBorderThickness));
1572
1573 if ((RowNr & 1) == 0)
1574 {
1575 if (!string.IsNullOrEmpty(this.XamlSettings.TableCellRowBackgroundColor1))
1576 this.XmlOutput.WriteAttributeString("Background", this.XamlSettings.TableCellRowBackgroundColor1);
1577 }
1578 else
1579 {
1580 if (!string.IsNullOrEmpty(this.XamlSettings.TableCellRowBackgroundColor2))
1581 this.XmlOutput.WriteAttributeString("Background", this.XamlSettings.TableCellRowBackgroundColor2);
1582 }
1583
1584 this.XmlOutput.WriteAttributeString("Grid.Column", Column.ToString());
1585 this.XmlOutput.WriteAttributeString("Grid.Row", RowNr.ToString());
1586
1587 if (ColSpan > 1)
1588 this.XmlOutput.WriteAttributeString("Grid.ColumnSpan", ColSpan.ToString());
1589
1590 if (E.InlineSpanElement)
1591 {
1592 this.XmlOutput.WriteStartElement("TextBlock");
1593 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1594 this.XmlOutput.WriteAttributeString("Padding", this.XamlSettings.TableCellPadding);
1595
1596 if (Bold)
1597 this.XmlOutput.WriteAttributeString("FontWeight", "Bold");
1598
1599 if (this.Alignment != TextAlignment.Left)
1600 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1601 }
1602 else
1603 {
1604 this.XmlOutput.WriteStartElement("StackPanel");
1605 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.TableCellPadding);
1606 }
1607
1608 await E.Render(this);
1609 this.XmlOutput.WriteEndElement();
1610 this.XmlOutput.WriteEndElement();
1611 }
1612
1613 this.Alignment = Bak;
1614 }
1615
1620 public override Task Render(TaskItem Element)
1621 {
1622 return this.RenderChild(Element);
1623 }
1624
1629 public override async Task Render(TaskList Element)
1630 {
1631 int Row = 0;
1632 bool ParagraphBullet;
1633 int i, c;
1634
1635 this.XmlOutput.WriteStartElement("Grid");
1636 this.XmlOutput.WriteAttributeString("Margin", this.XamlSettings.ParagraphMargins);
1637 this.XmlOutput.WriteStartElement("Grid.ColumnDefinitions");
1638
1639 this.XmlOutput.WriteStartElement("ColumnDefinition");
1640 this.XmlOutput.WriteAttributeString("Width", "Auto");
1641 this.XmlOutput.WriteEndElement();
1642
1643 this.XmlOutput.WriteStartElement("ColumnDefinition");
1644 this.XmlOutput.WriteAttributeString("Width", "*");
1645 this.XmlOutput.WriteEndElement();
1646
1647 this.XmlOutput.WriteEndElement();
1648 this.XmlOutput.WriteStartElement("Grid.RowDefinitions");
1649
1650 for (i = 0, c = Element.Children.Count; i < c; i++)
1651 {
1652 this.XmlOutput.WriteStartElement("RowDefinition");
1653 this.XmlOutput.WriteAttributeString("Height", "Auto");
1654 this.XmlOutput.WriteEndElement();
1655 }
1656
1657 this.XmlOutput.WriteEndElement();
1658
1661
1662 while (!(Loop is null))
1663 {
1664 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
1665 {
1666 E = Loop[i];
1667
1668 ParagraphBullet = !E.InlineSpanElement || E.OutsideParagraph;
1669 this.GetMargins(E, out int TopMargin, out int BottomMargin);
1670
1671 if (E is TaskItem TaskItem && TaskItem.IsChecked)
1672 {
1673 this.XmlOutput.WriteStartElement("TextBlock");
1674 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1675 this.XmlOutput.WriteAttributeString("Grid.Column", "0");
1676 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
1677 if (this.Alignment != TextAlignment.Left)
1678 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1679
1680 this.XmlOutput.WriteAttributeString("Margin", "0," + TopMargin.ToString() + "," +
1681 this.XamlSettings.ListContentMargin.ToString() + "," + BottomMargin.ToString());
1682
1683 this.XmlOutput.WriteValue("✓");
1684 this.XmlOutput.WriteEndElement();
1685 }
1686
1687 this.XmlOutput.WriteStartElement("StackPanel");
1688 this.XmlOutput.WriteAttributeString("Grid.Column", "1");
1689 this.XmlOutput.WriteAttributeString("Grid.Row", Row.ToString());
1690
1691 if (ParagraphBullet)
1692 await E.Render(this);
1693 else
1694 {
1695 this.XmlOutput.WriteStartElement("TextBlock");
1696 this.XmlOutput.WriteAttributeString("TextWrapping", "Wrap");
1697 if (this.Alignment != TextAlignment.Left)
1698 this.XmlOutput.WriteAttributeString("TextAlignment", this.Alignment.ToString());
1699
1700 await E.Render(this);
1701
1702 this.XmlOutput.WriteEndElement();
1703 }
1704
1705 this.XmlOutput.WriteEndElement();
1706
1707 Row++;
1708 }
1709
1710 Loop = Loop.Next;
1711 }
1712
1713 this.XmlOutput.WriteEndElement();
1714 }
1715
1720 public override Task Render(UnnumberedItem Element)
1721 {
1722 return this.RenderChild(Element);
1723 }
1724
1725 #endregion
1726
1727 }
1728}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:15
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:596
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:7
int? Width
Width of image, if available.
Definition: ImageSource.cs:16
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:17
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:12
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:65
MarkdownElement[][] Headers
Headers in table.
Definition: Table.cs:55
TextAlignment?[][] RowCellAlignments
Row cell alignments in table.
Definition: Table.cs:80
TextAlignment?[][] HeaderCellAlignments
Header cell alignments in table.
Definition: Table.cs:75
MarkdownElement[][] Rows
Rows in table.
Definition: Table.cs:60
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 ChunkedList< 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.
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.
virtual ChunkedList< MarkdownElement > Children
Any children of the element.
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:41
bool AloneInParagraph
If the element is alone in a paragraph.
Abstract base class for Markdown renderers.
Definition: Renderer.cs:15
readonly StringBuilder Output
Renderer output.
Definition: Renderer.cs:19
Task RenderChild(MarkdownElementSingleChild Element)
Renders the child of Element .
Definition: Renderer.cs:178
Task RenderChildren(MarkdownElementChildren Element)
Renders the children of Element .
Definition: Renderer.cs:147
MarkdownDocument Document
Reference to Markdown document being processed.
Definition: Renderer.cs:24
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 .
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 .
async Task Render(string Url, string Title, ChunkedList< MarkdownElement > ChildNodes, MarkdownDocument Document)
Generates XAML for a link.
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:21
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Definition: Log.cs:828
Node referencing a chunk in a ChunkedList<T>
Definition: ChunkNode.cs:11
ChunkNode< T > Next
Next chunk
Definition: ChunkNode.cs:26
int Pos
Index after the last element in chunk.
Definition: ChunkNode.cs:51
int Start
Index of first element in chunk.
Definition: ChunkNode.cs:46
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
ChunkNode< T > FirstChunk
First chunk
Definition: ChunkedList.cs:259
int Count
Number of elements in collection.
Definition: ChunkedList.cs:68
Base class for graphs.
Definition: Graph.cs:88
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:10
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:7
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
Definition: ImplTypes.g.cs:58
TextAlignment
Text alignment of contents.
BaselineAlignment
Where baselign of horizontally organized elements are rendered.