예제 #1
0
        public void TestCanProduceTable()
        {
            var table = new Table
            {
                Columns = new[]
                {
                    new TableColumn{HeaderCell = new TableCell {Text = "Year"}},
                    new TableColumn{HeaderCell = new TableCell {Text = "Album"}},
                    new TableColumn{HeaderCell = new TableCell {Text = "Song Count"}},
                    new TableColumn{HeaderCell = new TableCell {Text = "Rating"}}
                },
                Rows = new[]
                {
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "1991"},
                            new TableCell {Text = "Out of Time"},
                            new TableCell {Text = "11"},
                            new TableCell {Text = "* * * *"}
                        }
                    },
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "1992"},
                            new TableCell {Text = "Automatic for the People"},
                            new TableCell {Text = "12"},
                            new TableCell {Text = "* * * * *"}
                        }
                    },
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "1994"},
                            new TableCell {Text = "Monster"},
                            new TableCell {Text = "12"},
                            new TableCell {Text = "* * *"}
                        }
                    }
                }
            };

            table.AssertOutputEquals(
                "     Year | Album                    | Song Count | Rating   \r\n" +
                "     ---- | ------------------------ | ---------- | --------- \r\n" +
                "     1991 | Out of Time              | 11         | * * * *  \r\n" +
                "     1992 | Automatic for the People | 12         | * * * * *\r\n" +
                "     1994 | Monster                  | 12         | * * *    \r\n"
                ,
                "<pre><code> Year | Album                    | Song Count | Rating   \n" +
                " ---- | ------------------------ | ---------- | --------- \n" +
                " 1991 | Out of Time              | 11         | * * * *  \n" +
                " 1992 | Automatic for the People | 12         | * * * * *\n" +
                " 1994 | Monster                  | 12         | * * *    \n" +
                "</code></pre>\n");
        }
예제 #2
0
            internal MarkdownBuilder(Table table)
            {
                _columns = table.Columns.ToList();
                _rows = table.Rows.Select(row => new Row {Cells = row.Cells.ToList()}).ToList();

                var columnCount = Math.Max(_columns.Count, _rows.Any() ? _rows.Max(r => r.Cells.Count) : 0);
                _columnRenderSpecs = Enumerable.Range(0, columnCount).Select(BuildColumnSpecification).ToList();
            }
예제 #3
0
 public static void Write(string mdFileName, MarkdownLog.Table mdTable)
 {
     using (var stream = new FileStream(mdFileName, FileMode.Create))
     {
         using (var sw = new StreamWriter(stream))
         {
             sw.Write(ToTrimmedTable(mdTable));
         }
     }
 }
예제 #4
0
        public static string ToTrimmedTable(MarkdownLog.Table mdTable)
        {
            using (var sr = new StringReader(mdTable.ToMarkdown()))
            {
                string line;
                var    sb = new StringBuilder();

                while ((line = sr.ReadLine()) != null)
                {
                    line = line.TrimStart(' ');
                    line = !line.StartsWith(":") ? $" {line}" : line;
                    sb.AppendLine(line);
                }

                return(sb.ToString());
            }
        }
예제 #5
0
        public void TestColumnContentsCanBeAligned()
        {
            var table = new Table
            {
                Columns = new[]
                {
                    new TableColumn{HeaderCell = new TableCell {Text = "Animal"}, Alignment = TableColumnAlignment.Left},
                    new TableColumn{HeaderCell = new TableCell {Text = "Good Pet?"},Alignment = TableColumnAlignment.Center},
                    new TableColumn{HeaderCell = new TableCell {Text = "Lifespan (years)"}, Alignment = TableColumnAlignment.Right}
                },
                Rows = new[]
                {
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "Cat"},
                            new TableCell {Text = "[X]"},
                            new TableCell {Text = "14"}
                        }
                    },
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "Mouse"},
                            new TableCell {Text = "[X]"},
                            new TableCell {Text = "2"}
                        }
                    },
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "Elephant"},
                            new TableCell {Text = "[ ]"},
                            new TableCell {Text = "65"}
                        }
                    }
                }
            };

            table.AssertOutputEquals(
                "     Animal   | Good Pet? | Lifespan (years)\r\n" +
                "    :-------- |:---------:| ----------------:\r\n" +
                "     Cat      |    [X]    |               14\r\n" +
                "     Mouse    |    [X]    |                2\r\n" +
                "     Elephant |    [ ]    |               65\r\n");
        }
예제 #6
0
        public void TestHeadersAreAutomaticallyAddedIfNotSpecified()
        {
            var table = new Table
            {
                Rows = new[]
                {
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "Avatar"},
                            new TableCell {Text = "2009"},
                            new TableCell {Text = "$2,782,275,172"}
                        }
                    },
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "Titanic"},
                            new TableCell {Text = "1997"},
                            new TableCell {Text = "$2,186,772,302"}
                        }
                    },
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "The Avengers"},
                            new TableCell {Text = "2012"},
                            new TableCell {Text = "$1,518,594,910"}
                        }
                    }
                }
            };

            table.AssertOutputEquals(
                "     A            | B    | C             \r\n" +
                "     ------------ | ---- | -------------- \r\n" +
                "     Avatar       | 2009 | $2,782,275,172\r\n" +
                "     Titanic      | 1997 | $2,186,772,302\r\n" +
                "     The Avengers | 2012 | $1,518,594,910\r\n");
        }
예제 #7
0
        public void TestCanProduceTable()
        {
            var table = new Table
            {
                Columns = new[]
                {
                    new TableColumn{HeaderCell = new TableCell {Text = "Year"}},
                    new TableColumn{HeaderCell = new TableCell {Text = "Album"}},
                    new TableColumn{HeaderCell = new TableCell {Text = "Song Count"}},
                    new TableColumn{HeaderCell = new TableCell {Text = "Rating"}}
                },
                Rows = new[]
                {
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "1991"},
                            new TableCell {Text = "Out of Time"},
                            new TableCell {Text = "11"},
                            new TableCell {Text = "* * * *"}
                        }
                    },
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "1992"},
                            new TableCell {Text = "Automatic for the People"},
                            new TableCell {Text = "12"},
                            new TableCell {Text = "* * * * *"}
                        }
                    },
                    new TableRow
                    {
                        Cells = new[]
                        {
                            new TableCell {Text = "1994"},
                            new TableCell {Text = "Monster"},
                            new TableCell {Text = "12"},
                            new TableCell {Text = "* * *"}
                        }
                    }
                }
            };

            table.AssertOutputEquals(
                "     Year | Album                    | Song Count | Rating   \r\n" +
                "     ---- | ------------------------ | ---------- | --------- \r\n" +
                "     1991 | Out of Time              | 11         | * * * *  \r\n" +
                "     1992 | Automatic for the People | 12         | * * * * *\r\n" +
                "     1994 | Monster                  | 12         | * * *    \r\n"
                ,
                "<table>\n" +
                "<thead>\n" +
                "<tr>\n" +
                "	<th>Year</th>\n" +
                "	<th>Album</th>\n" +
                "	<th>Song Count</th>\n" +
                "	<th>Rating</th>\n" +
                "</tr>\n" +
                "</thead>\n" +
                "<tbody>\n" +
                "<tr>\n" +
                "	<td>1991</td>\n" +
                "	<td>Out of Time</td>\n" +
                "	<td>11</td>\n" +
                "	<td>* * * *</td>\n" +
                "</tr>\n" +
                "<tr>\n" +
                "	<td>1992</td>\n" +
                "	<td>Automatic for the People</td>\n" +
                "	<td>12</td>\n" +
                "	<td>* * * * *</td>\n" +
                "</tr>\n" +
                "<tr>\n" +
                "	<td>1994</td>\n" +
                "	<td>Monster</td>\n" +
                "	<td>12</td>\n" +
                "	<td>* * *</td>\n" +
                "</tr>\n" +
                "</tbody>\n" +
                "</table>\n");
        }