Beispiel #1
0
        private void AppendTags(List <ITagMatch> output, string text)
        {
            char endContentReadingChar = ' ';
            int  startPos = -1;

            StringBuilder content = null;

            for (var i = 0; i < text.Length; ++i)
            {
                var c = text[i];

                if (content == null)
                {
                    if (((c == '[' && text.Length > i + 1 && text[i + 1] != '[') || (c == '<' && text.Length > i + 1 && text[i + 1] != '<')) && (spanParser || i == 0 || text[i - 1] == '\n'))
                    {
                        content = new StringBuilder();
                        endContentReadingChar = !spanParser ? '\n' : (c == '[' ? ']' : '>');
                        startPos = i;
                    }
                }

                if (content != null)
                {
                    content.Append(c);

                    if (c == endContentReadingChar || i == text.Length - 1)
                    {
                        var str = content.ToString().Trim();

                        try
                        {
                            EMMarkdownAndHTMLStartOrEndTagMatch tag;

                            if (str.Length > 1 && str[1] == '/')
                            {
                                tag = new EMMarkdownAndHTMLEndTagMatch(startPos, str);
                            }
                            else
                            {
                                tag = new EMMarkdownAndHTMLStartTagMatch(startPos, str);
                            }

                            if (!tag.IsIgnored)
                            {
                                output.Add(tag);
                            }
                        }
                        catch (ArgumentException)
                        {
                            // ignore invalid tags
                        }

                        content = null;
                    }
                }
            }
        }
        private void AppendTags(List<ITagMatch> output, string text)
        {
            char endContentReadingChar = ' ';
            int startPos = -1;

            StringBuilder content = null;

            for (var i = 0; i < text.Length; ++i)
            {
                var c = text[i];

                if (content == null)
                {
                    if (((c == '[' && text.Length > i + 1 && text[i + 1] != '[') || (c == '<' && text.Length > i + 1 && text[i + 1] != '<')) && (spanParser || i == 0 || text[i - 1] == '\n'))
                    {
                        content = new StringBuilder();
                        endContentReadingChar = !spanParser ? '\n' : (c == '[' ? ']' : '>');
                        startPos = i;
                    }
                }

                if (content != null)
                {
                    content.Append(c);

                    if (c == endContentReadingChar || i == text.Length - 1)
                    {
                        var str = content.ToString().Trim();

                        try
                        {
                            EMMarkdownAndHTMLStartOrEndTagMatch tag;

                            if (str.Length > 1 && str[1] == '/')
                            {
                                tag = new EMMarkdownAndHTMLEndTagMatch(startPos, str);
                            }
                            else
                            {
                                tag = new EMMarkdownAndHTMLStartTagMatch(startPos, str);
                            }

                            if (!tag.IsIgnored)
                            {
                                output.Add(tag);
                            }
                        }
                        catch (ArgumentException)
                        {
                            // ignore invalid tags
                        }

                        content = null;
                    }
                }
            }
        }