예제 #1
0
        internal override bool TryParse(ParseState state, ParseOutput output)
        {
            output.Add(new HtmlStartTag("p"));
            state.StartRun();
            var ch = state.ReadInlineOrCharacter(output);

            while (ch != Symbols.EndOfFile)
            {
                ch = state.ReadInlineOrCharacter(output);
            }
            output.Add(state.EndRun());
            output.Add(new HtmlEndTag("p"));
            return(true);
        }
        internal override bool TryParse(ParseState state, ParseOutput output)
        {
            if (state.Peek() != _marker)
            {
                return(false);
            }

            var start = state.Index;

            state.ReadCharacter(); // consume _marker
            var ch = state.ReadCharacter();

            if (ch != _marker)
            {
                state.Index = start;
                return(false);
            }
            ch = state.ReadCharacter();
            if (ch == _marker)
            {
                state.Index = start;
                return(false);
            }

            state.StartRun(start + 2);
            while (ch != Symbols.EndOfFile)
            {
                if (ch == _marker)
                {
                    var next = state.ReadCharacter();
                    ch = next == _marker ? Symbols.EndOfFile : next;
                }
                else
                {
                    ch = state.ReadInlineOrCharacter(output);
                }
            }

            output.Add(new HtmlStartTag(_tag));
            output.Add(state.EndRun(-2));
            output.Add(new HtmlEndTag(_tag));
            return(true);
        }
        internal override bool TryParse(ParseState state, ParseOutput output)
        {
            var start     = state.Index;
            var ch        = state.ReadCharacter();
            var inBracket = false;

            if (_allowBracket && ch == '[')
            {
                inBracket = true;
                ch        = state.ReadCharacter();
            }

            // Bail if current character is not the marker
            // -or- current character is marker and the previous character was
            // neither a bracket or whitespace
            if (ch != _marker ||
                (!inBracket && start > 0 && !char.IsWhiteSpace(state[start - 1])))
            {
                return(state.Reset(start));
            }

            ch = state.ReadCharacter();
            if (ch == _marker)
            {
                return(state.Reset(start));
            }
            state.StartRun(start + (inBracket ? 2 : 1));

            while (ch != Symbols.EndOfFile)
            {
                if (ch == _marker)
                {
                    if (inBracket)
                    {
                        var next = state.ReadCharacter();
                        ch = next == ']' ? Symbols.EndOfFile : next;
                    }
                    else
                    {
                        var next = state.ReadCharacter();
                        if (char.IsWhiteSpace(ch))
                        {
                            ch = Symbols.EndOfFile;
                            state.Index--;
                        }
                        else
                        {
                            ch = next;
                        }
                    }
                }
                else
                {
                    ch = state.ReadInlineOrCharacter(output);
                }
            }

            output.Add(new HtmlStartTag(_tag));
            output.Add(state.EndRun(inBracket ? -2 : -1));
            output.Add(new HtmlEndTag(_tag));
            return(true);
        }