private static void Init() { List <ICodeContent> CodeContents = new List <ICodeContent>(); TypeInfo TI; foreach (Type T in Types.GetTypesImplementingInterface(typeof(ICodeContent))) { TI = T.GetTypeInfo(); if (TI.IsAbstract || TI.IsGenericTypeDefinition) { continue; } try { ICodeContent CodeContent = (ICodeContent)Activator.CreateInstance(T); CodeContents.Add(CodeContent); } catch (Exception ex) { Log.Critical(ex); } } lock (handlers) { codeContents = CodeContents.ToArray(); handlers.Clear(); } }
private static ICodeContent GetHandler(string Language) { ICodeContent[] Handlers; if (string.IsNullOrEmpty(Language)) { return(null); } lock (handlers) { if (!handlers.TryGetValue(Language, out Handlers)) { List <ICodeContent> List = new List <ICodeContent>(); foreach (ICodeContent Content in codeContents) { if (Content.Supports(Language) > Grade.NotAtAll) { List.Add(Content); } } if (List.Count > 0) { Handlers = List.ToArray(); } else { Handlers = null; } handlers[Language] = Handlers; } } if (Handlers is null) { return(null); } ICodeContent Best = null; Grade BestGrade = Grade.NotAtAll; Grade ContentGrade; foreach (ICodeContent Content in Handlers) { ContentGrade = Content.Supports(Language); if (ContentGrade > BestGrade) { BestGrade = ContentGrade; Best = Content; } } return(Best); }
/// <summary> /// Represents a code block in a markdown document. /// </summary> /// <param name="Document">Markdown document.</param> /// <param name="Rows">Rows</param> /// <param name="Start">Start index of code.</param> /// <param name="End">End index of code.</param> /// <param name="Indent">Additional indenting.</param> /// <param name="Language">Language used.</param> public CodeBlock(MarkdownDocument Document, string[] Rows, int Start, int End, int Indent, string Language) : base(Document) { this.rows = Rows; this.start = Start; this.end = End; this.indent = Indent; this.indentString = this.indent <= 0 ? string.Empty : new string('\t', this.indent); this.language = Language; this.handler = GetHandler(this.language); }