Esempio n. 1
0
        private IEnumerable <Tag> GetTags()
        {
            var hasValidContents = true;

            while (position < text.Length)
            {
                string parsedTag;
                var    success = TryParseTag(position, out parsedTag);
                if (!success)
                {
                    hasValidContents = language.IsValidTagContents(text[position]);
                    position++;
                    continue;
                }
                var tag = new Tag(parsedTag, position);
                if (language.IsLineDelimiter(parsedTag))
                {
                    yield return(tag);
                }
                position += parsedTag.Length;

                var isCodeBlock = language.IsBeginningOfCodeBlock(parsedTag);
                if (isCodeBlock || language.IsBeginningOfList(parsedTag))
                {
                    var surroundingTags = isCodeBlock ? language.CodeBlockTags : language.ListTags;
                    var entryTags       = isCodeBlock ? new TagPair("", "") : language.ListEntryTag;
                    RenderMultilineTag(tag, surroundingTags, entryTags);
                    continue;
                }

                var isEscaped = language.IsEscapedTag(tag, text);
                if ((hasValidContents || !language.IsContentRestrictied(tag)) && !isEscaped)
                {
                    yield return(tag);
                }
                if (isEscaped)
                {
                    RenderEscapedTag(tag);
                }
                hasValidContents = true;
            }
        }