public static TableBlock TryParse(CreoleReader reader) { if (reader.Peek(1) != "|") return null; bool isFirstLine = true; string[] headers = null; List<string[]> rows = new List<string[]>(); while (!reader.EndOfMarkup) { var line = reader.PeekLine().TrimEnd(); if (!line.StartsWith("|")) break; var split = line.Substring(1).Split(new char[] { '|' }, StringSplitOptions.None); if (string.IsNullOrEmpty(split.Last().Trim())) split = split.Take(split.Count() - 1).ToArray(); if (isFirstLine && !split.Any(p => !p.StartsWith("="))) headers = split.Select(p => p.Substring(1)).ToArray(); else rows.Add(split); reader.ReadLine(); isFirstLine = false; } return new TableBlock(headers, rows.ToArray()); }
public static HorizontalLineBlock TryParse(CreoleReader reader) { var line = reader.PeekLine().Trim(); if (!line.StartsWith("----")) return null; if (line.Any(c => c != '-')) return null; reader.SkipLine(); return new HorizontalLineBlock(); }
public static HeadingBlock TryParse(CreoleReader reader) { var line = reader.PeekLine().Trim(); if (!line.StartsWith("=")) return null; var level = 0; for (level = 1; level < 6; level++) if (line[level] != '=') break; var endIndex = 0; for (endIndex = line.Length - 1; endIndex >= line.Length - level; endIndex--) if (line[endIndex] != '=') break; reader.SkipLine(); var content = line.Substring(level, endIndex - (level - 1)); return new HeadingBlock(level, content); }