2using System.Collections.Generic;
3using System.Reflection;
4using System.Threading.Tasks;
18 private Type handlerType =
null;
19 private readonly
string[] rows;
20 private readonly
string indentString;
21 private readonly
string language;
22 private readonly
int start, end, indent;
53 this.indentString = this.indent <= 0 ? string.Empty :
new string(
'\t', this.indent);
65 public string[]
Rows => this.rows;
73 if (this.handlerType is
null || this.handlerType != typeof(T))
76 this.handlerType = typeof(T);
79 return (T)this.handler;
83 private readonly
static Dictionary<Type, Dictionary<string, ICodeContentRenderer[]>> codeContentHandlers =
new Dictionary<Type, Dictionary<string, ICodeContentRenderer[]>>();
84 private readonly
static Dictionary<string, IXmlVisualizer[]> xmlVisualizerHandlers =
new Dictionary<string, IXmlVisualizer[]>(StringComparer.CurrentCultureIgnoreCase);
89 Types.OnInvalidated += (Sender, e) => Init();
92 private static void Init()
94 List<ICodeContentRenderer> CodeContents =
new List<ICodeContentRenderer>();
95 List<IXmlVisualizer> XmlVisualizers =
new List<IXmlVisualizer>();
106 CodeContents.Add(CodeContent);
123 XmlVisualizers.Add(XmlVisualizer);
131 lock (codeContentHandlers)
133 codeContentHandlers.Clear();
136 lock (xmlVisualizerHandlers)
138 xmlVisualizers = XmlVisualizers.ToArray();
139 xmlVisualizerHandlers.Clear();
143 internal static T GetCodeBlockHandler<T>(
string Language,
bool AllowScript)
151 lock (codeContentHandlers)
153 if (!codeContentHandlers.TryGetValue(typeof(T), out Dictionary<
string,
ICodeContentRenderer[]> PerLanguage))
155 PerLanguage =
new Dictionary<string, ICodeContentRenderer[]>();
156 codeContentHandlers[typeof(T)] = PerLanguage;
159 if (!PerLanguage.TryGetValue(
Language, out Handlers))
161 List<ICodeContentRenderer> List =
new List<ICodeContentRenderer>();
173 List.Add(CodeContent);
182 Handlers = List.ToArray();
190 if (Handlers is
null)
200 if (ContentGrade > BestGrade && Content is T TypedContent && (AllowScript || !Content.
EvaluatesScript))
202 BestGrade = ContentGrade;
210 internal static IXmlVisualizer GetXmlVisualizerHandler(XmlDocument Xml)
212 if (Xml is
null || Xml.DocumentElement is
null)
215 IXmlVisualizer[] Handlers;
216 string Key = Xml.DocumentElement.NamespaceURI +
"#" + Xml.DocumentElement.LocalName;
218 lock (xmlVisualizerHandlers)
220 if (!xmlVisualizerHandlers.TryGetValue(Key, out Handlers))
222 List<IXmlVisualizer> List =
new List<IXmlVisualizer>();
224 foreach (IXmlVisualizer Visualizer
in xmlVisualizers)
226 if (Visualizer.Supports(Xml) >
Grade.NotAtAll)
227 List.Add(Visualizer);
231 Handlers = List.ToArray();
235 xmlVisualizerHandlers[Key] = Handlers;
239 if (Handlers is
null)
242 IXmlVisualizer Best =
null;
244 Grade VisualizerGrade;
246 foreach (IXmlVisualizer Visualizer
in Handlers)
248 VisualizerGrade = Visualizer.Supports(Xml);
249 if (VisualizerGrade > BestGrade)
251 BestGrade = VisualizerGrade;
288 public int End => this.end;
299 this.indent == x.indent &&
300 this.indentString == x.indentString &&
301 this.language == x.language &&
303 base.SameMetaData(E);
314 this.indent == x.indent &&
315 this.indentString == x.indentString &&
316 this.language == x.language &&
327 int h1 = base.GetHashCode();
328 int h2 = this.indent.GetHashCode();
330 h1 = ((h1 << 5) + h1) ^ h2;
331 h2 = this.indentString?.GetHashCode() ?? 0;
333 h1 = ((h1 << 5) + h1) ^ h2;
334 h2 = this.language?.GetHashCode() ?? 0;
336 h1 = ((h1 << 5) + h1) ^ h2;
339 h1 = ((h1 << 5) + h1) ^ h2;
Contains a markdown document. This markdown document class supports original markdown,...
MarkdownSettings Settings
Markdown settings.
bool AllowInlineScript
If inline script is allowed embedded in the Markdown.
Contains some basic statistical information about a Markdown document.
int NrCodeBlocks
Number of code blocks.
Abstract base class for block elements.
Represents a code block in a markdown document.
string IndentString
String used for indentation.
CodeBlock(MarkdownDocument Document, string[] Rows, int Start, int End, int Indent, string Language)
Represents a code block in a markdown document.
override bool InlineSpanElement
If the element is an inline span element.
override int GetHashCode()
Serves as the default hash function.
override Task Render(IRenderer Output)
Renders the element.
int Indent
Code block indentation.
override bool SameMetaData(MarkdownElement E)
If the current object has same meta-data as E (but not necessarily same content).
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
T CodeContentHandler< T >()
Multimedia handler.
override void IncrementStatistics(MarkdownStatistics Statistics)
Increments the property or properties in Statistics corresponding to the element.
CodeBlock(MarkdownDocument Document, string[] Rows, int Start, int End, int Indent)
Represents a code block in a markdown document.
string[] Rows
Rows in code block
Abstract base class for all markdown elements.
MarkdownDocument Document
Markdown document.
static bool AreEqual(Array Items1, Array Items2)
Checks if two typed arrays are equal
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 class that dynamically manages types and interfaces available in the runtime environment.
static object[] NoParameters
Contains an empty array of parameter values.
static Type[] GetTypesImplementingInterface(string InterfaceFullName)
Gets all types implementing a given interface.
static ConstructorInfo GetDefaultConstructor(Type Type)
Gets the default constructor of a type, if one exists.
Interface for all markdown handlers of code content.
bool EvaluatesScript
If script is evaluated for this type of code block.
Grade Supports(string Language)
Checks how well the handler supports code content of a given type.
Interface for all XML visalizers.
Interface for code content renderers.
Interface for Markdown renderers.