2using System.Collections.Generic;
5using System.Threading.Tasks;
44 int i = Language.IndexOf(
':');
46 Language = Language.Substring(0, i).TrimEnd();
48 if (
string.Compare(Language,
"async",
true) == 0)
49 return Grade.Excellent;
51 return Grade.NotAtAll;
65 this.document = Document;
67 if (!Document.
TryGetMetaData(
"JAVASCRIPT", out KeyValuePair<string, bool>[] Values) ||
68 !Contains(Values,
"/Events.js"))
74 private static bool Contains(KeyValuePair<string, bool>[] Values,
string Value)
76 foreach (KeyValuePair<string, bool> P
in Values)
78 if (
string.Compare(P.Key, Value,
true) == 0)
97 int i = Language.IndexOf(
':');
99 Title = Language.Substring(i + 1).Trim();
103 AsyncState State =
new AsyncState()
106 Script = this.BuildExpression(Rows),
108 ImplicitPrint =
new StringBuilder()
111 State.Variables.ConsoleOut =
new StringWriter(State.ImplicitPrint);
119 private class AsyncState
124 public StringBuilder ImplicitPrint;
127 private Task ExecuteScript(
object State)
129 AsyncState AsyncState = (AsyncState)State;
130 return this.Evaluate(AsyncState.Script, AsyncState.Variables, AsyncState.ImplicitPrint, AsyncState.Id);
133 private Expression BuildExpression(
string[] Rows)
158 XmlEntitiesOnly =
true
173 XmlEntitiesOnly =
true
176 Variables.OnPreview += Preview;
179 object Result = await this.Evaluate(Script,
Variables);
181 string Printed = ImplicitPrint.ToString();
182 if (!
string.IsNullOrEmpty(Printed))
184 StringBuilder sb =
new StringBuilder();
185 sb.AppendLine(
"BodyOnly: 1");
188 sb.AppendLine(
"AllowScriptTag: 1");
195 if (!(this.document is
null))
217 Variables.OnPreview -= Preview;
235 Expression Script = this.BuildExpression(Rows);
237 object Result = await this.Evaluate(Script,
Variables);
255 Expression Script = this.BuildExpression(Rows);
257 object Result = await this.Evaluate(Script,
Variables);
259 await
Renderer.RenderObject(Result,
true);
275 Expression Script = this.BuildExpression(Rows);
277 object Result = await this.Evaluate(Script,
Variables);
295 Expression Script = this.BuildExpression(Rows);
297 object Result = await this.Evaluate(Script,
Variables);
315 Expression Script = this.BuildExpression(Rows);
317 object Result = await this.Evaluate(Script,
Variables);
335 Expression Script = this.BuildExpression(Rows);
337 object Result = await this.Evaluate(Script,
Variables);
Renders Contracts XML from a Markdown document.
Renders LaTeX from a Markdown document.
Contains a markdown document. This markdown document class supports original markdown,...
static string AppendRows(string[] Rows)
Appends a set of rows into a single string with newlines between rows.
MarkdownSettings Settings
Markdown settings.
async Task RenderDocument(IRenderer Output)
Renders the document using provided output format.
bool AllowScriptTag
If client-side script tags are allowed in the document.
void QueueAsyncTask(AsyncMarkdownProcessing Callback, object State)
Queues an asynchronous task to be executed. Asynchronous tasks will be executed after the main docume...
bool TryGetMetaData(string Key, out KeyValuePair< string, bool >[] Value)
Tries to get a meta-data value given its key.
void AddMetaData(string Key, string Value)
Adds meta-data to the document.
const string MarkdownSettingsVariableName
Variable name used for storing Markdown settings.
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.
Variables Variables
Collection of variables. Providing such a collection enables script execution inside markdown documen...
Renders HTML from a Markdown document.
async Task RenderObject(object Result, bool AloneInParagraph, Variables Variables)
Generates HTML from Script output.
Contains settings that the HTML export uses to customize HTML output.
Renders portable Markdown from a Markdown document.
Abstract base class for Markdown renderers.
readonly StringBuilder Output
Renderer output.
void Clear()
Clears the underlying StringBuilder.
override string ToString()
Returns the renderer output.
Renders plain text from a Markdown document.
Renders XAML (WPF flavour) from a Markdown document.
Renders XAML (Xamarin.Forms flavour) from a Markdown document.
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Pushes asynchronously generated HTML content to clients
Class managing asynchronous script execution in Markdown documents.
bool EvaluatesScript
If script is evaluated for this type of code block.
Grade Supports(string Language)
Checks how well the handler supports multimedia content of a given type.
async Task< bool > RenderLatex(LatexRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates LaTeX for the code content.
async Task< bool > RenderXamarinFormsXaml(XamarinFormsXamlRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates Xamarin.Forms XAML for the code content.
async Task< bool > RenderMarkdown(MarkdownRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates Markdown for the code content.
async Task< bool > RenderContractXml(ContractsRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates smart contract XML for the code content.
async Task< bool > RenderWpfXaml(WpfXamlRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates WPF XAML for the code content.
AsyncScript()
Class managing 2D XML Layout integration into Markdown documents.
async Task< bool > RenderHtml(HtmlRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates HTML for the code content.
void Register(MarkdownDocument Document)
Is called on the object when an instance of the element has been created in a document.
async Task< bool > RenderText(TextRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates plain text for the code content.
Implements an HTTP server.
static Variables CreateVariables()
Creates a new collection of variables, that contains access to the global set of variables.
Class managing a script expression.
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
Event arguments for preview events.
IElement Preview
Preview of result.
Contains information about a variable.
void CopyTo(Variables Variables)
Copies available variables to another variable collection.
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Interface for code content contract renderers.
Interface for code content LaTeX renderers.
Interface for all markdown handlers of code content.
Interface for code content HTML renderers.
Interface for code content Markdown renderers.
Interface for code content plain text renderers.
Interface for code content WPF XAML renderers.
Interface for code content Xamarin.Forms XAML renderers.
MarkdownOutputType
Markdown output type.