5using System.Threading.Tasks;
44 int i = Language.IndexOf(
':');
46 Language = Language[..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[(i + 1)..].Trim();
104 AsyncState State =
new AsyncState()
107 Script = this.BuildExpression(Rows),
109 ImplicitPrint =
new StringBuilder()
112 State.Variables.ConsoleOut =
new StringWriter(State.ImplicitPrint);
117 SessionVariables.LastPost = CurrentSessionVariables.LastPost;
118 SessionVariables.CurrentRequest = CurrentSessionVariables.CurrentRequest;
119 SessionVariables.CurrentResponse = CurrentSessionVariables.CurrentResponse;
120 SessionVariables.CurrentPageVariables = CurrentSessionVariables.CurrentPageVariables;
121 SessionVariables.CurrentPageUrl = CurrentSessionVariables.CurrentPageUrl;
129 private class AsyncState
134 public StringBuilder ImplicitPrint;
137 private Task ExecuteScript(
object State)
139 AsyncState AsyncState = (AsyncState)State;
140 return this.Evaluate(AsyncState.Script, AsyncState.Variables, AsyncState.ImplicitPrint, AsyncState.Id);
143 private Expression BuildExpression(
string[] Rows)
168 XmlEntitiesOnly =
true
172 await asyncHtmlOutput.ReportResult(
MarkdownOutputType.Html, Id, Renderer2.ToString(),
true);
182 XmlEntitiesOnly =
true
185 Variables.OnPreview += Preview;
188 object Result = await this.Evaluate(Script,
Variables);
190 string Printed = ImplicitPrint.ToString();
191 if (!
string.IsNullOrEmpty(Printed))
193 StringBuilder sb =
new StringBuilder();
194 sb.AppendLine(
"BodyOnly: 1");
197 sb.AppendLine(
"AllowScriptTag: 1");
204 if (!(this.document is
null))
226 Variables.OnPreview -= Preview;
243 Expression Script = this.BuildExpression(Rows);
245 object Result = await this.Evaluate(Script,
Variables);
263 Expression Script = this.BuildExpression(Rows);
265 object Result = await this.Evaluate(Script,
Variables);
267 await
Renderer.RenderObject(Result,
true);
283 Expression Script = this.BuildExpression(Rows);
285 object Result = await this.Evaluate(Script,
Variables);
303 Expression Script = this.BuildExpression(Rows);
305 object Result = await this.Evaluate(Script,
Variables);
323 Expression Script = this.BuildExpression(Rows);
325 object Result = await this.Evaluate(Script,
Variables);
343 Expression Script = this.BuildExpression(Rows);
345 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 asynchronous script execution in 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 SessionVariables CreateSessionVariables()
Creates a new collection of variables, that contains access to the global set of variables.
Collection of session 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.