Example #1
0
        public void TestStringLineGroupWithModifiedStart()
        {
            var line1 = new StringSlice("  ABC");

            line1.NextChar();
            line1.NextChar();

            var line2 = new StringSlice("  DEF ");

            line2.Trim();

            var text = new StringLineGroup(4)
            {
                line1, line2
            };

            var result = ToString(text.ToCharIterator());

            TextAssert.AreEqual("ABC\nDEF", result);
        }
Example #2
0
        public void TestStringLineGroupWithSlices()
        {
            var text = new StringLineGroup(4)
            {
                new StringSlice("XABC")
                {
                    Start = 1
                },
                new StringSlice("YYE")
                {
                    Start = 2
                },
                new StringSlice("ZZZF")
                {
                    Start = 3
                }
            };

            var chars = ToString(text.ToCharIterator());

            TextAssert.AreEqual("ABC\nE\nF", chars.ToString());
        }
        private bool TryMatchLinkReferenceDefinition(ref StringLineGroup lines, BlockProcessor state)
        {
            bool atLeastOneFound = false;

            while (true)
            {
                // If we have found a LinkReferenceDefinition, we can discard the previous paragraph
                var iterator = lines.ToCharIterator();
                LinkReferenceDefinition linkReferenceDefinition;
                if (LinkReferenceDefinition.TryParse(ref iterator, out linkReferenceDefinition))
                {
                    if (!state.Document.ContainsLinkReferenceDefinition(linkReferenceDefinition.Label))
                    {
                        state.Document.SetLinkReferenceDefinition(linkReferenceDefinition.Label, linkReferenceDefinition);
                    }
                    atLeastOneFound = true;

                    // Remove lines that have been matched
                    if (iterator.Start > iterator.End)
                    {
                        lines.Clear();
                    }
                    else
                    {
                        for (int i = iterator.SliceIndex - 1; i >= 0; i--)
                        {
                            lines.RemoveAt(i);
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            return(atLeastOneFound);
        }
Example #4
0
        private bool TryMatchLinkReferenceDefinition(ref StringLineGroup lines, BlockProcessor state)
        {
            bool atLeastOneFound = false;

            while (true)
            {
                // If we have found a LinkReferenceDefinition, we can discard the previous paragraph
                var iterator = lines.ToCharIterator();
                if (LinkReferenceDefinition.TryParse(ref iterator, out LinkReferenceDefinition linkReferenceDefinition))
                {
                    state.Document.SetLinkReferenceDefinition(linkReferenceDefinition.Label, linkReferenceDefinition);
                    atLeastOneFound = true;

                    // Correct the locations of each field
                    linkReferenceDefinition.Line = lines.Lines[0].Line;
                    int startPosition = lines.Lines[0].Slice.Start;

                    linkReferenceDefinition.Span      = linkReferenceDefinition.Span.MoveForward(startPosition);
                    linkReferenceDefinition.LabelSpan = linkReferenceDefinition.LabelSpan.MoveForward(startPosition);
                    linkReferenceDefinition.UrlSpan   = linkReferenceDefinition.UrlSpan.MoveForward(startPosition);
                    linkReferenceDefinition.TitleSpan = linkReferenceDefinition.TitleSpan.MoveForward(startPosition);

                    lines = iterator.Remaining();
                }