3using System.Collections.Generic;
5using System.Threading.Tasks;
25 private bool portableSyntax =
true;
69 get => this.portableSyntax;
70 set => this.portableSyntax = value;
78 if (!(this.
Document?.FootnoteOrder is
null))
84 if (!Guid.TryParse(Key, out _) &&
99 foreach (
string Row
in s.Replace(
"\r\n",
"\n").Replace(
'\r',
'\n').Split(
'\n'))
102 this.
Output.AppendLine(Row);
110 #region Span Elements
120 this.
Output.Append(
"](abbr:");
135 return Task.CompletedTask;
148 return Task.CompletedTask;
168 this.
Output.Append(
"[%Details]");
170 return Task.CompletedTask;
183 return Task.CompletedTask;
237 return Task.CompletedTask;
269 string s = Html.HtmlEntity.EntityToCharacter(
Element.Entity);
270 if (!
string.IsNullOrEmpty(s))
275 return Task.CompletedTask;
288 return Task.CompletedTask;
301 return Task.CompletedTask;
312 return Task.CompletedTask;
321 object Result = await
Element.EvaluateExpression();
337 if (Result is XmlDocument Xml)
342 if (Result is
Graph G)
352 else if (Result is SKImage Img)
362 Doc.ProcessAsyncTasks();
372 Doc.ProcessAsyncTasks();
375 else if (Result is Exception ex)
379 this.
Output.Append(
"<font class=\"error\">");
381 if (ex is AggregateException ex2)
383 foreach (Exception ex3
in ex2.InnerExceptions)
385 this.
Output.Append(
"<p>");
387 this.
Output.AppendLine(
"</p>");
392 if (AloneInParagraph)
393 this.
Output.Append(
"<p>");
397 if (AloneInParagraph)
398 this.
Output.Append(
"</p>");
401 this.
Output.Append(
"</font>");
408 else if (Result is Array A)
410 foreach (
object Item
in A)
415 if (AloneInParagraph)
416 this.
Output.Append(
"<p>");
420 if (AloneInParagraph)
421 this.
Output.Append(
"</p>");
424 if (AloneInParagraph)
436 return Task.CompletedTask;
456 this.
Output.AppendLine(
" ");
458 return Task.CompletedTask;
472 if (!
string.IsNullOrEmpty(
Element.Title))
474 this.
Output.Append(
" \"");
475 this.
Output.Append(Element.
Title.Replace(
"\"",
"\\\""));
501 bool FirstOnRow =
true;
503 if (
Element.TryGetMetaData(out KeyValuePair<string, bool>[] Values))
505 foreach (KeyValuePair<string, bool> P
in Values)
515 this.
Output.AppendLine(
" ");
521 return Task.CompletedTask;
543 private async Task DefaultRenderingMultimedia(
MultimediaItem[] Items, IEnumerable<MarkdownElement> ChildNodes,
544 bool AloneInParagraph)
559 else if (AloneInParagraph)
568 if (!
string.IsNullOrEmpty(Item.
Title))
570 this.
Output.Append(
" \"");
571 this.
Output.Append(Item.
Title.Replace(
"\"",
"\\\""));
575 if (Item.
Width.HasValue)
590 if (AloneInParagraph)
681 private Task PrefixedBlock(IEnumerable<MarkdownElement> Children,
string Prefix)
683 return this.PrefixedBlock(Children, Prefix, Prefix);
692 private Task PrefixedBlock(
MarkdownElement Child,
string PrefixFirstRow,
string PrefixNextRows)
694 return this.PrefixedBlock(
new MarkdownElement[] { Child }, PrefixFirstRow, PrefixNextRows);
703 private async Task PrefixedBlock(IEnumerable<MarkdownElement> Children,
string PrefixFirstRow,
string PrefixNextRows)
710 string s =
Renderer.ToString().Replace(
"\r\n",
"\n").Replace(
'\r',
'\n');
711 string[] Rows = s.Split(
'\n');
712 int i, c = Rows.Length;
714 if (c > 0 &&
string.IsNullOrEmpty(Rows[c - 1]))
717 for (i = 0; i < c; i++)
719 this.
Output.Append(PrefixFirstRow);
720 this.
Output.AppendLine(Rows[i]);
721 PrefixFirstRow = PrefixNextRows;
731 private Task SuffixedBlock(IEnumerable<MarkdownElement> Children,
string Suffix)
733 return this.SuffixedBlock(Children, Suffix, Suffix);
742 private async Task SuffixedBlock(IEnumerable<MarkdownElement> Children,
string SuffixFirstRow,
string SuffixNextRows)
749 string s =
Renderer.ToString().Replace(
"\r\n",
"\n").Replace(
'\r',
'\n');
750 string[] Rows = s.Split(
'\n');
751 int i, c = Rows.Length;
753 if (c > 0 &&
string.IsNullOrEmpty(Rows[c - 1]))
756 for (i = 0; i < c; i++)
758 this.
Output.Append(Rows[i]);
759 this.
Output.AppendLine(SuffixFirstRow);
760 SuffixFirstRow = SuffixNextRows;
771 private Task PrefixSuffixedBlock(IEnumerable<MarkdownElement> Children,
string Prefix,
string Suffix)
773 return this.PrefixSuffixedBlock(Children, Prefix, Prefix, Suffix, Suffix);
784 private async Task PrefixSuffixedBlock(IEnumerable<MarkdownElement> Children,
string PrefixFirstRow,
string PrefixNextRows,
785 string SuffixFirstRow,
string SuffixNextRows)
792 string s =
Renderer.ToString().Replace(
"\r\n",
"\n").Replace(
'\r',
'\n');
793 string[] Rows = s.Split(
'\n');
794 int i, c = Rows.Length;
796 if (c > 0 &&
string.IsNullOrEmpty(Rows[c - 1]))
799 for (i = 0; i < c; i++)
801 this.
Output.Append(PrefixFirstRow);
802 this.
Output.Append(Rows[i]);
803 this.
Output.AppendLine(SuffixFirstRow);
804 PrefixFirstRow = PrefixNextRows;
805 SuffixFirstRow = SuffixNextRows;
812 #region Block elements
820 await this.PrefixedBlock(
Element.Children,
">\t");
840 await this.PrefixSuffixedBlock(
Element.Children,
">>",
"<<");
850 if (this.portableSyntax)
870 foreach (
string Row
in Element.Rows)
874 foreach (
char ch
in Row)
891 string s =
new string(
'`', Max + 1);
896 foreach (
string Row
in Element.Rows)
897 this.
Output.AppendLine(Row);
899 this.
Output.AppendLine(s);
909 return Task.CompletedTask;
918 await this.PrefixedBlock(
Element.Children,
":\t",
":\t");
951 await this.PrefixedBlock(
Element.Children,
"->\t");
994 return Task.CompletedTask;
1004 this.
Output.AppendLine();
1013 await this.PrefixedBlock(
Element.Children,
"+>\t");
1014 this.
Output.AppendLine();
1024 this.
Output.AppendLine();
1026 return Task.CompletedTask;
1035 await this.PrefixedBlock(
Element.Children,
"<<");
1036 this.
Output.AppendLine();
1045 await this.PrefixSuffixedBlock(
Element.Children,
"<<",
">>");
1046 this.
Output.AppendLine();
1067 Prefix =
Element.Number.ToString() +
".\t";
1071 await this.PrefixedBlock(
Element.Child, Prefix,
"\t");
1073 if (
Element.Child.IsBlockElement)
1074 this.
Output.AppendLine();
1084 this.
Output.AppendLine();
1095 this.
Output.AppendLine();
1096 this.
Output.AppendLine();
1105 await this.SuffixedBlock(
Element.Children,
">>");
1106 this.
Output.AppendLine();
1115 if (!
string.IsNullOrEmpty(
Element.InitialRow))
1118 this.
Output.AppendLine();
1131 this.
Output.AppendLine();
1133 return Task.CompletedTask;
1142 int[] Widths =
new int[
Element.Columns];
1145 string[][] Headers =
new string[c =
Element.Headers.Length][];
1146 for (i = 0; i < c; i++)
1149 string[][] Rows =
new string[d =
Element.Rows.Length][];
1150 for (i = 0; i < d; i++)
1153 for (i = 0; i < c; i++)
1156 foreach (
string Headline
in Element.ColumnAlignmentDefinitions)
1159 this.
Output.Append(Headline);
1162 this.
Output.AppendLine(
"|");
1164 for (i = 0; i < d; i++)
1167 bool NewLine =
false;
1169 if (!
string.IsNullOrEmpty(
Element.Caption))
1177 if (!
string.IsNullOrEmpty(
Element.Id))
1186 this.
Output.AppendLine();
1188 this.
Output.AppendLine();
1198 for (i = 0; i <
Element.Columns;)
1206 j = Widths[i] - s.Length;
1210 while (i <
Element.Columns && Elements[i] is
null)
1223 this.
Output.AppendLine();
1230 string[] Result =
new string[
Element.Columns];
1237 for (i = 0; i <
Element.Columns; i++)
1247 Alignment = Alignments[i];
1248 if (Alignment.HasValue)
1250 switch (Alignment.Value)
1261 s =
">>" + s +
"<<";
1268 LastLen = s.Length + 2;
1270 while (j <
Element.Columns && Elements[j] is
null)
1279 LastLen -= (j - 1) * Len;
1283 if (Widths[i] < Len)
1289 if (Widths[i] < LastLen)
1290 Widths[i] = LastLen;
1303 await this.PrefixedBlock(
Element.Child,
Element.IsChecked ?
"[x]\t" :
"[ ]\t",
"\t");
1305 if (
Element.Child.IsBlockElement)
1306 this.
Output.AppendLine();
1316 this.
Output.AppendLine();
1325 await this.PrefixedBlock(
Element.Child,
Element.Prefix +
"\t",
"\t");
1327 if (
Element.Child.IsBlockElement)
1328 this.
Output.AppendLine();
Converts an element to a markdown string.
static string ImageToMarkdown(SKImage Image)
Converts an image to Markdown.
static string MatrixToMarkdown(IMatrix Matrix)
Converts a matrix to Markdown.
static string PixelsToMarkdown(PixelInformation Pixels)
Converts pixels to Markdown.
static string GraphToMarkdown(Graph Graph)
Converts a graph to Markdown.
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.
static string Encode(string s)
Encodes all special characters in a string so that it can be included in a markdown document without ...
bool TryGetFootnote(string Key, out Footnote Footnote)
Tries to get a footnote, given its key.
IEnumerable< string > FootnoteOrder
Order of footnotes.
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.
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.
Represents a definition list in a markdown document.
Represents inserted blocks in a markdown document.
string Row
Original Row generating the horizontal rule.
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.
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.
string InitialRow
Initial row
Represents a table in a markdown document.
MarkdownElement[][] Headers
Headers in table.
MarkdownElement[][] Rows
Rows in table.
Represents a task item in a task list.
Represents a task list in a markdown document.
Represents an unnumbered item in an ordered list.
Abstract base class for all markdown elements.
abstract Task Render(IRenderer Output)
Renders the element.
int? Height
Height of media item, if available.
string Title
Optional title.
int? Width
Width of media item, if available.
string Description
Description
string Delimiter
Delimiter string used to identify emoji.
EmojiInfo Emoji
Emoji information.
Represents an HTML entity.
Represents an HTML entity in Unicode format.
int Code
Unicode character
string Title
Optional Link title.
MultimediaItem[] Items
Multimedia items.
Renders portable Markdown from a Markdown document.
override Task Render(CommentBlock Element)
Renders Element .
override Task Render(InlineHTML Element)
Renders Element .
override Task Render(InvisibleBreak Element)
Renders Element .
override async Task Render(MarginAligned Element)
Renders Element .
override async Task Render(Header Element)
Renders Element .
override async Task Render(Delete Element)
Renders Element .
override async Task RenderFootnotes()
Renders footnotes.
override async Task Render(FootnoteReference Element)
Renders Element .
override async Task Render(SuperScript Element)
Renders Element .
MarkdownRenderer(StringBuilder Output, MarkdownDocument Document)
Renders portable Markdown from a Markdown document.
override Task Render(InlineText Element)
Renders Element .
override async Task Render(Link Element)
Renders Element .
override Task Render(MultimediaReference Element)
Renders Element .
override Task Render(AutomaticLinkMail Element)
Renders Element .
override Task Render(HashTag Element)
Renders Element .
override async Task Render(Emphasize Element)
Renders Element .
override async Task Render(DefinitionDescriptions Element)
Renders Element .
MarkdownRenderer()
Renders portable Markdown from a Markdown document.
override async Task Render(DeleteBlocks Element)
Renders Element .
override Task Render(DetailsReference Element)
Renders Element .
override async Task Render(NumberedItem Element)
Renders Element .
async Task RenderObject(object Result, bool AloneInParagraph, Variables Variables)
Generates Markdown from Script output.
override Task Render(NestedBlock Element)
Renders Element .
override async Task Render(DefinitionList Element)
Renders Element .
MarkdownRenderer(StringBuilder Output)
Renders portable Markdown from a Markdown document.
override async Task Render(BulletList Element)
Renders Element .
override Task Render(Footnote Element)
Renders Element .
override Task Render(LineBreak Element)
Renders Element .
override async Task Render(Abbreviation Element)
Renders Element .
override async Task Render(TaskList Element)
Renders Element .
override async Task Render(InsertBlocks Element)
Renders Element .
override Task Render(AutomaticLinkUrl Element)
Renders Element .
override Task Render(InlineCode Element)
Renders Element .
override async Task Render(Underline Element)
Renders Element .
override Task Render(HorizontalRule Element)
Renders Element .
override async Task Render(Table Element)
Renders Element .
override async Task Render(RightAligned Element)
Renders Element .
override async Task Render(Insert Element)
Renders Element .
override async Task Render(UnnumberedItem Element)
Renders Element .
override async Task Render(Strong Element)
Renders Element .
override Task Render(HtmlEntity Element)
Renders Element .
override async Task Render(HtmlBlock Element)
Renders Element .
override Task Render(SectionSeparator Element)
Renders Element .
override async Task Render(StrikeThrough Element)
Renders Element .
bool PortableSyntax
If a portable syntax of markdown is to be generated (true), or if generated Markdown is to be process...
MarkdownRenderer(MarkdownDocument Document)
Renders portable Markdown from a Markdown document.
override Task Render(Sections Element)
Renders Element .
override Task Render(HtmlEntityUnicode Element)
Renders Element .
override async Task Render(CodeBlock Element)
Renders Element .
override async Task Render(SubScript Element)
Renders Element .
override async Task Render(BlockQuote Element)
Renders Element .
override Task Render(MetaReference Element)
Renders Element .
override async Task Render(InlineScript Element)
Renders Element .
override async Task Render(DefinitionTerms Element)
Renders Element .
override async Task Render(LinkReference Element)
Renders Element .
override Task Render(EmojiReference Element)
Renders Element .
override async Task Render(TaskItem Element)
Renders Element .
override Task Render(Model.SpanElements.Multimedia Element)
Renders Element .
override async Task Render(NumberedList Element)
Renders Element .
override async Task Render(Paragraph Element)
Renders Element .
override async Task Render(CenterAligned Element)
Renders Element .
override async Task Render(LeftAligned Element)
Renders Element .
Abstract base class for Markdown renderers.
readonly StringBuilder Output
Renderer output.
async Task RenderChildren(MarkdownElementChildren Element)
Renders the children of Element .
void Clear()
Clears the underlying StringBuilder.
virtual async Task RenderDocument(MarkdownDocument Document, bool Inclusion)
Renders a document.
override string ToString()
Returns the renderer output.
abstract Task Render(Abbreviation Element)
Renders Element .
MarkdownDocument Document
Reference to Markdown document being processed.
Renderer()
Abstract base class for Markdown renderers.
Helps with common XML-related tasks.
static string HtmlValueEncode(string s)
Differs from Encode(String), in that it does not encode the aposotrophe or the quote.
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.
Base class for all types of elements.
ToMatrix(ScriptNode Operand, bool NullCheck, int Start, int Length, Expression Expression)
To-Matrix operator.
Interface for code content Markdown renderers.
Interface for multimedia content Markdown renderers.
Basic interface for matrices.
Interface for objects that can be converted into matrices.
TextAlignment
Text alignment of contents.