示例#1
0
        /// <summary>
        /// Called by all elements to find the next element to parse out of the markdown given a startingPos and an ending Pos
        /// </summary>
        /// <param name="markdown"></param>
        /// <param name="startingPos"></param>
        /// <param name="endingPost"></param>
        /// <returns></returns>
        public static MarkdownBlock FindNextBlock(ref string markdown, ref int startingPos, int endingPos)
        {
            // We need to look at the start of this current block and figure out what type it is.
            // Find the next char that isn't a \n, \r, or ' ', keep track of white space
            int spaceCount = 0;

            while (markdown.Length > startingPos && endingPos > startingPos && (markdown[startingPos] == '\r' || markdown[startingPos] == '\n' || Char.IsWhiteSpace(markdown[startingPos])))
            {
                // If we find a space count it for the indent rules. If not reset the count.
                spaceCount = markdown[startingPos] == ' ' ? spaceCount + 1 : 0;
                startingPos++;
            }

            if (CodeBlock.CanHandleBlock(ref markdown, startingPos, endingPos, spaceCount))
            {
                return(new CodeBlock());
            }
            if (QuoteBlock.CanHandleBlock(ref markdown, startingPos, endingPos))
            {
                return(new QuoteBlock());
            }
            if (HeaderBlock.CanHandleBlock(ref markdown, startingPos, endingPos))
            {
                return(new HeaderBlock());
            }
            if (ListElementBlock.CanHandleBlock(ref markdown, startingPos, endingPos))
            {
                return(new ListElementBlock());
            }
            if (HorizontalRuleBlock.CanHandleBlock(ref markdown, startingPos, endingPos))
            {
                return(new HorizontalRuleBlock());
            }
            if (LineBreakBlock.CanHandleBlock(ref markdown, startingPos, endingPos))
            {
                return(new LineBreakBlock());
            }

            // If we can't match any of these just make a new paragraph.
            return(new ParagraphBlock());
        }