5using System.Threading.Tasks;
27 private bool portableSyntax =
true;
71 get => this.portableSyntax;
72 set => this.portableSyntax = value;
80 if (!(this.
Document?.FootnoteOrder is
null))
86 if (!Guid.TryParse(Key, out
_) &&
101 foreach (
string Row
in s.Replace(
"\r\n",
"\n").Replace(
'\r',
'\n').Split(
'\n'))
104 this.
Output.AppendLine(Row);
112 #region Span Elements
122 this.
Output.Append(
"](abbr:");
137 return Task.CompletedTask;
150 return Task.CompletedTask;
186 return Task.CompletedTask;
240 return Task.CompletedTask;
272 string s = Html.HtmlEntity.EntityToCharacter(
Element.Entity);
273 if (!
string.IsNullOrEmpty(s))
278 return Task.CompletedTask;
291 return Task.CompletedTask;
304 return Task.CompletedTask;
315 return Task.CompletedTask;
324 object Result = await
Element.EvaluateExpression();
340 if (Result is XmlDocument Xml)
345 if (Result is
Graph G)
355 else if (Result is SKImage Img)
365 Doc.ProcessAsyncTasks();
375 Doc.ProcessAsyncTasks();
378 else if (Result is Exception ex)
382 this.
Output.Append(
"<font class=\"error\">");
384 if (ex is AggregateException ex2)
386 foreach (Exception ex3
in ex2.InnerExceptions)
388 this.
Output.Append(
"<p>");
390 this.
Output.AppendLine(
"</p>");
395 if (AloneInParagraph)
396 this.
Output.Append(
"<p>");
400 if (AloneInParagraph)
401 this.
Output.Append(
"</p>");
404 this.
Output.Append(
"</font>");
411 else if (Result is Array A)
413 foreach (
object Item
in A)
418 if (AloneInParagraph)
419 this.
Output.Append(
"<p>");
423 if (AloneInParagraph)
424 this.
Output.Append(
"</p>");
427 if (AloneInParagraph)
439 return Task.CompletedTask;
459 this.
Output.AppendLine(
" ");
461 return Task.CompletedTask;
475 if (!
string.IsNullOrEmpty(
Element.Title))
477 this.
Output.Append(
" \"");
478 this.
Output.Append(Element.
Title.Replace(
"\"",
"\\\""));
504 bool FirstOnRow =
true;
506 if (
Element.TryGetMetaData(out KeyValuePair<string, bool>[] Values))
508 foreach (KeyValuePair<string, bool> P
in Values)
518 this.
Output.AppendLine(
" ");
524 return Task.CompletedTask;
547 bool AloneInParagraph)
552 await this.
Render(ChildNodes);
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)
683 return this.PrefixedBlock(Children, Prefix, Prefix);
692 private Task PrefixedBlock(
MarkdownElement Child,
string PrefixFirstRow,
string PrefixNextRows)
709 string s =
Renderer.ToString().Replace(
"\r\n",
"\n").Replace(
'\r',
'\n');
710 string[] Rows = s.Split(
'\n');
711 int i, c = Rows.Length;
713 if (c > 0 &&
string.IsNullOrEmpty(Rows[c - 1]))
716 for (i = 0; i < c; i++)
718 this.
Output.Append(PrefixFirstRow);
719 this.
Output.AppendLine(Rows[i]);
720 PrefixFirstRow = PrefixNextRows;
732 return this.SuffixedBlock(Children, Suffix, Suffix);
747 string s =
Renderer.ToString().Replace(
"\r\n",
"\n").Replace(
'\r',
'\n');
748 string[] Rows = s.Split(
'\n');
749 int i, c = Rows.Length;
751 if (c > 0 &&
string.IsNullOrEmpty(Rows[c - 1]))
754 for (i = 0; i < c; i++)
756 this.
Output.Append(Rows[i]);
757 this.
Output.AppendLine(SuffixFirstRow);
758 SuffixFirstRow = SuffixNextRows;
771 return this.PrefixSuffixedBlock(Children, Prefix, Prefix, Suffix, Suffix);
783 string SuffixFirstRow,
string SuffixNextRows)
789 string s =
Renderer.ToString().Replace(
"\r\n",
"\n").Replace(
'\r',
'\n');
790 string[] Rows = s.Split(
'\n');
791 int i, c = Rows.Length;
793 if (c > 0 &&
string.IsNullOrEmpty(Rows[c - 1]))
796 for (i = 0; i < c; i++)
798 this.
Output.Append(PrefixFirstRow);
799 this.
Output.Append(Rows[i]);
800 this.
Output.AppendLine(SuffixFirstRow);
801 PrefixFirstRow = PrefixNextRows;
802 SuffixFirstRow = SuffixNextRows;
809 #region Block elements
817 await this.PrefixedBlock(
Element.Children,
">\t");
837 await this.PrefixSuffixedBlock(
Element.Children,
">>",
"<<");
847 if (this.portableSyntax)
867 foreach (
string Row
in Element.Rows)
871 foreach (
char ch
in Row)
888 string s =
new string(
'`', Max + 1);
893 foreach (
string Row
in Element.Rows)
894 this.
Output.AppendLine(Row);
896 this.
Output.AppendLine(s);
906 return Task.CompletedTask;
915 await this.PrefixedBlock(
Element.Children,
":\t",
":\t");
938 while (!(Loop is
null))
940 for (i = Loop.
Start, c = Loop.
Pos; i < c; i++)
942 await Loop[i].Render(
this);
956 await this.PrefixedBlock(
Element.Children,
"->\t");
999 return Task.CompletedTask;
1009 this.
Output.AppendLine();
1018 await this.PrefixedBlock(
Element.Children,
"+>\t");
1019 this.
Output.AppendLine();
1029 this.
Output.AppendLine();
1031 return Task.CompletedTask;
1040 await this.PrefixedBlock(
Element.Children,
"<<");
1041 this.
Output.AppendLine();
1050 await this.PrefixSuffixedBlock(
Element.Children,
"<<",
">>");
1051 this.
Output.AppendLine();
1072 Prefix =
Element.Number.ToString() +
".\t";
1076 await this.PrefixedBlock(
Element.Child, Prefix,
"\t");
1078 if (
Element.Child.IsBlockElement)
1079 this.
Output.AppendLine();
1089 this.
Output.AppendLine();
1100 this.
Output.AppendLine();
1101 this.
Output.AppendLine();
1110 await this.SuffixedBlock(
Element.Children,
">>");
1111 this.
Output.AppendLine();
1120 if (!
string.IsNullOrEmpty(
Element.InitialRow))
1123 this.
Output.AppendLine();
1136 this.
Output.AppendLine();
1138 return Task.CompletedTask;
1147 int[] Widths =
new int[
Element.Columns];
1150 string[][] Headers =
new string[c =
Element.Headers.Length][];
1151 for (i = 0; i < c; i++)
1154 string[][] Rows =
new string[d =
Element.Rows.Length][];
1155 for (i = 0; i < d; i++)
1158 for (i = 0; i < c; i++)
1161 foreach (
string Headline
in Element.ColumnAlignmentDefinitions)
1164 this.
Output.Append(Headline);
1167 this.
Output.AppendLine(
"|");
1169 for (i = 0; i < d; i++)
1172 bool NewLine =
false;
1174 if (!
string.IsNullOrEmpty(
Element.Caption))
1182 if (!
string.IsNullOrEmpty(
Element.Id))
1191 this.
Output.AppendLine();
1193 this.
Output.AppendLine();
1203 for (i = 0; i <
Element.Columns;)
1211 j = Widths[i] - s.Length;
1215 while (i <
Element.Columns && Elements[i] is
null)
1228 this.
Output.AppendLine();
1235 string[] Result =
new string[
Element.Columns];
1242 for (i = 0; i <
Element.Columns; i++)
1252 Alignment = Alignments[i];
1253 if (Alignment.HasValue)
1255 switch (Alignment.Value)
1266 s =
">>" + s +
"<<";
1273 LastLen = s.Length + 2;
1275 while (j <
Element.Columns && Elements[j] is
null)
1284 LastLen -= (j - 1) * Len;
1288 if (Widths[i] < Len)
1294 if (Widths[i] < LastLen)
1295 Widths[i] = LastLen;
1308 await this.PrefixedBlock(
Element.Child,
Element.IsChecked ?
"[x]\t" :
"[ ]\t",
"\t");
1310 if (
Element.Child.IsBlockElement)
1311 this.
Output.AppendLine();
1321 this.
Output.AppendLine();
1330 await this.PrefixedBlock(
Element.Child,
Element.Prefix +
"\t",
"\t");
1332 if (
Element.Child.IsBlockElement)
1333 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.
MarkdownDocument Detail
Detail document of a master document.
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.
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.
async Task< bool > Render(ChunkedList< MarkdownElement > Elements)
Renders a collection of elements.
readonly StringBuilder Output
Renderer output.
void Clear()
Clears the underlying StringBuilder.
virtual async Task RenderDocument(MarkdownDocument Document, bool Inclusion)
Renders a document.
Task RenderChildren(MarkdownElementChildren Element)
Renders the children of Element .
override string ToString()
Returns the renderer output.
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.
Node referencing a chunk in a ChunkedList<T>
ChunkNode< T > Next
Next chunk
int Pos
Index after the last element in chunk.
int Start
Index of first element in chunk.
A chunked list is a linked list of chunks of objects of type T .
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.