示例#1
0
        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());
        }
示例#2
0
        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());
        }
示例#3
0
文件: MarkLeft.cs 项目: cj525/yaclops
        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;
        }
示例#4
0
        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());
        }
示例#5
0
文件: Document.cs 项目: cj525/yaclops
 public Paragraph AddParagraph(Paragraph paragraph)
 {
     _paragraphs.Add(paragraph);
     return paragraph;
 }