2using System.Globalization;
88 this.XmlOutput = XmlWriter.Create(this.
Output, XmlSettings);
99 this.XmlOutput = XmlWriter.Create(this.Output, XmlSettings);
106 GC.SuppressFinalize(
this);
109 private bool isDisposed;
114 protected virtual void Dispose(
bool disposing)
122 this.XmlOutput.Dispose();
125 this.isDisposed =
true;
138 this.StrikeThrough =
false;
139 this.Underline =
false;
140 this.Superscript =
false;
141 this.Subscript =
false;
143 this.InLabel =
false;
144 this.Hyperlink =
null;
146 return base.RenderDocument(
Document, Inclusion);
154 this.XmlOutput.WriteStartElement(
"VerticalStackLayout",
"http://schemas.microsoft.com/dotnet/2021/maui");
155 this.XmlOutput.WriteAttributeString(
"xmlns",
"x",
null,
"http://schemas.microsoft.com/winfx/2009/xaml");
156 this.XmlOutput.WriteAttributeString(
"xmlns",
"ui",
null,
"clr-namespace:NeuroAccessMaui.UI");
157 this.XmlOutput.WriteAttributeString(
"Spacing",
"0");
159 return Task.CompletedTask;
171 this.XmlOutput.WriteStartElement(
"BoxView");
172 this.XmlOutput.WriteAttributeString(
"HeightRequest",
"1");
173 this.XmlOutput.WriteAttributeString(
"BackgroundColor",
"{AppThemeBinding Light={StaticResource NormalEditPlaceholderLight}, Dark={StaticResource NormalEditPlaceholderDark}}");
174 this.XmlOutput.WriteAttributeString(
"HorizontalOptions",
"FillAndExpand");
175 this.XmlOutput.WriteAttributeString(
"Margin", SmallMargins(
false,
false,
true,
true));
176 this.XmlOutput.WriteEndElement();
178 this.XmlOutput.WriteStartElement(
"Grid");
179 this.XmlOutput.WriteAttributeString(
"RowSpacing",
"0");
180 this.XmlOutput.WriteAttributeString(
"ColumnSpacing",
"0");
182 this.XmlOutput.WriteStartElement(
"Grid.ColumnDefinitions");
184 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
185 this.XmlOutput.WriteAttributeString(
"Width",
"Auto");
186 this.XmlOutput.WriteEndElement();
188 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
189 this.XmlOutput.WriteAttributeString(
"Width",
"*");
190 this.XmlOutput.WriteEndElement();
192 this.XmlOutput.WriteEndElement();
193 this.XmlOutput.WriteStartElement(
"Grid.RowDefinitions");
197 if ((this.
Document?.TryGetFootnoteNumber(Key, out Nr) ??
false) &&
201 this.XmlOutput.WriteStartElement(
"RowDefinition");
202 this.XmlOutput.WriteAttributeString(
"Height",
"Auto");
203 this.XmlOutput.WriteEndElement();
207 this.XmlOutput.WriteEndElement();
213 if ((this.
Document?.TryGetFootnoteNumber(Key, out Nr) ??
false) &&
217 this.XmlOutput.WriteStartElement(
"ContentView");
218 this.XmlOutput.WriteAttributeString(
"Margin",
"{StaticResource SmallMargins}");
219 this.XmlOutput.WriteAttributeString(
"Grid.Column",
"0");
220 this.XmlOutput.WriteAttributeString(
"Grid.Row", Row.ToString(CultureInfo.InvariantCulture));
221 this.XmlOutput.WriteAttributeString(
"Scale",
"0.75");
222 this.XmlOutput.WriteAttributeString(
"TranslationY",
"-5");
224 this.XmlOutput.WriteStartElement(
"Label");
225 this.XmlOutput.WriteAttributeString(
"Text", Nr.ToString(CultureInfo.InvariantCulture));
226 this.XmlOutput.WriteEndElement();
227 this.XmlOutput.WriteEndElement();
229 this.XmlOutput.WriteStartElement(
"ContentView");
230 this.XmlOutput.WriteAttributeString(
"Grid.Column",
"1");
231 this.XmlOutput.WriteAttributeString(
"Grid.Row", Row.ToString(CultureInfo.InvariantCulture));
233 this.XmlOutput.WriteEndElement();
240 this.XmlOutput.WriteEndElement();
248 this.XmlOutput.WriteEndElement();
249 this.XmlOutput.Flush();
251 return Task.CompletedTask;
254 #region Span Elements
272 this.Hyperlink =
"mailto:" + Element.
EMail;
273 this.RenderSpan(this.Hyperlink);
274 this.Hyperlink = Bak;
276 return Task.CompletedTask;
286 this.Hyperlink = Element.
URL;
287 this.RenderSpan(Element.
URL);
288 this.Hyperlink = Bak;
290 return Task.CompletedTask;
300 this.StrikeThrough =
true;
304 this.StrikeThrough = Bak;
331 if (EmojiSource is
null)
338 await
Multimedia.ImageContent.OutputMauiXaml(this.XmlOutput, Source);
367 await this.
Render(Footnote);
368 else if (this.
Document?.TryGetFootnoteNumber(Element.
Key, out
int Nr) ??
false)
371 this.Superscript =
true;
373 this.RenderSpan(Nr.ToString(CultureInfo.InvariantCulture));
375 this.Superscript = Bak;
378 Footnote.Referenced =
true;
388 this.RenderSpan(Element.
Tag);
389 return Task.CompletedTask;
399 if (!
string.IsNullOrEmpty(s))
402 return Task.CompletedTask;
411 this.RenderSpan(
new string((
char)Element.
Code, 1));
412 return Task.CompletedTask;
421 bool Bak = this.
Code;
424 this.RenderSpan(Element.
Code);
428 return Task.CompletedTask;
437 this.XmlOutput.WriteComment(Element.
HTML);
438 return Task.CompletedTask;
464 if (Result is XmlDocument Xml)
471 s = Result?.ToString();
472 if (!
string.IsNullOrEmpty(s))
473 this.RenderSpan(Result?.
ToString() ??
string.Empty);
478 if (Result is
Graph G)
483 s =
"data:image/png;base64," + Convert.ToBase64String(Bin, 0, Bin.Length);
488 Width = Pixels.Width,
489 Height = Pixels.Height
492 else if (Result is SKImage Img)
494 using SKData Data = Img.Encode(SKEncodedImageFormat.Png, 100);
495 byte[] Bin = Data.ToArray();
497 s =
"data:image/png;base64," + Convert.ToBase64String(Bin, 0, Bin.Length);
509 Doc.ProcessAsyncTasks();
515 Doc.ProcessAsyncTasks();
517 else if (Result is Exception ex)
521 if (ex is AggregateException ex2)
523 foreach (Exception ex3
in ex2.InnerExceptions)
525 this.RenderContentView();
526 this.XmlOutput.WriteStartElement(
"Label");
527 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
528 this.XmlOutput.WriteAttributeString(
"TextColor",
"Red");
529 this.XmlOutput.WriteValue(ex3.Message);
530 this.XmlOutput.WriteEndElement();
531 this.XmlOutput.WriteEndElement();
536 if (AloneInParagraph)
537 this.RenderContentView();
539 this.XmlOutput.WriteStartElement(
"Label");
540 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
541 this.XmlOutput.WriteAttributeString(
"TextColor",
"Red");
542 this.XmlOutput.WriteValue(ex.Message);
543 this.XmlOutput.WriteEndElement();
545 if (AloneInParagraph)
546 this.XmlOutput.WriteEndElement();
551 if (AloneInParagraph)
552 this.RenderContentView();
554 this.XmlOutput.WriteStartElement(
"Label");
555 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
558 this.XmlOutput.WriteValue(Result.ToString());
559 this.XmlOutput.WriteEndElement();
561 if (AloneInParagraph)
562 this.XmlOutput.WriteEndElement();
572 this.RenderSpan(Element.
Value);
573 return Task.CompletedTask;
583 this.Underline =
true;
587 this.Underline = Bak;
596 this.RenderSpan(Environment.NewLine);
597 return Task.CompletedTask;
607 this.Hyperlink = Element.
Url;
611 this.Hyperlink = Bak;
624 if (Multimedia is not
null)
629 this.Hyperlink = Bak;
638 StringBuilder sb =
new();
639 bool FirstOnRow =
true;
641 if (Element.
TryGetMetaData(out KeyValuePair<string, bool>[] Values))
643 foreach (KeyValuePair<string, bool> P
in Values)
653 sb.Append(Environment.NewLine);
659 this.RenderSpan(sb.ToString());
661 return Task.CompletedTask;
674 return Renderer.RenderMauiXaml(
this, Element.Items, Element.Children, Element.AloneInParagraph, Element.Document);
702 this.StrikeThrough =
true;
706 this.StrikeThrough = Bak;
715 bool Bak = this.
Bold;
730 this.Subscript =
true;
734 this.Subscript = Bak;
744 this.Superscript =
true;
748 this.Superscript = Bak;
758 this.Underline =
true;
762 this.Underline = Bak;
767 #region Block elements
775 this.XmlOutput.WriteStartElement(
"ContentView");
776 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
true,
false,
true,
true));
778 this.XmlOutput.WriteStartElement(
"Frame");
779 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
true,
true,
false,
false));
780 this.XmlOutput.WriteAttributeString(
"BorderColor",
"{AppThemeBinding Light={StaticResource PrimaryForegroundLight}, Dark={StaticResource PrimaryForegroundDark}}");
783 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
787 this.XmlOutput.WriteEndElement();
788 this.XmlOutput.WriteEndElement();
789 this.XmlOutput.WriteEndElement();
799 bool ParagraphBullet;
801 this.XmlOutput.WriteStartElement(
"ContentView");
802 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
false,
false,
true,
true));
804 this.XmlOutput.WriteStartElement(
"Grid");
805 this.XmlOutput.WriteAttributeString(
"RowSpacing",
"0");
806 this.XmlOutput.WriteAttributeString(
"ColumnSpacing",
"0");
808 this.XmlOutput.WriteStartElement(
"Grid.ColumnDefinitions");
810 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
811 this.XmlOutput.WriteAttributeString(
"Width",
"Auto");
812 this.XmlOutput.WriteEndElement();
814 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
815 this.XmlOutput.WriteAttributeString(
"Width",
"*");
816 this.XmlOutput.WriteEndElement();
818 this.XmlOutput.WriteEndElement();
819 this.XmlOutput.WriteStartElement(
"Grid.RowDefinitions");
823 this.XmlOutput.WriteStartElement(
"RowDefinition");
824 this.XmlOutput.WriteAttributeString(
"Height",
"Auto");
825 this.XmlOutput.WriteEndElement();
828 this.XmlOutput.WriteEndElement();
835 GetMargins(E, out
bool TopMargin, out
bool BottomMargin);
837 this.RenderContentView(SmallMargins(
false,
true, TopMargin, BottomMargin));
839 this.XmlOutput.WriteAttributeString(
"Grid.Column",
"0");
840 this.XmlOutput.WriteAttributeString(
"Grid.Row", Row.ToString(CultureInfo.InvariantCulture));
842 this.XmlOutput.WriteElementString(
"Label",
"•");
843 this.XmlOutput.WriteEndElement();
845 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
846 this.XmlOutput.WriteAttributeString(
"Grid.Column",
"1");
847 this.XmlOutput.WriteAttributeString(
"Grid.Row", Row.ToString(CultureInfo.InvariantCulture));
852 await this.RenderLabel(Item,
false);
854 this.XmlOutput.WriteEndElement();
860 this.XmlOutput.WriteEndElement();
861 this.XmlOutput.WriteEndElement();
864 private static string SmallMargins(
bool Left,
bool Right,
bool Top,
bool Bottom)
866 StringBuilder sb =
new();
868 sb.Append(
"{StaticResource ");
870 if (!(Left || Right || Top || Bottom))
876 if (!(Left && Right && Top && Bottom))
892 sb.Append(
"Margins}");
894 return sb.ToString();
903 private static void GetMargins(
MarkdownElement Element, out
bool TopMargin, out
bool BottomMargin)
908 BottomMargin =
false;
914 TopMargin = BottomMargin =
false;
921 GetMargins(E, out TopMargin, out BottomMargin);
924 GetMargins(E, out
bool _, out BottomMargin);
928 GetMargins(SingleChild.Child, out TopMargin, out BottomMargin);
942 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
949 this.Alignment = Bak;
950 this.XmlOutput.WriteEndElement();
972 if (ex is AggregateException ex2)
974 foreach (Exception ex3
in ex2.InnerExceptions)
976 this.RenderContentView();
977 this.XmlOutput.WriteStartElement(
"Label");
978 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
979 this.XmlOutput.WriteAttributeString(
"TextColor",
"Red");
980 this.XmlOutput.WriteValue(ex3.Message);
981 this.XmlOutput.WriteEndElement();
982 this.XmlOutput.WriteEndElement();
987 this.RenderContentView();
988 this.XmlOutput.WriteStartElement(
"Label");
989 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
990 this.XmlOutput.WriteAttributeString(
"TextColor",
"Red");
991 this.XmlOutput.WriteValue(ex.Message);
992 this.XmlOutput.WriteEndElement();
993 this.XmlOutput.WriteEndElement();
998 this.RenderContentView();
999 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1003 for (i = Element.
Start; i <= Element.
End; i++)
1005 this.XmlOutput.WriteStartElement(
"Label");
1006 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"NoWrap");
1008 this.XmlOutput.WriteAttributeString(
"FontFamily",
"Courier New");
1009 this.XmlOutput.WriteAttributeString(
"Text", Element.
Rows[i]);
1010 this.XmlOutput.WriteEndElement();
1013 this.XmlOutput.WriteEndElement();
1014 this.XmlOutput.WriteEndElement();
1023 return Task.CompletedTask;
1041 this.RenderContentView();
1043 this.XmlOutput.WriteStartElement(
"Label");
1044 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
1046 this.XmlOutput.WriteAttributeString(
"TextType",
"Html");
1050 XmlEntitiesOnly =
true
1057 this.XmlOutput.WriteEndElement();
1058 this.XmlOutput.WriteEndElement();
1062 this.XmlOutput.WriteStartElement(
"ContentView");
1063 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
true,
false,
false, Description == Last));
1065 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1066 await Description.
Render(
this);
1067 this.XmlOutput.WriteEndElement();
1069 this.XmlOutput.WriteEndElement();
1093 this.RenderContentView(SmallMargins(
true,
true, Top,
false));
1095 bool BoldBak = this.
Bold;
1098 await this.RenderLabel(Term,
true);
1100 this.Bold = BoldBak;
1101 this.XmlOutput.WriteEndElement();
1113 this.XmlOutput.WriteStartElement(
"ContentView");
1114 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
true,
false,
true,
true));
1116 this.XmlOutput.WriteStartElement(
"Frame");
1117 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
true,
true,
false,
false));
1118 this.XmlOutput.WriteAttributeString(
"BorderColor",
"{AppThemeBinding Light={StaticResource DeletedBorderLight}, Dark={StaticResource DeletedBorderDark}}");
1121 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1126 this.XmlOutput.WriteEndElement();
1127 this.XmlOutput.WriteEndElement();
1128 this.XmlOutput.WriteEndElement();
1146 this.RenderContentView();
1148 int Level = Math.Max(0, Math.Min(9, Element.
Level));
1150 this.XmlOutput.WriteStartElement(
"Label");
1151 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
1152 this.XmlOutput.WriteAttributeString(
"Style",
"{StaticResource Header" + Level.ToString(CultureInfo.InvariantCulture) +
"}");
1155 this.XmlOutput.WriteAttributeString(
"TextType",
"Html");
1159 XmlEntitiesOnly =
true
1167 this.XmlOutput.WriteEndElement();
1168 this.XmlOutput.WriteEndElement();
1176 switch (this.Alignment)
1179 this.XmlOutput.WriteAttributeString(
"HorizontalTextAlignment",
"Start");
1183 this.XmlOutput.WriteAttributeString(
"HorizontalTextAlignment",
"End");
1187 this.XmlOutput.WriteAttributeString(
"HorizontalTextAlignment",
"Center");
1198 this.XmlOutput.WriteStartElement(
"BoxView");
1199 this.XmlOutput.WriteAttributeString(
"HeightRequest",
"1");
1200 this.XmlOutput.WriteAttributeString(
"BackgroundColor",
"{AppThemeBinding Light={StaticResource NormalEditPlaceholderLight}, Dark={StaticResource NormalEditPlaceholderDark}}");
1201 this.XmlOutput.WriteAttributeString(
"HorizontalOptions",
"FillAndExpand");
1202 this.XmlOutput.WriteAttributeString(
"Margin", SmallMargins(
false,
false,
true,
true));
1203 this.XmlOutput.WriteEndElement();
1205 return Task.CompletedTask;
1214 this.RenderContentView();
1216 this.XmlOutput.WriteStartElement(
"Label");
1217 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
1219 this.XmlOutput.WriteAttributeString(
"TextType",
"Html");
1223 XmlEntitiesOnly =
true
1230 this.XmlOutput.WriteEndElement();
1231 this.XmlOutput.WriteEndElement();
1240 this.XmlOutput.WriteStartElement(
"ContentView");
1241 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
true,
false,
true,
true));
1243 this.XmlOutput.WriteStartElement(
"Frame");
1244 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
true,
true,
false,
false));
1245 this.XmlOutput.WriteAttributeString(
"BorderColor",
"{AppThemeBinding Light={StaticResource InsertedBorderLight}, Dark={StaticResource InsertedBorderDark}}");
1248 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1252 this.XmlOutput.WriteEndElement();
1253 this.XmlOutput.WriteEndElement();
1254 this.XmlOutput.WriteEndElement();
1263 return Task.CompletedTask;
1272 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1279 this.Alignment = Bak;
1280 this.XmlOutput.WriteEndElement();
1289 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1296 this.Alignment = Bak;
1297 this.XmlOutput.WriteEndElement();
1312 XmlEntitiesOnly =
true
1327 if (Html is not
null)
1329 this.XmlOutput.WriteStartElement(
"Label");
1330 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
1332 this.XmlOutput.WriteAttributeString(
"TextType",
"Html");
1333 this.XmlOutput.WriteCData(Html.
ToString());
1334 this.XmlOutput.WriteEndElement();
1344 if (Html is not
null)
1346 this.XmlOutput.WriteStartElement(
"Label");
1347 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
1349 this.XmlOutput.WriteAttributeString(
"TextType",
"Html");
1350 this.XmlOutput.WriteCData(Html.
ToString());
1351 this.XmlOutput.WriteEndElement();
1378 bool ParagraphBullet;
1380 this.XmlOutput.WriteStartElement(
"ContentView");
1381 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
false,
false,
true,
true));
1383 this.XmlOutput.WriteStartElement(
"Grid");
1384 this.XmlOutput.WriteAttributeString(
"RowSpacing",
"0");
1385 this.XmlOutput.WriteAttributeString(
"ColumnSpacing",
"0");
1387 this.XmlOutput.WriteStartElement(
"Grid.ColumnDefinitions");
1389 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
1390 this.XmlOutput.WriteAttributeString(
"Width",
"Auto");
1391 this.XmlOutput.WriteEndElement();
1393 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
1394 this.XmlOutput.WriteAttributeString(
"Width",
"*");
1395 this.XmlOutput.WriteEndElement();
1397 this.XmlOutput.WriteEndElement();
1398 this.XmlOutput.WriteStartElement(
"Grid.RowDefinitions");
1402 this.XmlOutput.WriteStartElement(
"RowDefinition");
1403 this.XmlOutput.WriteAttributeString(
"Height",
"Auto");
1404 this.XmlOutput.WriteEndElement();
1407 this.XmlOutput.WriteEndElement();
1416 GetMargins(E, out
bool TopMargin, out
bool BottomMargin);
1418 this.RenderContentView(SmallMargins(
false,
true, TopMargin, BottomMargin));
1419 this.XmlOutput.WriteAttributeString(
"Grid.Column",
"0");
1420 this.XmlOutput.WriteAttributeString(
"Grid.Row", Row.ToString(CultureInfo.InvariantCulture));
1422 this.XmlOutput.WriteStartElement(
"Label");
1425 this.XmlOutput.WriteValue((Expected =
NumberedItem.
Number).ToString(CultureInfo.InvariantCulture));
1427 this.XmlOutput.WriteValue(Expected.ToString(CultureInfo.InvariantCulture));
1429 this.XmlOutput.WriteValue(
".");
1430 this.XmlOutput.WriteEndElement();
1431 this.XmlOutput.WriteEndElement();
1433 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1434 this.XmlOutput.WriteAttributeString(
"Grid.Column",
"1");
1435 this.XmlOutput.WriteAttributeString(
"Grid.Row", Row.ToString(CultureInfo.InvariantCulture));
1437 if (ParagraphBullet)
1440 await this.RenderLabel(Item,
false);
1442 this.XmlOutput.WriteEndElement();
1448 this.XmlOutput.WriteEndElement();
1449 this.XmlOutput.WriteEndElement();
1458 this.RenderContentView();
1459 await this.RenderLabel(Element,
false);
1460 this.XmlOutput.WriteEndElement();
1463 internal async Task RenderLabel(
MarkdownElement Element,
bool IncludeElement)
1465 bool HasLink = !Element.
ForEach((E, _) =>
1474 this.XmlOutput.WriteStartElement(
"Label");
1475 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
1483 await Element.
Render(
this);
1489 this.InLabel =
true;
1491 this.XmlOutput.WriteStartElement(
"Label.FormattedText");
1492 this.XmlOutput.WriteStartElement(
"FormattedString");
1495 await Element.
Render(
this);
1499 this.XmlOutput.WriteEndElement();
1500 this.XmlOutput.WriteEndElement();
1502 this.InLabel =
false;
1507 this.XmlOutput.WriteAttributeString(
"TextType",
"Html");
1510 this.XmlOutput.WriteAttributeString(
"FontAttributes",
"Bold");
1514 XmlEntitiesOnly =
true
1525 this.XmlOutput.WriteEndElement();
1528 internal void RenderSpan(
string Text)
1532 this.XmlOutput.WriteStartElement(
"Label");
1533 this.XmlOutput.WriteAttributeString(
"LineBreakMode",
"WordWrap");
1535 this.XmlOutput.WriteStartElement(
"Label.FormattedText");
1536 this.XmlOutput.WriteStartElement(
"FormattedString");
1539 this.XmlOutput.WriteStartElement(
"Span");
1541 if (this.Superscript)
1543 else if (this.Subscript)
1546 this.XmlOutput.WriteAttributeString(
"Text", Text);
1548 if (this.Bold && this.Italic)
1549 this.XmlOutput.WriteAttributeString(
"FontAttributes",
"Italic, Bold");
1551 this.XmlOutput.WriteAttributeString(
"FontAttributes",
"Bold");
1552 else if (this.Italic)
1553 this.XmlOutput.WriteAttributeString(
"FontAttributes",
"Italic");
1555 if (this.StrikeThrough && this.Underline)
1556 this.XmlOutput.WriteAttributeString(
"TextDecorations",
"Strikethrough, Underline");
1557 else if (this.StrikeThrough)
1558 this.XmlOutput.WriteAttributeString(
"TextDecorations",
"Strikethrough");
1559 else if (this.Underline)
1560 this.XmlOutput.WriteAttributeString(
"TextDecorations",
"Underline");
1563 this.XmlOutput.WriteAttributeString(
"FontFamily",
"Courier New");
1565 if (this.Hyperlink is not
null)
1567 this.XmlOutput.WriteAttributeString(
"TextColor",
"{AppThemeBinding Light={StaticResource AccentForegroundLight}, Dark={StaticResource AccentForegroundDark}}");
1569 this.XmlOutput.WriteStartElement(
"Span.GestureRecognizers");
1570 this.XmlOutput.WriteStartElement(
"TapGestureRecognizer");
1571 this.XmlOutput.WriteAttributeString(
"Command",
"{Binding HyperlinkClicked}");
1572 this.XmlOutput.WriteAttributeString(
"CommandParameter", this.Hyperlink);
1573 this.XmlOutput.WriteEndElement();
1574 this.XmlOutput.WriteEndElement();
1579 this.XmlOutput.WriteEndElement();
1580 this.XmlOutput.WriteEndElement();
1581 this.XmlOutput.WriteEndElement();
1584 this.XmlOutput.WriteEndElement();
1587 internal void RenderContentView()
1589 this.RenderContentView(this.Alignment, SmallMargins(
false,
false,
true,
true),
null);
1592 internal void RenderContentView(
string Margins)
1594 this.RenderContentView(this.Alignment, Margins,
null);
1599 this.RenderContentView(
Alignment, Margins,
null);
1604 this.XmlOutput.WriteStartElement(
"ContentView");
1606 if (!
string.IsNullOrEmpty(Margins))
1607 this.XmlOutput.WriteAttributeString(
"Padding", Margins);
1609 if (!
string.IsNullOrEmpty(Style))
1610 this.XmlOutput.WriteAttributeString(
"Style",
"{StaticResource " + Style +
"}");
1615 this.XmlOutput.WriteAttributeString(
"HorizontalOptions",
"Center");
1619 this.XmlOutput.WriteAttributeString(
"HorizontalOptions",
"Start");
1623 this.XmlOutput.WriteAttributeString(
"HorizontalOptions",
"End");
1634 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1641 this.Alignment = Bak;
1642 this.XmlOutput.WriteEndElement();
1660 this.XmlOutput.WriteStartElement(
"BoxView");
1661 this.XmlOutput.WriteAttributeString(
"HeightRequest",
"1");
1662 this.XmlOutput.WriteAttributeString(
"BackgroundColor",
"{AppThemeBinding Light={StaticResource NormalEditPlaceholderLight}, Dark={StaticResource NormalEditPlaceholderDark}}");
1663 this.XmlOutput.WriteAttributeString(
"HorizontalOptions",
"FillAndExpand");
1664 this.XmlOutput.WriteAttributeString(
"Margin", SmallMargins(
false,
false,
true,
true));
1665 this.XmlOutput.WriteEndElement();
1667 return Task.CompletedTask;
1680 this.XmlOutput.WriteStartElement(
"ScrollView");
1681 this.XmlOutput.WriteAttributeString(
"Orientation",
"Horizontal");
1682 this.XmlOutput.WriteStartElement(
"ContentView");
1683 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
false,
false,
true,
true));
1685 this.XmlOutput.WriteStartElement(
"Grid");
1686 this.XmlOutput.WriteAttributeString(
"RowSpacing",
"-2");
1687 this.XmlOutput.WriteAttributeString(
"ColumnSpacing",
"-2");
1691 this.XmlOutput.WriteStartElement(
"Grid.ColumnDefinitions");
1693 for (Column = 0; Column < Element.
Columns; Column++)
1695 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
1696 this.XmlOutput.WriteAttributeString(
"Width",
"Auto");
1697 this.XmlOutput.WriteEndElement();
1700 this.XmlOutput.WriteEndElement();
1701 this.XmlOutput.WriteStartElement(
"Grid.RowDefinitions");
1703 for (Row = 0, NrRows = Element.
Rows.Length + Element.
Headers.Length; Row < NrRows; Row++)
1705 this.XmlOutput.WriteStartElement(
"RowDefinition");
1706 this.XmlOutput.WriteAttributeString(
"Height",
"Auto");
1707 this.XmlOutput.WriteEndElement();
1710 this.XmlOutput.WriteEndElement();
1712 for (Row = 0, NrRows = Element.
Headers.Length; Row < NrRows; Row++, RowNr++)
1715 for (Row = 0, NrRows = Element.
Rows.Length; Row < NrRows; Row++, RowNr++)
1718 this.XmlOutput.WriteEndElement();
1719 this.XmlOutput.WriteEndElement();
1720 this.XmlOutput.WriteEndElement();
1724 private void ClearState()
1728 this.Italic =
false;
1729 this.StrikeThrough =
false;
1730 this.Underline =
false;
1731 this.Superscript =
false;
1732 this.Subscript =
false;
1734 this.InLabel =
false;
1735 this.Hyperlink =
null;
1738 private StateBackup Backup()
1740 return new StateBackup()
1751 Hyperlink = this.Hyperlink
1755 private void Restore(StateBackup Backup)
1757 this.Alignment = Backup.Alignment;
1758 this.Bold = Backup.Bold;
1759 this.Italic = Backup.Italic;
1760 this.StrikeThrough = Backup.StrikeThrough;
1761 this.Underline = Backup.Underline;
1762 this.Superscript = Backup.Superscript;
1763 this.Subscript = Backup.Subscript;
1764 this.Code = Backup.Code;
1765 this.InLabel = Backup.InLabel;
1766 this.Hyperlink = Backup.Hyperlink;
1769 private class StateBackup
1776 public bool Superscript;
1777 public bool Subscript;
1779 public bool InLabel;
1780 public string? Hyperlink;
1789 int NrColumns = Element.
Columns;
1791 StateBackup Bak = this.Backup();
1795 for (Column = 0; Column < NrColumns; Column++)
1797 E = CurrentRow[Column];
1802 ColSpan = Column + 1;
1803 while (ColSpan < NrColumns && CurrentRow[ColSpan] is
null)
1808 this.XmlOutput.WriteStartElement(
"Frame");
1810 if ((RowNr & 1) == 0)
1811 this.XmlOutput.WriteAttributeString(
"Style",
"{StaticResource TableCellEven}");
1813 this.XmlOutput.WriteAttributeString(
"Style",
"{StaticResource TableCellOdd}");
1815 this.XmlOutput.WriteAttributeString(
"Grid.Column", Column.ToString(CultureInfo.InvariantCulture));
1816 this.XmlOutput.WriteAttributeString(
"Grid.Row", RowNr.ToString(CultureInfo.InvariantCulture));
1819 this.XmlOutput.WriteAttributeString(
"Grid.ColumnSpan", ColSpan.ToString(CultureInfo.InvariantCulture));
1826 await this.RenderLabel(E,
true);
1829 this.XmlOutput.WriteEndElement();
1833 this.XmlOutput.WriteStartElement(
"ContentView");
1834 this.XmlOutput.WriteAttributeString(
"Style",
null,
"{StaticResource TableCell}");
1836 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1838 this.XmlOutput.WriteEndElement();
1840 this.XmlOutput.WriteEndElement();
1843 this.XmlOutput.WriteEndElement();
1865 bool ParagraphBullet;
1867 this.XmlOutput.WriteStartElement(
"ContentView");
1868 this.XmlOutput.WriteAttributeString(
"Padding", SmallMargins(
false,
false,
true,
true));
1870 this.XmlOutput.WriteStartElement(
"Grid");
1871 this.XmlOutput.WriteAttributeString(
"RowSpacing",
"0");
1872 this.XmlOutput.WriteAttributeString(
"ColumnSpacing",
"0");
1874 this.XmlOutput.WriteStartElement(
"Grid.ColumnDefinitions");
1876 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
1877 this.XmlOutput.WriteAttributeString(
"Width",
"Auto");
1878 this.XmlOutput.WriteEndElement();
1880 this.XmlOutput.WriteStartElement(
"ColumnDefinition");
1881 this.XmlOutput.WriteAttributeString(
"Width",
"*");
1882 this.XmlOutput.WriteEndElement();
1884 this.XmlOutput.WriteEndElement();
1885 this.XmlOutput.WriteStartElement(
"Grid.RowDefinitions");
1889 this.XmlOutput.WriteStartElement(
"RowDefinition");
1890 this.XmlOutput.WriteAttributeString(
"Height",
"Auto");
1891 this.XmlOutput.WriteEndElement();
1894 this.XmlOutput.WriteEndElement();
1901 GetMargins(E, out
bool TopMargin, out
bool BottomMargin);
1905 this.RenderContentView(SmallMargins(
false,
true, TopMargin, BottomMargin));
1906 this.XmlOutput.WriteAttributeString(
"Grid.Column",
"0");
1907 this.XmlOutput.WriteAttributeString(
"Grid.Row", Row.ToString(CultureInfo.InvariantCulture));
1909 this.XmlOutput.WriteElementString(
"Label",
"✓");
1910 this.XmlOutput.WriteEndElement();
1913 this.XmlOutput.WriteStartElement(
"VerticalStackLayout");
1914 this.XmlOutput.WriteAttributeString(
"Grid.Column",
"1");
1915 this.XmlOutput.WriteAttributeString(
"Grid.Row", Row.ToString(CultureInfo.InvariantCulture));
1917 if (ParagraphBullet)
1920 await this.RenderLabel(
TaskItem,
false);
1922 this.XmlOutput.WriteEndElement();
1928 this.XmlOutput.WriteEndElement();
1929 this.XmlOutput.WriteEndElement();
Renders XAML (Maui flavour) from a Markdown document.
override Task RenderDocumentHeader()
Renders the document header.
override async Task Render(Emphasize Element)
Renders Element .
override async Task Render(Underline Element)
Renders Element .
override async Task Render(NestedBlock Element)
Renders Element .
override Task Render(TaskItem Element)
Renders Element .
override async Task Render(TaskList Element)
Renders Element .
void RenderLabelAlignment()
Writes a text-alignment attribute to a Maui label element.
override Task Render(InlineText Element)
Renders Element .
override async Task Render(DeleteBlocks Element)
Renders Element .
override Task Render(HtmlEntity Element)
Renders Element .
override async Task Render(Table Element)
Renders Element .
bool Subscript
If text is subscript
override Task Render(AutomaticLinkMail Element)
Renders Element .
override async Task Render(Delete Element)
Renders Element .
override async Task Render(DefinitionTerms Element)
Renders Element .
override Task Render(HashTag Element)
Renders Element .
virtual void Dispose(bool disposing)
IDisposable.Dispose
override Task Render(Footnote Element)
Renders Element .
override Task Render(HorizontalRule Element)
Renders Element .
Waher.Content.Markdown.Model.TextAlignment Alignment
Current text-alignment.
override async Task Render(FootnoteReference Element)
Renders Element .
override Task Render(CommentBlock Element)
Renders Element .
override Task Render(MultimediaReference Element)
Renders Element .
override async Task Render(InlineScript Element)
Renders Element .
override async Task Render(BlockQuote Element)
Renders Element .
readonly XmlWriter XmlOutput
XML output
override async Task Render(NumberedList Element)
Renders Element .
override async Task Render(RightAligned Element)
Renders Element .
override async Task Render(DefinitionDescriptions Element)
Renders Element .
override async Task Render(EmojiReference Element)
Renders Element .
override async Task Render(HtmlBlock Element)
Renders Element .
override async Task Render(Paragraph Element)
Renders Element .
override async Task Render(SubScript Element)
Renders Element .
override Task Render(Abbreviation Element)
Renders Element .
bool InLabel
If rendering is inside a label.
override async Task Render(LinkReference Element)
Renders Element .
override Task Render(UnnumberedItem Element)
Renders Element .
override Task Render(DetailsReference Element)
Renders Element .
MauiXamlRenderer(StringBuilder Output, XmlWriterSettings XmlSettings)
Renders XAML (Maui flavour) from a Markdown document.
override Task Render(LineBreak Element)
Renders Element .
override Task Render(InlineHTML Element)
Renders Element .
bool Superscript
If text is superscript
async Task RenderObject(object? Result, bool AloneInParagraph, Variables Variables)
Generates Maui XAML from Script output.
override Task Render(Sections Element)
Renders Element .
override Task Render(Waher.Content.Markdown.Model.SpanElements.Multimedia Element)
Renders Element .
override async Task Render(Insert Element)
Renders Element .
override async Task Render(InsertBlocks Element)
Renders Element .
override Task Render(MetaReference Element)
Renders Element .
override async Task RenderFootnotes()
Renders footnotes.
override Task RenderDocumentFooter()
Renders the document header.
override async Task Render(CenterAligned Element)
Renders Element .
override Task Render(DefinitionList Element)
Renders Element .
override Task Render(AutomaticLinkUrl Element)
Renders Element .
bool Code
If text is inline code.
override async Task Render(StrikeThrough Element)
Renders Element .
override Task Render(SectionSeparator Element)
Renders Element .
bool Italic
If text is italic
string? Hyperlink
Link, if rendering a hyperlink, null otherwise.
override Task Render(NumberedItem Element)
Renders Element .
override async Task Render(BulletList Element)
Renders Element .
override Task Render(InlineCode Element)
Renders Element .
override async Task Render(SuperScript Element)
Renders Element .
override Task Render(HtmlEntityUnicode Element)
Renders Element .
override async Task Render(Header Element)
Renders Element .
MauiXamlRenderer(XmlWriterSettings XmlSettings)
Renders XAML (Maui flavour) from a Markdown document.
override async Task Render(Link Element)
Renders Element .
override async Task Render(LeftAligned Element)
Renders Element .
override Task Render(InvisibleBreak Element)
Renders Element .
override async Task Render(CodeBlock Element)
Renders Element .
bool StrikeThrough
If text is stricken through
override async Task Render(Strong Element)
Renders Element .
bool Underline
If text is underlined
override async Task Render(MarginAligned Element)
Renders Element .
override Task RenderDocument(MarkdownDocument Document, bool Inclusion)
Renders a document.
override void Dispose()
Disposes of the renderer.
string ShortName
Emoji short name.
string Unicode
Unicode representation of emoji.
Contains information about an emoji image.
static string EntityToCharacter(string Entity)
Converts an HTML entity into a character.
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.
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,...
Abstract base class for block elements with one child.
Represents a block quote in a markdown document.
Represents a bullet list in a markdown document.
Represents a center-aligned set of blocks in a markdown document.
Represents a code block in a markdown document.
int Indent
Code block indentation.
string[] Rows
Rows in code block
Represents a definition list in a markdown document.
Represents inserted blocks in a markdown document.
Represents a block of HTML in a markdown document.
Represents inserted blocks in a markdown document.
Represents a left-aligned set of blocks in a markdown document.
Represents a margin-aligned set of blocks in a markdown document.
Represents a nested block with no special formatting rules in a markdown document.
Represents a numbered item in an ordered list.
int Number
Number associated with item.
Represents a numbered list in a markdown document.
Represents a paragraph in a markdown document.
Represents a right-aligned set of blocks in a markdown document.
Represents a sequence of sections.
Represents a table in a markdown document.
TextAlignment[] ColumnAlignments
Table column alignments.
override IEnumerable< MarkdownElement > Children
Any children of the element.
MarkdownElement[][] Headers
Headers in table.
int Columns
Number of columns.
TextAlignment?[][] RowCellAlignments
Row cell alignments in table.
TextAlignment?[][] HeaderCellAlignments
Header cell alignments in table.
MarkdownElement[][] Rows
Rows in table.
Represents a task item in a task list.
bool IsChecked
If the item is checked or not.
Represents a task list in a markdown document.
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.
virtual bool ForEach(MarkdownElementHandler Callback, object State)
Loops through all child-elements for the element.
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.
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)
EmojiInfo Emoji
Emoji information.
Represents an HTML entity.
Represents an HTML entity in Unicode format.
int Code
Unicode character
bool AloneInParagraph
If the element is alone in a paragraph.
Variables Variables
Variables.
async Task< object > EvaluateExpression()
Evaluates the script expression.
string Value
Unformatted text.
bool TryGetMetaData(out KeyValuePair< string, bool >[] Values)
Tries to get meta-data from the document.
MultimediaItem[] Items
Multimedia items.
bool AloneInParagraph
If the element is alone in a paragraph.
Renders HTML from a Markdown document.
Contains settings that the HTML export uses to customize HTML output.
Abstract base class for Markdown renderers.
readonly StringBuilder Output
Renderer output.
Task RenderChild(MarkdownElementSingleChild Element)
Renders the child of Element .
async Task RenderChildren(MarkdownElementChildren Element)
Renders the children of Element .
override string ToString()
Returns the renderer output.
virtual void Dispose()
Disposes of the renderer.
MarkdownDocument Document
Reference to Markdown document being processed.
Renders plain text from a Markdown document.
static string ToSubscript(string s)
Converts a string to subscript (as far as it goes).
static string ToSuperscript(string s)
Converts a string to superscript (as far as it goes).
Static class managing the application event log. Applications and services log events on this static ...
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
ToMatrix(ScriptNode Operand, bool NullCheck, int Start, int Length, Expression Expression)
To-Matrix operator.
Interface for code content Maui XAML renderers.
Interface for Emoji sources. Emoji sources provide emojis to content providers.
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.
Interface for objects that can be converted into matrices.
TextAlignment
Text alignment of contents.