コード例 #1
0
ファイル: TableSpec.cs プロジェクト: Xilium-it/MarkdownDeep
        public List <TableCellDefinition> ParseRow(StringScanner p)
        {
            p.SkipLinespace();

            if (p.eol)
            {
                return(null);                           // Blank line ends the table
            }
            bool bAnyBars = LeadingBar;

            if (LeadingBar && !p.SkipChar('|'))
            {
                return(null);
            }

            // Create the row
            List <TableCellDefinition> row = new List <TableCellDefinition>();

            // Parse all columns except the last
            int totalColSpan = 0;

            while (!p.eol)
            {
                // Build new TableCellDefinition

                var  cell        = new TableCellDefinition();
                bool bAlignLeft  = false;
                bool bAlignRight = false;

                // Check custom cell alignment
                bAlignLeft = p.SkipChar(':');

                // Check custom cell style
                if (p.SkipString("# "))
                {
                    cell.CellStyle = TableCellStyle.TH;
                }

                // Find the next vertical bar
                p.Mark();
                while (!p.eol && p.current != '|')
                {
                    p.SkipForward(1);
                }

                // Check custom cell alignment
                bAlignRight = p.DoesMatch(-2, " :");

                // Get cell content
                cell.Content = p.Extract(0, (bAlignRight ? -2 : 0)).Trim();

                // Get colspan
                bAnyBars |= p.SkipChar('|');
                int colSpan = 1;
                while (p.SkipChar('|'))
                {
                    colSpan++;
                }
                cell.ColSpan  = colSpan;
                totalColSpan += colSpan;

                // Set cell alignment
                if (bAlignLeft && bAlignRight)
                {
                    cell.Alignment = TableCellAlignment.Center;
                }
                else if (bAlignLeft)
                {
                    cell.Alignment = TableCellAlignment.Left;
                }
                else if (bAlignRight)
                {
                    cell.Alignment = TableCellAlignment.Right;
                }

                // Add cell to row
                row.Add(cell);
            }

            // Require at least one bar to continue the table
            if (!bAnyBars)
            {
                return(null);
            }

            // Add missing columns in Columns
            while (Columns.Count < totalColSpan)
            {
                Columns.Add(TableCellAlignment.NA);
            }

            p.SkipEol();
            return(row);
        }
コード例 #2
0
        public List<TableCellDefinition> ParseRow(StringScanner p)
        {
            p.SkipLinespace();

            if (p.eol)
                return null;		// Blank line ends the table

            bool bAnyBars = LeadingBar;
            if (LeadingBar && !p.SkipChar('|'))
            {
                return null;
            }

            // Create the row
            List<TableCellDefinition> row = new List<TableCellDefinition>();

            // Parse all columns except the last
            int totalColSpan = 0;

            while (!p.eol)
            {
                // Build new TableCellDefinition

                var cell = new TableCellDefinition();
                bool bAlignLeft = false;
                bool bAlignRight = false;

                // Check custom cell alignment
                bAlignLeft = p.SkipChar(':');

                // Check custom cell style
                if (p.SkipString("# "))
                    cell.CellStyle = TableCellStyle.TH;

                // Find the next vertical bar
                p.Mark();
                while (!p.eol && p.current != '|')
                    p.SkipForward(1);

                // Check custom cell alignment
                bAlignRight = p.DoesMatch(-2, " :");

                // Get cell content
                cell.Content = p.Extract(0, (bAlignRight ? -2 : 0)).Trim();

                // Get colspan
                bAnyBars |= p.SkipChar('|');
                int colSpan = 1;
                while (p.SkipChar('|')) colSpan++;
                cell.ColSpan = colSpan;
                totalColSpan += colSpan;

                // Set cell alignment
                if (bAlignLeft && bAlignRight)
                    cell.Alignment = TableCellAlignment.Center;
                else if (bAlignLeft)
                    cell.Alignment = TableCellAlignment.Left;
                else if (bAlignRight)
                    cell.Alignment = TableCellAlignment.Right;

                // Add cell to row
                row.Add(cell);
            }

            // Require at least one bar to continue the table
            if (!bAnyBars)
                return null;

            // Add missing columns in Columns
            while (Columns.Count < totalColSpan)
                Columns.Add(TableCellAlignment.NA);

            p.SkipEol();
            return row;
        }