public override BlockState TryContinue(BlockProcessor processor, Block block)
        {
            var footnote = (Footnote)block;

            if (processor.CurrentBlock == null || processor.CurrentBlock.IsBreakable)
            {
                if (processor.IsBlankLine)
                {
                    footnote.IsLastLineEmpty = true;
                    return(BlockState.ContinueDiscard);
                }

                if (footnote.IsLastLineEmpty && processor.Column == 0)
                {
                    return(BlockState.Break);
                }
            }
            footnote.IsLastLineEmpty = false;

            if (processor.IsCodeIndent)
            {
                processor.GoToCodeIndent();
            }

            return(BlockState.Continue);
        }
Exemple #2
0
        /// <summary>
        /// Parses a line.
        /// </summary>
        internal virtual BlockState ParseLine(BlockProcessor blockProcessor, ProxyLeafBlock proxyLeafBlock)
        {
            bool isBlankLine = blockProcessor.IsBlankLine;
            bool blockExists = proxyLeafBlock != null;

            if (isBlankLine && !blockExists)
            {
                return(BlockState.None);
            }

            if (!blockProcessor.IsCodeIndent && (!blockExists || !isBlankLine))
            {
                return(BlockState.None);
            }

            // Reset indent so extra leading spaces are included in the line.
            // E.g before resetting, if the current line is "line" with indent 6, after resetting it will be "  line".
            if (blockProcessor.Indent > 4)
            {
                blockProcessor.GoToCodeIndent();
            }

            if (proxyLeafBlock == null)
            {
                proxyLeafBlock = _flexiCodeBlockFactory.CreateProxyLeafBlock(blockProcessor, this);
                blockProcessor.NewBlocks.Push(proxyLeafBlock);
            }
            else
            {
                proxyLeafBlock.UpdateSpanEnd(blockProcessor.Line.End);
            }

            return(BlockState.Continue);
        }
Exemple #3
0
        public override BlockState TryContinue(BlockProcessor processor, Block block)
        {
            var footnote = (Footnote)block;

            if (processor.CurrentBlock == null || processor.CurrentBlock.IsBreakable)
            {
                if (processor.IsBlankLine)
                {
                    footnote.IsLastLineEmpty = true;
                    return(BlockState.ContinueDiscard);
                }

                if (processor.Column == 0)
                {
                    if (footnote.IsLastLineEmpty)
                    {
                        // Close the current footnote
                        processor.Close(footnote);

                        // Parse any opening footnote
                        return(TryOpen(processor));
                    }

                    // Make sure that consecutive footnotes without a blanklines are parsed correctly
                    if (TryOpen(processor, true) == BlockState.Continue)
                    {
                        processor.Close(footnote);
                        return(BlockState.Continue);
                    }
                }
            }
            footnote.IsLastLineEmpty = false;

            if (processor.IsCodeIndent)
            {
                processor.GoToCodeIndent();
            }

            return(BlockState.Continue);
        }
Exemple #4
0
        public override BlockState TryContinue(BlockProcessor processor, Block block)
        {
            var definitionItem = (DefinitionItem)block;

            if (processor.IsCodeIndent)
            {
                processor.GoToCodeIndent();
                return(BlockState.Continue);
            }

            var list          = (DefinitionList)definitionItem.Parent;
            var lastBlankLine = definitionItem.LastChild as BlankLineBlock;

            // Check if we have another definition list
            if (Array.IndexOf(OpeningCharacters, processor.CurrentChar) >= 0)
            {
                var startPosition = processor.Start;
                var column        = processor.ColumnBeforeIndent;
                processor.NextChar();
                processor.ParseIndent();
                var delta = processor.Column - column;

                // We expect to have a least
                if (delta < 4)
                {
                    // Remove the blankline before breaking this definition item
                    if (lastBlankLine != null)
                    {
                        definitionItem.RemoveAt(definitionItem.Count - 1);
                    }

                    list.Span.End = list.LastChild.Span.End;
                    return(BlockState.None);
                }

                if (delta > 4)
                {
                    processor.GoToColumn(column + 4);
                }

                processor.Close(definitionItem);
                var nextDefinitionItem = new DefinitionItem(this)
                {
                    Span             = new SourceSpan(startPosition, processor.Line.End),
                    Line             = processor.LineIndex,
                    Column           = processor.Column,
                    OpeningCharacter = processor.CurrentChar,
                };
                list.Add(nextDefinitionItem);
                processor.Open(nextDefinitionItem);

                return(BlockState.Continue);
            }

            var isBreakable = definitionItem.LastChild?.IsBreakable ?? true;

            if (processor.IsBlankLine)
            {
                if (lastBlankLine == null && isBreakable)
                {
                    definitionItem.Add(new BlankLineBlock());
                }
                return(isBreakable ? BlockState.ContinueDiscard : BlockState.Continue);
            }

            var paragraphBlock = definitionItem.LastChild as ParagraphBlock;

            if (lastBlankLine == null && paragraphBlock != null)
            {
                return(BlockState.Continue);
            }

            // Remove the blankline before breaking this definition item
            if (lastBlankLine != null)
            {
                definitionItem.RemoveAt(definitionItem.Count - 1);
            }

            list.Span.End = list.LastChild.Span.End;
            return(BlockState.Break);
        }