Beispiel #1
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>
        /// 尝试解析当前字符串。
        /// </summary>
        /// <param name="processor">代码块进程。</param>
        /// <returns>返回代码块状态。</returns>
        public override BlockState TryOpen(BlockProcessor processor)
        {
            if (processor.IsCodeIndent)
            {
                return(BlockState.None);
            }

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

            var quoteChar = processor.CurrentChar;
            var c         = processor.NextChar();

            if (c.IsSpaceOrTab())
            {
                processor.NextColumn();
            }

            var rawNewBlock = new QuoteSectionNoteBlock(this)
            {
                Line      = processor.LineIndex,
                QuoteChar = quoteChar,
                Column    = column,
                Span      = new SourceSpan(sourcePosition, processor.Line.End),
            };

            TryParseFromLine(processor, rawNewBlock);
            processor.NewBlocks.Push(rawNewBlock);

            if (rawNewBlock.QuoteType == QuoteSectionNoteType.DFMVideo)
            {
                return(BlockState.BreakDiscard);
            }
            else
            {
                return(BlockState.Continue);
            }
        }
Beispiel #3
0
        public override BlockState TryOpen(BlockProcessor processor)
        {
            if (processor.IsCodeIndent)
            {
                return(BlockState.None);
            }

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

            // 5.1 Block quotes
            // A block quote marker consists of 0-3 spaces of initial indent, plus
            // (a) the character > together with a following space, or
            // (b) a single character > not followed by a space.
            // (c) a single character > followed by a space and explanation mark
            // denoting the css class to apply to the block quote
            // i.e....
            // > !danger This is a dangerous quote
            // > !success This is a success quote

            var currentChar = processor.CurrentChar;
            var c           = processor.NextChar();

            if (c.IsSpaceOrTab())
            {
                c = processor.NextChar();
            }

            var cssClass = "";

            if (c == '!')
            {
                // Parse until we reach white space
                while (true)
                {
                    if (c.IsWhitespace())
                    {
                        break;
                    }
                    c = processor.NextChar();
                    if (!c.IsWhitespace())
                    {
                        cssClass += c;
                    }
                }
            }

            if (c.IsSpaceOrTab())
            {
                processor.NextColumn();
            }

            // Build quote
            var quoteBlock = new QuoteBlock(this)
            {
                QuoteChar = currentChar,
                Column    = column,
                Span      = new SourceSpan(sourcePosition, processor.Line.End),
            };

            // If we found a css class ensure it's allowed
            if (!string.IsNullOrEmpty(cssClass))
            {
                var validCss = cssClass.ToLower();
                if (_validCssClasses.Contains(validCss))
                {
                    quoteBlock.GetAttributes().AddClass(validCss);
                }
            }

            processor.NewBlocks.Push(quoteBlock);

            return(BlockState.Continue);
        }