public void SingleLineGivesOneParaOneSpan() { const string content = "This is a single line of text with no markup."; var paras = MarkLeft.Parse(content); var expected = new Paragraph(); expected.AddSpan(content); paras.Dump().ShouldBe((new[] { expected }).Dump()); }
public void TwoLinesGivesOneParaOneSpan() { var paras = MarkLeft.Parse(@" This is still one span, but with newlines. "); var expected = new Paragraph(); expected.AddSpan("This is still one span, but with newlines."); paras.Dump().ShouldBe((new[] { expected }).Dump()); }
public static IEnumerable<Paragraph> Parse(string content, ParagraphStyle style = null) { if (string.IsNullOrEmpty(content)) { yield break; } if (style == null) { style = new ParagraphStyle(); } // TODO - this is a HACK! Make this work right! (A blank line should start a new paragraph, for a start) StringBuilder builder = new StringBuilder(); Paragraph para; int returnCount = 0; foreach (var c in content) { switch (c) { case '\n': break; case '\r': returnCount += 1; if (returnCount > 1) { para = new Paragraph(style); para.AddSpan(builder.ToString().Trim()); yield return para; builder.Clear(); } else { builder.Append(' '); } break; default: builder.Append(c); returnCount = 0; break; } } para = new Paragraph(style); para.AddSpan(builder.ToString().Trim()); yield return para; }
public void BlankLineSeparatorGivesTwoParas() { var paras = MarkLeft.Parse(@" One para. Two para. "); var expected1 = new Paragraph(); expected1.AddSpan("One para."); var expected2 = new Paragraph(); expected2.AddSpan("Two para."); paras.Dump().ShouldBe((new[] { expected1, expected2 }).Dump()); }
public Paragraph AddParagraph(Paragraph paragraph) { _paragraphs.Add(paragraph); return paragraph; }