3using System.Reflection;
4using System.Threading.Tasks;
19 private Type handlerType =
null;
20 private readonly
string[] rows;
21 private readonly
string indentString;
22 private readonly
string language;
23 private readonly
int start, end, indent;
66 public string[]
Rows => this.rows;
74 if (this.handlerType is
null || this.handlerType != typeof(T))
77 this.handlerType = typeof(T);
80 return (T)this.handler;
84 private readonly
static Dictionary<Type, Dictionary<string, ICodeContentRenderer[]>> codeContentHandlers =
new Dictionary<Type, Dictionary<string, ICodeContentRenderer[]>>();
85 private readonly
static Dictionary<string, IXmlVisualizer[]> xmlVisualizerHandlers =
new Dictionary<string, IXmlVisualizer[]>(StringComparer.CurrentCultureIgnoreCase);
90 Types.OnInvalidated += (Sender, e) => Init();
93 private static void Init()
107 CodeContents.
Add(CodeContent);
124 XmlVisualizers.
Add(XmlVisualizer);
132 lock (codeContentHandlers)
134 codeContentHandlers.Clear();
137 lock (xmlVisualizerHandlers)
139 xmlVisualizers = XmlVisualizers.
ToArray();
140 xmlVisualizerHandlers.Clear();
144 internal static T GetCodeBlockHandler<T>(
string Language,
bool AllowScript)
152 lock (codeContentHandlers)
154 if (!codeContentHandlers.TryGetValue(typeof(T), out Dictionary<
string,
ICodeContentRenderer[]> PerLanguage))
156 PerLanguage =
new Dictionary<string, ICodeContentRenderer[]>();
157 codeContentHandlers[typeof(T)] = PerLanguage;
160 if (!PerLanguage.TryGetValue(
Language, out Handlers))
174 List.
Add(CodeContent);
191 if (Handlers is
null)
201 if (ContentGrade > BestGrade && Content is T TypedContent && (AllowScript || !Content.
EvaluatesScript))
203 BestGrade = ContentGrade;
218 if (Xml is
null || Xml.DocumentElement is
null)
222 string Key = Xml.DocumentElement.NamespaceURI +
"#" + Xml.DocumentElement.LocalName;
224 lock (xmlVisualizerHandlers)
226 if (!xmlVisualizerHandlers.TryGetValue(Key, out Handlers))
233 List.
Add(Visualizer);
241 xmlVisualizerHandlers[Key] = Handlers;
245 if (Handlers is
null)
250 Grade VisualizerGrade;
254 VisualizerGrade = Visualizer.
Supports(Xml);
255 if (VisualizerGrade > BestGrade)
257 BestGrade = VisualizerGrade;
294 public int End => this.end;
305 this.indent == x.indent &&
306 this.indentString == x.indentString &&
307 this.language == x.language &&
309 base.SameMetaData(E);
320 this.indent == x.indent &&
321 this.indentString == x.indentString &&
322 this.language == x.language &&
333 int h1 = base.GetHashCode();
334 int h2 = this.indent.GetHashCode();
336 h1 = ((h1 << 5) + h1) ^ h2;
337 h2 = this.indentString?.GetHashCode() ?? 0;
339 h1 = ((h1 << 5) + h1) ^ h2;
340 h2 = this.language?.GetHashCode() ?? 0;
342 h1 = ((h1 << 5) + h1) ^ h2;
345 h1 = ((h1 << 5) + h1) ^ h2;
Helps with common JSON-related tasks.
static string IndentString(int NrTabs)
Gets an indentation string consisting of a number of tab characters. Strings are caches and reused to...
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.
static IXmlVisualizer GetXmlVisualizerHandler(XmlDocument Xml)
Gets the best XML Visualizer for a given XML document.
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.
A chunked list is a linked list of chunks of objects of type T .
int Count
Number of elements in collection.
void Add(T Item)
Adds an item to the collection.
T[] ToArray()
Returns an array containing all elements of the collection.
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.
Grade Supports(T Object)
If the interface understands objects such as Object .