Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MarkdownEncode.cs
1using System;
2using System.Threading.Tasks;
3using Waher.Script;
7
9{
14 {
24 {
25 }
26
30 public override string FunctionName => nameof(MarkdownEncode);
31
39 {
40 return new StringValue(EscapeText(Argument));
41 }
42
50 {
51 return new StringValue(EscapeText(Argument.AssociatedObjectValue?.ToString() ?? string.Empty));
52 }
53
60 public override Task<IElement> EvaluateScalarAsync(IElement Argument, Variables Variables)
61 {
62 return Task.FromResult(this.EvaluateScalar(Argument, Variables));
63 }
64
70 public static string EscapeText(string PlainText)
71 {
72 return CommonTypes.Escape(PlainText, specialCharacters, specialCharactersEncoded);
73 }
74
75 private static readonly char[] specialCharacters = new char[]
76 {
77 '*', '_', '~', '\\', '`', '{', '}', '[', ']', '(', ')', '<', '>', '&', '#', '+', '-', '.', '!', '"', '\'', '^', '%', '=', ':', '|'
78 };
79
80 private static readonly string[] specialCharactersEncoded = new string[]
81 {
82 "\\*", "\\_", "\\~", "\\\\", "\\`", "\\{", "\\}", "\\[", "\\]", "\\(", "\\)", "\\<", "\\>", "\\&",
83 "\\#", "\\+", "\\-", "\\.", "\\!", "\\\"", "\\'", "\\^", "\\%", "\\=", "\\:", "&#124;"
84 };
85
86 }
87}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string Escape(string s, char[] CharactersToEscape, string EscapeSequence)
Escapes a set of characters in a string.
Definition: CommonTypes.cs:828
override Task< IElement > EvaluateScalarAsync(IElement Argument, Variables Variables)
Evaluates the function on a scalar argument.
MarkdownEncode(ScriptNode Argument, int Start, int Length, Expression Expression)
MarkdownEncode(x)
static string EscapeText(string PlainText)
Escapes text for inclusion in a Markdown document.
override IElement EvaluateScalar(IElement Argument, Variables Variables)
Evaluates the function on a scalar argument.
override string FunctionName
Name of the function
override IElement EvaluateScalar(string Argument, Variables Variables)
Evaluates the function on a scalar argument.
Class managing a script expression.
Definition: Expression.cs:39
Base class for funcions of one scalar string variable.
ScriptNode Argument
Function argument.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20