Пример #1
0
        public MarkdownBuilder AppendTable(TableHeaderCollection headers, TableRowCollection rows)
        {
            int columnCount = headers.Count;

            if (columnCount == 0)
            {
                return(this);
            }

            if (!FormatTableContent)
            {
                AppendTableHeader(headers, columnCount);
                AppendTableRows(rows, columnCount);
            }
            else
            {
                bool formatHeader = FormatTableHeader;

                List <int> widths = CalculateWidths((formatHeader) ? headers : null, rows, columnCount);

                AppendTableHeader(headers, columnCount, (formatHeader) ? widths : null);
                AppendTableRows(rows, columnCount, widths);
            }

            return(this);
        }
Пример #2
0
        private List <int> CalculateWidths(TableHeaderCollection headers, TableRowCollection rows, int columnCount)
        {
            var widths = new List <int>();

            int index = 0;

            var mb = new MarkdownBuilder(Settings);

            if (headers != null)
            {
                foreach (TableHeader header in headers)
                {
                    mb.Append(header.Name);
                    widths.Add(mb.Length - index);
                    index = mb.Length;
                }
            }

            foreach (TableRow row in rows)
            {
                for (int i = 0; i < row.Count; i++)
                {
                    mb.Append(row[i]);
                    widths.Add(mb.Length - index);
                    index = mb.Length;
                }
            }

            int count = widths.Count;

            var maxWidths = new List <int>();

            for (int i = 0; i < columnCount; i++)
            {
                maxWidths.Add(0);

                for (int j = i; j < count; j += columnCount)
                {
                    maxWidths[i] = Math.Max(maxWidths[i], widths[j]);
                }
            }

            return(maxWidths);
        }