public void TestColumnCount() { var table = new MarkdownTable(new MarkdownTableHeader(3)); Assert.Equal(3, table.ColumnCount); }
private void ProjectiveTables() { MdSparsityTable = new MarkdownTable(); var firstColumn = MdSparsityTable.AddColumn("op", MarkdownTableColumnAlignment.Left); firstColumn.Add("Geometric Product - Multivectors"); firstColumn.Add("Geometric Product - Terms"); firstColumn.Add("Scalar Product - Multivectors"); firstColumn.Add("Scalar Product - Terms"); firstColumn.Add("Left Contraction Product - Multivectors"); firstColumn.Add("Left Contraction Product - Terms"); MdSizeTable = new MarkdownTable(); firstColumn = MdSizeTable.AddColumn("op", MarkdownTableColumnAlignment.Left); firstColumn.Add("Geometric Product - Hash"); firstColumn.Add("Geometric Product - Tree"); firstColumn.Add("Geometric Product - Array"); firstColumn.Add("Geometric Product - Combinations"); firstColumn.Add("Scalar Product - Hash"); firstColumn.Add("Scalar Product - Tree"); firstColumn.Add("Scalar Product - Array"); firstColumn.Add("Scalar Product - Combinations"); firstColumn.Add("Left Contraction Product - Hash"); firstColumn.Add("Left Contraction Product - Tree"); firstColumn.Add("Left Contraction Product - Array"); firstColumn.Add("Left Contraction Product - Combinations"); for (var n = MinVSpaceDimension; n <= MaxVSpaceDimension; n++) { Console.Out.WriteLine("Projective Frame " + n); Frame = GaSymFrame.CreateProjective(n); var sparsityColumn = MdSparsityTable.AddColumn( "n" + n, MarkdownTableColumnAlignment.Right, n.ToString() ); var sizeColumn = MdSizeTable.AddColumn( "n" + n, MarkdownTableColumnAlignment.Right, n.ToString() ); var t = GpHashTableSize(); sparsityColumn.Add(t.Item2.ToString(LongFmt)); sparsityColumn.Add(t.Item3.ToString(LongFmt)); sizeColumn.Add(t.Item1.ToString(LongFmt)); sizeColumn.Add(GpTreeTableSize().ToString(LongFmt)); sizeColumn.Add(GpArrayTableSize().ToString(LongFmt)); sizeColumn.Add(GpCoefSumsTableSize().ToString(LongFmt)); t = SpSparseTableSize(); sparsityColumn.Add(t.Item2.ToString(LongFmt)); sparsityColumn.Add(t.Item3.ToString(LongFmt)); sizeColumn.Add(t.Item1.ToString(LongFmt)); sizeColumn.Add(SpTreeTableSize().ToString(LongFmt)); sizeColumn.Add(SpArrayTableSize().ToString(LongFmt)); sizeColumn.Add(SpCoefSumsTableSize().ToString(LongFmt)); t = LcpHashTableSize(); sparsityColumn.Add(t.Item2.ToString(LongFmt)); sparsityColumn.Add(t.Item3.ToString(LongFmt)); sizeColumn.Add(t.Item1.ToString(LongFmt)); sizeColumn.Add(LcpTreeTableSize().ToString(LongFmt)); sizeColumn.Add(LcpArrayTableSize().ToString(LongFmt)); sizeColumn.Add(LcpCoefSumsTableSize().ToString(LongFmt)); } }
/// <summary> /// Texts the list. /// </summary> /// <param name="items">The items.</param> /// <param name="options">The options.</param> /// <returns>System.String.</returns> public static string TextList(IEnumerable items, TextDumpOptions options) { options ??= new TextDumpOptions(); if (items is IDictionary <string, object> single) { items = new[] { single } } ; var depth = options.Depth; options.Depth += 1; try { var headerStyle = options.HeaderStyle; List <string> keys = null; var table = new MarkdownTable { IncludeRowNumbers = options.IncludeRowNumbers }; foreach (var item in items) { if (item is IDictionary <string, object> d) { if (keys == null) { keys = d.Keys.ToList(); foreach (var key in keys) { table.Headers.Add(ViewUtils.StyleText(key, headerStyle)); } } var row = new List <string>(); foreach (var key in keys) { var value = d[key]; if (ReferenceEquals(value, items)) { break; // Prevent cyclical deps like 'it' binding } if (!isComplexType(value)) { row.Add(GetScalarText(value, options.Defaults)); } else { var cellValue = TextDump(value, options); row.Add(cellValue); } } table.Rows.Add(row); } } var isEmpty = table.Rows.Count == 0; if (isEmpty) { return(options.CaptionIfEmpty ?? string.Empty); } var caption = options.Caption; if (caption != null && !options.HasCaption) { table.Caption = caption; options.HasCaption = true; } var txt = table.Render(); return(txt); } finally { options.Depth = depth; } }
/// <summary>Generates the category section for the members info.</summary> /// <param name="sectionInfoTypes">The section kind.</param> /// <param name="categoryHeader">The category header name.</param> /// <param name="tableName">The table name.</param> /// <param name="settings">The image directory.</param> /// <param name="items">The table row items.</param> /// <returns>The <see cref="string"/>.</returns> private static string GenerateSection(MemberInfoTypes sectionInfoTypes, string categoryHeader, string tableName, ReportSettings settings, List <HierarchyNode> items) { const string DescriptionHeader = "Description"; const string ValuesHeader = "Values"; string basePath; char pathDivider; if (settings.FileRepositoryIsUrl) { pathDivider = Path.AltDirectorySeparatorChar; // Retrieve the trimmed relative path string parentUrl = TextUtil.GetParentUriString(new Uri(settings.ImageRepository)); string relativePath = TextUtil.GetRelativeURIPath(parentUrl, settings.ImageRepository); string formattedPath = relativePath.Substring(1, relativePath.Length - 2); // Formats the path to a url from string basePath = $@"{formattedPath}"; } else { pathDivider = Path.DirectorySeparatorChar; // Return the relative path string dirPath = Path.GetDirectoryName(settings.BuildPath); string relativePath = TextUtil.GetRelativePath(settings.ImageRepository, dirPath); // Format the path to scope into the image directory for retrieving the images from the local system. basePath = $@".\{relativePath}"; } string imageSource = $@"{basePath}{pathDivider}{tableName}{Constants.ImageFilePNGExtension}"; string memberImageText = HtmlUtil.GenerateHTMLImageCode(imageSource, tableName, new Size(16, 16)); // Create the markdown table layout. var columns = new List <string>(); var rows = new List <string>(); // Create the top left section. Add an empty buffer image to keep the table cells at a minimum size to prevent hiding the image cells when during text wrapping. columns.Add(string.Format("<img src={0}file://null{0} width={0}{1}{0} height={0}0{0} alt ={0}{0} />", Constants.Quotes, 64)); columns.Add(tableName); columns.Add(DescriptionHeader); // Determine the member kind. switch (sectionInfoTypes) { case MemberInfoTypes.Class: { // Create section separators. const string sectionSeparators = TableDividerSet0; rows.Add(sectionSeparators); // Create section items content. foreach (HierarchyNode entry in items) { string itemName = entry.Name; string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType); if (string.IsNullOrEmpty(itemDescription)) { itemDescription = MissingDocumentationText; } string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription}"; rows.Add(rowItemName); } break; } case MemberInfoTypes.Delegate: { // Create section separators. const string sectionSeparators = TableDividerSet0; rows.Add(sectionSeparators); // Create section items content. foreach (HierarchyNode entry in items) { string itemName = entry.Name; string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType); if (string.IsNullOrEmpty(itemDescription)) { itemDescription = MissingDocumentationText; } string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription}"; rows.Add(rowItemName); } break; } case MemberInfoTypes.Enumerator: { columns.Add(ValuesHeader); // Create section separators. const string sectionSeparators = TableDividerSet1; rows.Add(sectionSeparators); // Create section items content. foreach (HierarchyNode entry in items) { string itemName = entry.Name; string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType); if (string.IsNullOrEmpty(itemDescription)) { itemDescription = MissingDocumentationText; } string enumValues = TypesUtil.GetEnumeratorValues(entry.NodeType); string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription} {MarkdownSeparator} {enumValues}."; rows.Add(rowItemName); } break; } case MemberInfoTypes.Structure: { // Create section separators. const string sectionSeparators = TableDividerSet0; rows.Add(sectionSeparators); // Create section items content. foreach (HierarchyNode entry in items) { string itemName = entry.Name; string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType); if (string.IsNullOrEmpty(itemDescription)) { itemDescription = MissingDocumentationText; } string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription}"; rows.Add(rowItemName); } break; } case MemberInfoTypes.Interface: { // Create section separators. const string sectionSeparators = TableDividerSet0; rows.Add(sectionSeparators); // Create section items content. foreach (HierarchyNode entry in items) { string itemName = entry.Name; string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType); if (string.IsNullOrEmpty(itemDescription)) { itemDescription = MissingDocumentationText; } string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription}"; rows.Add(rowItemName); } break; } default: { throw new ArgumentOutOfRangeException(nameof(sectionInfoTypes), sectionInfoTypes, null); } } // Generate markdown table. StringBuilder sectionBuilder = new StringBuilder(); // Create the header. sectionBuilder.AppendLine(MarkdownHeader.CreateHeader(categoryHeader, 3)); // Create the table. string table = new MarkdownTable(columns, rows).MarkdownContentText; sectionBuilder.Append(table); return(sectionBuilder.ToString()); }
private static void Main(string[] args) { if (!Parser.TryParse(args, out s_options, new ParserOptions() { VariableNamePrefix = ParserPrefix })) { return; } if (s_options.CookieToken == null) { Colorizer.WriteLine($"[Red!Error]: Please specify authentication token as an argument or in the environment variable [Yellow!{ParserPrefix}_token]"); return; } FabricBotClient rs = new FabricBotClient(s_options.Owner, s_options.Repo, s_options.CookieToken); IssueRoutingCapability irc = new IssueRoutingCapability(s_options.Owner, s_options.Repo); string payload = string.Empty; if (s_options.Action == ActionToTake.create || s_options.Action == ActionToTake.update) { Colorizer.Write("Parsing service table... "); MarkdownTable table = MarkdownTable.Parse(s_options.ServicesFile); Colorizer.WriteLine("[Green!done]."); foreach (var row in table.Rows) { if (!string.IsNullOrEmpty(row[2].Trim())) { // the row at position 0 is the label to use on top of 'Service Attention' string[] labels = new string[] { "Service Attention", row[0] }; // The row at position 2 is the set of mentionees to ping on the issue. IEnumerable <string> mentionees = row[2].Split(',').Select(x => x.Replace("@", "").Trim()); //add the service irc.AddService(labels, mentionees); } } payload = irc.ToJson(); Colorizer.WriteLine("Found [Yellow!{0}] service routes.", irc.RouteCount); } if (s_options.Prompt) { Colorizer.WriteLine("Proceed with [Cyan!{0}] for repo [Yellow!{1}\\{2}] (y/n)? ", s_options.Action, s_options.Owner, s_options.Repo); var key = Console.ReadKey(); if (key.Key != ConsoleKey.Y) { Colorizer.WriteLine("No action taken."); return; } } try { switch (s_options.Action) { case ActionToTake.create: rs.CreateTask(payload); break; case ActionToTake.update: rs.UpdateTask(IssueRoutingCapability.GetTaskId(s_options.Owner, s_options.Repo), payload); break; case ActionToTake.delete: rs.DeleteTask(s_options.TaskId); break; case ActionToTake.deleteall: rs.DeleteAll(); break; case ActionToTake.listTaskIds: var taskIds = rs.GetTaskIds(); foreach (string item in taskIds) { Colorizer.WriteLine("Found task with id: [Yellow!{0}]", item); } break; default: Colorizer.WriteLine($"[Red!Error]: Command [Yellow!{s_options.Action}] unknown."); return; } Colorizer.WriteLine("[Green!Done]."); } catch (Exception e) { Colorizer.WriteLine("[Red!Error]: {0}", e.Message); } }
public void ConvertToAlignmentString_IllegalAlignmentValue_ThrowArgumentOutOfRangeException() { MarkdownTable.ConvertToAlignmentString((PrintableDataRowAlignment)99); }
public void AddHeader_AfterRowsHaveBeenAdded_ShouldThrowNotSupportedException() { IPrintableParagraphTable table = new MarkdownTable(); table.WithRow("b", "c").WithHeader("a"); }
public void AddRow_WithOneHeaderAndOneDataRowWithTwoHeaders_ShouldThrowIndexOutOfRangeException() { IPrintableParagraphTable table = new MarkdownTable(); table.WithHeader("a").WithRow("b", "c"); }