public static MarkdownConstructor[] GetStaticConstructors(this MarkdownType mdType) { return(mdType.InternalType.GetConstructors(BindingFlags.Public | BindingFlags.Static) .Where(x => x.FilterMemberInfo() && !x.IsPrivate) .Select(mi => new MarkdownConstructor(mi, mi.IsStatic)) .ToArray()); }
public static MarkdownField[] GetStaticFields(this MarkdownType mdType) { return(mdType.InternalType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.GetField | BindingFlags.SetField) .Where(x => !x.IsSpecialName && x.FilterMemberInfo() && !x.IsPrivate) .Select(fi => new MarkdownField(fi, true)) .ToArray()); }
public static MarkdownMethod[] GetMethods(this MarkdownType mdType) { return(mdType.InternalType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.InvokeMethod) .Where(x => !x.IsSpecialName && x.FilterMemberInfo() && !x.IsPrivate) .Select(mi => new MarkdownMethod(mi, false)) .ToArray()); }
public static MarkdownEvent[] GetStaticEvents(this MarkdownType mdType) { return(mdType.InternalType.GetEvents(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) .Where(x => !x.IsSpecialName && x.FilterMemberInfo()) .Select(ei => new MarkdownEvent(ei, true)) .ToArray()); }
private void InitTemplate(IEnvironment environment, MarkdownType markdownType) { if (this._templateDictionary.Any()) { return; } var hyperRefTemp = markdownType == MarkdownType.GithubFlavoredMarkdown ? String.Format( "{0}{1}", "{0}", environment.NewLine) : String.Format( "[{0}](#{1}){2}", "{0}", "{1}", environment.NewLine); this._templateDictionary.Add("href", hyperRefTemp); var classRefTemp = markdownType == MarkdownType.GithubFlavoredMarkdown ? String.Format( "**{0}**{1}", "{0}", environment.NewLine) : String.Format( "[{0}](#{1}){2}", "{0}", "{1}", environment.NewLine); this._templateDictionary.Add("cref", classRefTemp); }
public MarkdownType BuildType(MarkdownType type, MarkdownNamespace namespaceItem, IEnumerable <XmlDocumentComment> comments) { Constants.Logger?.LogTrace("Building Markdown Item for Type {typeName}", type.Name); MarkdownRepo.TryAdd(type); type.NamespaceItem = namespaceItem; type.Summary = comments.FirstOrDefault(x => x.MemberName == type.Name || x.MemberName.StartsWith(type.Name))?.Summary ?? ""; Constants.Logger?.LogTrace("Getting Markdown Fields for Type {typeName}", type.Name); BuildFields(type, comments, type.GetFields().Together(type.GetStaticFields()).ToArray()); Constants.Logger?.LogTrace("Getting Markdown Properties for Type {typeName}", type.Name); BuildProperties(type, comments, type.GetProperties().Together(type.GetStaticProperties()).ToArray()); Constants.Logger?.LogTrace("Getting Markdown Methods for Type {typeName}", type.Name); BuildMethods(type, comments, type.GetMethods().Together(type.GetStaticMethods()).ToArray()); Constants.Logger?.LogTrace("Getting Markdown Events for Type {typeName}", type.Name); BuildEvents(type, comments, type.GetEvents().Together(type.GetStaticEvents()).ToArray()); Constants.Logger?.LogTrace("Getting Markdown Constructors for Type {typeName}", type.Name); BuildConstructors(type, comments, type.GetConstructors().Together(type.GetStaticConstructors()).ToArray()); Constants.Logger?.LogTrace("Completed Building Markdown Type {typeName}", type.Name); return(type); }
private string Convert(string title, Node?resultAnchorNode, MarkdownType markdownType) { string address = ConvertHeaderTitleToLink(title, markdownType); int newNumber = 0; string newAddress = address; if (_anchors.TryGetValue(address, out Anchor? foundAnchor)) { do { if (title != foundAnchor.Title || foundAnchor.Number == 0) { newAddress = $"{newAddress}-1"; newNumber = 1; } else { var number = foundAnchor.Number; newNumber = number + 1; newAddress = $"{newAddress.Remove(newAddress.Length - number.ToString().Length)}{newNumber}"; } } while (_anchors.TryGetValue(newAddress, out foundAnchor)); } if (resultAnchorNode != null) { var result = new Anchor(resultAnchorNode, title, newAddress, newNumber); _anchors.Add(newAddress, result); } return(newAddress); }
public static MarkdownProperty[] GetStaticProperties(this MarkdownType mdType) { return(mdType.InternalType.GetProperties(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.GetProperty | BindingFlags.SetProperty) .Where(x => !x.IsSpecialName && x.FilterMemberInfo()) .Where(y => y.FilterPropertyInfo()) .Select(pi => new MarkdownProperty(pi, true)) .ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="MarkdownNodeParserPool"/> class. /// </summary> /// <param name="environment">The environment.</param> /// <param name = "markdownType">The markdown type.</param> /// <param name = "loggerManager">The logger manager.</param> internal MarkdownNodeParserPool( IEnvironment environment, MarkdownType markdownType, ILoggerManager loggerManager) { this._logger = loggerManager.GetLogger("Parser"); this.InitDictionary(environment, markdownType); }
/// <summary> /// Builds Type Pages with the given MarkdownType Item /// </summary> /// <param name="item">The item to build the page with</param> /// <returns>A string of the markdown content or "" if no page created</returns> public string BuildPage(MarkdownType item) { if (!_options.BuildTypePages) { return(""); } return(_typeBuilder.BuildPage(item)); }
public void BuildConstructors(MarkdownType type, IEnumerable <XmlDocumentComment> comments, MarkdownConstructor[] infos) { Constants.Logger?.LogTrace("Found {itemCount} Markdown Constructors for Type {typeName}", infos.Length, type.Name); foreach (var item in infos) { item.ParentType = type; type.Constructors.Add(item); MarkdownRepo.TryAdd(item); item.Summary = comments.FirstOrDefault(x => ConstructorCommentFilter(x, item))?.Summary ?? ""; } }
//[InlineData(MarkdownType.Habr, MarkdownType.GitHub)] //TODO //[InlineData(MarkdownType.Habr, MarkdownType.Dev)] //TODO public void ShouldConvertDetailsSummary(MarkdownType inMarkdownType, MarkdownType outMarkdownType) { var options = new ProcessorOptions { LinesMaxLength = 0, InputMarkdownType = inMarkdownType, OutputMarkdownType = outMarkdownType }; CompareFiles($"DetailsSummary.{inMarkdownType}.md", $"DetailsSummary.{outMarkdownType}.md", options); }
private void Compare(string inputFileName, string outputFileName, MarkdownType inputKind, MarkdownType outputKind) { var options = new ProcessorOptions { InputMarkdownType = inputKind, OutputMarkdownType = outputKind }; var logger = new Logger(); CompareFiles(inputFileName, outputFileName, options, logger); }
public void BuildProperties(MarkdownType type, IEnumerable <XmlDocumentComment> comments, MarkdownProperty[] infos) { Constants.Logger?.LogTrace("Found {itemCount} Markdown Properties for Type {typeName}", infos.Length, type.Name); foreach (var item in infos) { item.ParentType = type; type.Properties.Add(item); MarkdownRepo.TryAdd(item); item.Summary = comments.FirstOrDefault(x => x.MemberName == item.Name || x.MemberName.StartsWith(item.Name + "`"))?.Summary ?? ""; } }
public void BuildMethods(MarkdownType type, IEnumerable <XmlDocumentComment> comments, MarkdownMethod[] infos) { Constants.Logger?.LogTrace("Found {itemCount} Markdown Comments for Type {typeName}", infos.Length, type.Name); var memberComments = comments.Where(c => c.MemberType == MemberType.Method); foreach (var item in infos) { item.ParentType = type; type.Methods.Add(item); MarkdownRepo.TryAdd(item); item.Summary = memberComments.Where(mc => mc.MemberName == item.InternalItem.GetCommentName()).FirstOrDefault(a => MethodCommentFilter(a, item))?.Summary ?? ""; } }
public MarkdownEnum BuildEnum(MarkdownType type, MarkdownNamespace namespaceItem, IEnumerable <XmlDocumentComment> comments) { Constants.Logger?.LogTrace("Building Markdown Item for Enum {enumName}", type.Name); MarkdownEnum me = new MarkdownEnum(); me.NamespaceItem = namespaceItem; me.InternalType = type.InternalType; me.Comments = comments; me.Summary = comments.FirstOrDefault(x => x.MemberName == me.Name || x.MemberName.StartsWith(me.Name + "`"))?.Summary ?? ""; MarkdownRepo.TryAdd(me); Constants.Logger?.LogTrace("Completed Building Markdown Enum {typeName}", me.Name); return(me); }
private static void SetMarkdownType(IConfiguration configuration) { Console.WriteLine("Setting up markdown type"); var markdownTypeString = configuration["markdownType"]; Console.WriteLine("MarkdownTypeString: {0}", markdownTypeString); Int32 markdownType; if (!Int32.TryParse(markdownTypeString, out markdownType)) { throw new InvalidCastException("The cast for the markdown type did not work"); } Console.WriteLine("MarkdownType: {0}", markdownType); _markdownType = (MarkdownType)markdownType; Console.WriteLine("Markdowntype setup finished"); }
public static string ConvertHeaderTitleToLink(string title, MarkdownType markdownType) { var result = new StringBuilder(title.Length); foreach (char c in title) { var lower = char.ToLowerInvariant(c); if (markdownType == MarkdownType.Habr) { if (lower >= 'a' && lower <= 'z' || lower >= '0' && lower <= '9') { result.Append(lower); } else if (RussianTransliterationMap.TryGetValue(lower, out string?replacement)) { result.Append(replacement); } } else { if (char.IsLetterOrDigit(lower)) { result.Append(lower); } else { if (lower == ' ' || lower == '-') { result.Append('-'); } else if (lower == '_') { result.Append('_'); } } } } return(result.ToString()); }
public string Convert(Node resultAnchorNode, MarkdownType markdownType) { string title; if (markdownType == MarkdownType.Habr) { char headingChar = '#'; if (resultAnchorNode is MarkdownNode markdownNode && markdownNode.MarkdownObject is HeadingBlock headingBlock) { headingChar = headingBlock.HeaderChar; } title = resultAnchorNode.Substring.Trim(headingChar, ' '); } else { title = Markdown.ToPlainText(resultAnchorNode.Substring).Trim(); } return(Convert(title, resultAnchorNode, markdownType)); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionMarkdownNodeParser"/> class. /// </summary> /// <param name="parserPool">The parser pool.</param> /// <param name="environment">The environment.</param> /// <param name="markdownType">The markdown type.</param> public ExceptionMarkdownNodeParser(IParserPool parserPool, IEnvironment environment, MarkdownType markdownType) { this._parserPool = parserPool; this.InitTemplate(environment, markdownType); }
/// <summary> /// Builds the page of a MarkdownType and return the rendered markdown /// </summary> /// <param name="item">The markdown item to be rendered</param> /// <returns>The markdown text</returns> public string BuildPage(MarkdownType item) { DefaultTheme.ThemeLogger?.LogDebug("Building Type Page"); var mb = new MarkdownBuilder(); mb.HeaderWithCode(1, Cleaner.CreateFullTypeWithLinks(item, item.InternalType, false, false)); mb.AppendLine(); item.BuildNamespaceLinks(item.Namespace, mb); if (_options.ShowAssembly) { mb.Append("Assembly: ").AppendLine(item.InternalType.Module.Name).AppendLine(); } bool firstInterface = true; foreach (var interfaceItem in item.InternalType.GetInterfaces()) { if (firstInterface) { firstInterface = false; mb.Append("Implements "); } else { mb.Append(", "); } var link = Cleaner.CreateFullTypeWithLinks(item, interfaceItem, false, false); if (string.IsNullOrEmpty(link)) { mb.Link(Cleaner.CleanName(interfaceItem.Name, false, false), ""); } else { mb.Append(link); } } if (!firstInterface) { mb.AppendLine().AppendLine(); } if (!string.IsNullOrEmpty(item.Summary)) { mb.Header(2, "Summary"); mb.AppendLine(item.Summary); } mb.AppendLine(); var typeZeroHeaders = new[] { "Name", "Summary" }; var typeOneHeaders = new[] { "Type", "Name", "Summary" }; var typeTwoHeaders = new[] { "Return", "Name", "Summary" }; BuildTable(mb, "Static Constructors", item.GetConstructors(true), typeZeroHeaders, item); BuildTable(mb, "Constructors", item.GetConstructors(false), typeZeroHeaders, item); BuildTable(mb, "Fields", item.GetFields(false), typeZeroHeaders, item); BuildTable(mb, "Properties", item.GetProperties(false), typeZeroHeaders, item); BuildTable(mb, "Methods", item.GetMethods(false), typeZeroHeaders, item); BuildTable(mb, "Events", item.GetEvents(false), typeZeroHeaders, item); BuildTable(mb, "Static Fields", item.GetFields(true), typeZeroHeaders, item); BuildTable(mb, "Static Properties", item.GetProperties(true), typeZeroHeaders, item); BuildTable(mb, "Static Methods", item.GetMethods(true), typeZeroHeaders, item); BuildTable(mb, "Static Events", item.GetEvents(true), typeZeroHeaders, item); return(mb.ToString()); }
public void ShouldConvertRelativeLinks(MarkdownType inMarkdownType, MarkdownType outMarkdownType) { Compare($"RelativeLinks.{inMarkdownType}.md", $"RelativeLinks.{outMarkdownType}.md", inMarkdownType, outMarkdownType); }
private static MarkdownNamespace[] LoadDll(string dllPath, string namespaceMatch) { var dllName = Path.GetFileNameWithoutExtension(dllPath); var commentsLookup = GetComments(dllPath, namespaceMatch); var namespaceRegex = !string.IsNullOrEmpty(namespaceMatch) ? new Regex(namespaceMatch) : null; IEnumerable <Type> AssemblyTypesSelector(Assembly x) { try { var types = x.GetExportedTypes(); Constants.Logger?.LogDebug("Loaded {typeCount} Types Successfully", types.Count()); return(types); } catch (ReflectionTypeLoadException ex) { Constants.Logger?.LogWarning("Failed to Load some types in {dllName}", dllName); return(ex.Types.Where(t => t != null)); } catch { Constants.Logger?.LogWarning("Failed to Load any types in {dllName}", dllName); return(Type.EmptyTypes); } } bool NotNullPredicate(Type x) { return(x != null); } bool NamespaceFilterPredicate(Type x) { var _IsRequiredNamespace = IsRequiredNamespace(x, namespaceRegex); return(_IsRequiredNamespace); } MarkdownType markdownableTypeSelector(Type x) { MarkdownType markdownableType = new MarkdownType() { InternalType = x }; return(markdownableType); } bool OthersPredicate(Type x) { var IsPublic = x.IsPublic; var IsAssignableFromDelegate = typeof(Delegate).IsAssignableFrom(x); var HaveObsoleteAttribute = x.GetCustomAttributes <ObsoleteAttribute>().Any(); return(IsPublic && !IsAssignableFromDelegate && !HaveObsoleteAttribute); } var dllAssemblys = new[] { Assembly.LoadFile(dllPath) }; var markdownableTypes = dllAssemblys .SelectMany(AssemblyTypesSelector) .Where(NotNullPredicate) .Where(OthersPredicate) .Where(NamespaceFilterPredicate) .Select(markdownableTypeSelector) .ToArray(); Constants.Logger?.LogDebug("Beginning Building of Markdown Items in {dllName}", dllName); return(new MarkdownTypeBuilder().BuildTypes(markdownableTypes, commentsLookup).ToArray()); }
private void InitTemplate(IEnvironment environment, MarkdownType markdownType) { this._template = markdownType == MarkdownType.GithubFlavoredMarkdown ? String.Format(">**Exception:** *{0}*:{2}> {1}{2}{2}", "{0}", "{1}", environment.NewLine) : String.Format(">**Exception:** [{0}](#{0}):{2}> {1}{2}{2}", "{0}", "{1}", environment.NewLine); }
public string Convert(string address, MarkdownType markdownType) { return(Convert(address, null, markdownType)); }
private void InitDictionary(IEnvironment environment, MarkdownType markdownType) { this._logger.Debug("---- Started initialising of parser dictionary."); this._parserDictionary = new Dictionary <Type, IMarkdownNodeParser>(); this._parserDictionary.Add( typeof(DocMarkdownNodeParser), new DocMarkdownNodeParser( this, environment, this._logger)); this._parserDictionary.Add( typeof(MemberMarkdownNodeParser), new MemberMarkdownNodeParser( this, environment)); this._parserDictionary.Add( typeof(SummaryMarkdownNodeParser), new SummaryMarkdownNodeParser( this, environment)); this._parserDictionary.Add( typeof(ReturnsMarkdownNodeParser), new ReturnsMarkdownNodeParser( this, environment)); this._parserDictionary.Add( typeof(PermissionMarkdownNodeParser), new PermissionMarkdownNodeParser( environment)); this._parserDictionary.Add( typeof(SeeMarkdownNodeParser), new SeeMarkdownNodeParser(environment, markdownType)); this._parserDictionary.Add( typeof(SeealsoMarkdownNodeParser), new SeealsoMarkdownNodeParser(environment, markdownType)); this._parserDictionary.Add(typeof(ParaMarkdownNodeParser), new ParaMarkdownNodeParser(this)); this._parserDictionary.Add( typeof(ListMarkdownNodeParser), new ListMarkdownNodeParser(environment, this, 0)); this._parserDictionary.Add( typeof(TypeparamMarkdownNodeParser), new TypeparamMarkdownNodeParser( this, environment)); this._parserDictionary.Add(typeof(TypeparamrefMarkdownNodeParser), new TypeparamrefMarkdownNodeParser()); this._parserDictionary.Add( typeof(ParamMarkdownNodeParser), new ParamMarkdownNodeParser(this, environment)); this._parserDictionary.Add(typeof(ParamrefMarkdownNodeParser), new ParamrefMarkdownNodeParser()); this._parserDictionary.Add( typeof(ExceptionMarkdownNodeParser), new ExceptionMarkdownNodeParser( this, environment, markdownType)); this._parserDictionary.Add( typeof(CodeMarkdownNodeParser), new CodeMarkdownNodeParser( this, environment)); this._parserDictionary.Add( typeof(ExampleMarkdownNodeParser), new ExampleMarkdownNodeParser( this, environment)); this._parserDictionary.Add( typeof(RemarksMarkdownNodeParser), new RemarksMarkdownNodeParser( this, environment)); this._parserDictionary.Add( typeof(ValueMarkdownNodeParser), new ValueMarkdownNodeParser(environment)); this._logger.Debug("---- Finished initialising of parser dictionary."); }
private void BuildTable(MarkdownBuilder mb, string label, IMarkdownItem[] items, string[] headers, MarkdownType mdType) { if (items.Any()) { mb.Header(2, label); mb.AppendLine(); var seq = items.OrderBy(x => x.Name); List <string[]> data = new List <string[]>(); foreach (var item in seq) { string[] dataValues = new string[headers.Length]; Type lookUpType = null; if (item.ItemType == MarkdownItemTypes.Method) { lookUpType = item.As <MarkdownMethod>().ReturnType; } else if (item.ItemType == MarkdownItemTypes.Constructor) { lookUpType = null; } else { lookUpType = item.As <IMarkdownTypePartValue>().Type; } if (item.ItemType == MarkdownItemTypes.Constructor) { dataValues[0] = Cleaner.CreateFullConstructorsWithLinks(mdType, item.As <MarkdownConstructor>(), false, _options.ShowParameterNames); } else { dataValues[0] = Cleaner.CreateFullTypeWithLinks(mdType, lookUpType, false, false); } string name = item.FullName; string summary = item.Summary; if (item.ItemType == MarkdownItemTypes.Method) { name = Cleaner.CreateFullMethodWithLinks(mdType, item.As <MarkdownMethod>(), false, _options.ShowParameterNames, false); } else if (item.ItemType == MarkdownItemTypes.Property) { name = Cleaner.CreateFullParameterWithLinks(mdType, item.As <MarkdownProperty>(), false, _options.ShowParameterNames); } else if (item.ItemType == MarkdownItemTypes.Constructor) { name = Cleaner.CreateFullConstructorsWithLinks(mdType, item.As <MarkdownConstructor>(), false, _options.BuildConstructorPages); } dataValues[0] = name; if (headers.Length > 1) { dataValues[1] = item.Summary; } data.Add(dataValues); } mb.Table(headers, data, true); mb.AppendLine(); } }
public MarkdownInfo(MarkdownType type, string content = "") { Type = type; Content = content; }
/// <summary> /// Initializes a new instance of the <see cref="SeeMarkdownNodeParser"/> class. /// </summary> /// <param name="environment">The environment.</param> /// <param name = "markdownType">The markdown type.</param> internal SeeMarkdownNodeParser(IEnvironment environment, MarkdownType markdownType) { this.InitTemplate(environment, markdownType); }