Exemple #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());
        }
Exemple #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());
        }
Exemple #3
0
        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;
        }
Exemple #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());
        }
Exemple #5
0
 private void AddNamed(Paragraph para, IList<CommandNamedParameter> parameters)
 {
     foreach (var p in parameters)
     {
         // TODO - set the spans to not split whitespace
         para.AddSpan(p.Usage);
     }
 }