Exemplo n.º 1
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);

                    // 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);
                        }
                    }
                }
Exemplo n.º 2
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();
                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);
        }