Exemplo n.º 1
0
        public override BlockState TryContinue(BlockProcessor processor, Block block)
        {
            if (processor.IsCodeIndent)
            {
                return(BlockState.None);
            }

            var quote = (FooterBlock)block;

            // A footer
            // A Footer marker consists of 0-3 spaces of initial indent, plus (a) the characters ^^ together with a following space, or (b) a double character ^^ not followed by a space.
            var c      = processor.CurrentChar;
            var result = BlockState.Continue;

            if (c != quote.OpeningCharacter || processor.PeekChar(1) != c)
            {
                result = processor.IsBlankLine ? BlockState.BreakDiscard : BlockState.None;
            }
            else
            {
                processor.NextChar();     // Skip ^^ char (1st)
                c = processor.NextChar(); // Skip ^^ char (2nd)
                if (c.IsSpace())
                {
                    processor.NextChar(); // Skip following space
                }
                block.UpdateSpanEnd(processor.Line.End);
            }
            return(result);
        }
Exemplo n.º 2
0
        public override BlockState TryOpen(BlockProcessor processor)
        {
            if (processor.IsCodeIndent)
            {
                return(BlockState.None);
            }

            var column        = processor.Column;
            var startPosition = processor.Start;

            // A footer
            // A Footer marker consists of 0-3 spaces of initial indent, plus (a) the characters ^^ together with a following space, or (b) a double character ^^ not followed by a space.
            var openingChar = processor.CurrentChar;

            if (processor.PeekChar(1) != openingChar)
            {
                return(BlockState.None);
            }
            processor.NextChar();         // Grab 2nd^
            var c = processor.NextChar(); // grab space

            if (c.IsSpaceOrTab())
            {
                processor.NextColumn();
            }
            processor.NewBlocks.Push(new FooterBlock(this)
            {
                Span             = new SourceSpan(startPosition, processor.Line.End),
                OpeningCharacter = openingChar,
                Column           = column,
                Line             = processor.LineIndex,
            });
            return(BlockState.Continue);
        }
        /// <summary>
        /// Parses a line.
        /// </summary>
        internal virtual BlockState ParseLine(BlockProcessor blockProcessor, FlexiAlertBlock flexiAlertBlock)
        {
            if (blockProcessor.IsCodeIndent)
            {
                return(BlockState.None);
            }

            if (blockProcessor.CurrentChar != _openingChar)
            {
                return(blockProcessor.IsBlankLine ? BlockState.BreakDiscard : BlockState.None);
            }

            if (blockProcessor.PeekChar(1) == '[') // Avoid conflicting with images
            {
                return(BlockState.None);
            }

            if (flexiAlertBlock == null)
            {
                blockProcessor.NewBlocks.Push(_flexiAlertBlockFactory.Create(blockProcessor, this));
            }
            else
            {
                flexiAlertBlock.UpdateSpanEnd(blockProcessor.Line.End);
            }

            // Skip opening char and first whitespace char following it
            if (blockProcessor.NextChar().IsSpaceOrTab())
            {
                blockProcessor.NextChar();
            }

            return(BlockState.Continue);
        }
Exemplo n.º 4
0
        public override Boolean TryParse(BlockProcessor state, Char pendingBulletType, out ListInfo result)
        {
            result = new ListInfo();

            if (state.PeekChar(1) != ' ')
            {
                return(false);
            }

            state.NextChar();

            return(true);
        }
        /// <summary>
        /// Opens a <typeparamref name="TProxy"/> if a line begins with at least 3 fence characters.
        /// </summary>
        /// <param name="blockProcessor">The <see cref="BlockProcessor"/> for the document that contains a line with a fence character as its first character.</param>
        /// <returns>
        /// <see cref="BlockState.None"/> if the current line has code indent.
        /// <see cref="BlockState.None"/> if the current line does not contain an opening fence.
        /// <see cref="BlockState.ContinueDiscard"/> if the current line contains an opening fence and a <typeparamref name="TProxy"/> is opened.
        ///</returns>
        protected override BlockState TryOpenBlock(BlockProcessor blockProcessor)
        {
            if (blockProcessor.IsCodeIndent)
            {
                return(BlockState.None);
            }

            // First line of a JSONBlock must begin with <opening char>{
            if (blockProcessor.PeekChar(1) != '{')
            {
                return(BlockState.None);
            }

            // Create block
            TProxy proxyJsonBlock = _jsonBlockFactory.CreateProxyJsonBlock(blockProcessor, this);

            blockProcessor.NewBlocks.Push(proxyJsonBlock);

            // Dispose of first char (JSON starts at the curly bracket)
            blockProcessor.NextChar();

            return(ParseLine(blockProcessor.Line, proxyJsonBlock));
        }