MarkdownDeep.TableSpec.ParseRow C# (CSharp) Method

ParseRow() public method

public ParseRow ( StringScanner p ) : List
p StringScanner
return List
        public List<string> 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<string> row = new List<string>();

            // Parse all columns except the last

            while (!p.Eol)
            {
                // Find the next vertical bar
                p.Mark();
                while (!p.Eol && p.Current != '|')
                    p.SkipEscapableChar(true);

                row.Add(p.Extract().Trim());

                bAnyBars|=p.SkipChar('|');
            }

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

            // Add missing columns
            while (row.Count < Columns.Count)
            {
                row.Add("&nbsp;");
            }

            p.SkipEol();
            return row;
        }

Usage Example

		internal bool StartTable(TableSpec spec, List<Block> lines)
		{
			// Mustn't have more than 1 preceeding line
			if (lines.Count > 1)
				return false;

			// Rewind, parse the header row then fast forward back to current pos
			if (lines.Count == 1)
			{
				int savepos = position;
				position = lines[0].lineStart;
				spec.Headers = spec.ParseRow(this);
				if (spec.Headers == null)
					return false;
				position = savepos;
				lines.Clear();
			}

			// Parse all rows
			while (true)
			{
				int savepos = position;

				var row = spec.ParseRow(this);
				if (row != null)
				{
					spec.Rows.Add(row);
					continue;
				}

				position = savepos;
				break;
			}

			return true;
		}
All Usage Examples Of MarkdownDeep.TableSpec::ParseRow