コード例 #1
0
ファイル: BoldTextInline.cs プロジェクト: lostmsu/Quarrel
        /// <summary>
        /// Attempts to parse a bold text span.
        /// </summary>
        /// <param name="markdown"> The markdown text. </param>
        /// <param name="start"> The location to start parsing. </param>
        /// <param name="maxEnd"> The location to stop parsing. </param>
        /// <returns> A parsed bold text span, or <c>null</c> if this is not a bold text span. </returns>
        internal static Helpers.Common.InlineParseResult Parse(string markdown, int start, int maxEnd)
        {
            if (start >= maxEnd - 1)
            {
                return(null);
            }

            // Check the start sequence.
            string startSequence = markdown.Substring(start, 2);

            if (startSequence != "**" && startSequence != "__")
            {
                return(null);
            }

            // Find the end of the span.  The end sequence (either '**' or '__') must be the same
            // as the start sequence.
            var innerStart = start + 2;
            int innerEnd   = Helpers.Common.IndexOf(markdown, startSequence, innerStart, maxEnd);

            if (innerEnd == -1)
            {
                return(null);
            }

            // The span must contain at least one character.
            if (innerStart == innerEnd)
            {
                return(null);
            }

            // The first character inside the span must NOT be a space.
            if (Helpers.Common.IsWhiteSpace(markdown[innerStart]))
            {
                return(null);
            }

            // The last character inside the span must NOT be a space.
            if (Helpers.Common.IsWhiteSpace(markdown[innerEnd - 1]))
            {
                return(null);
            }

            // We found something!
            var result = new BoldTextInline();

            result.Inlines = Helpers.Common.ParseInlineChildren(markdown, innerStart, innerEnd);
            return(new Helpers.Common.InlineParseResult(result, start, innerEnd + 2));
        }
コード例 #2
0
        /// <summary>
        /// Attempts to parse a bold text span.
        /// </summary>
        /// <param name="markdown"> The markdown text. </param>
        /// <param name="start"> The location to start parsing. </param>
        /// <param name="maxEnd"> The location to stop parsing. </param>
        /// <returns> A parsed bold text span, or <c>null</c> if this is not a bold text span. </returns>
        internal static Helpers.Common.InlineParseResult Parse(string markdown, int start, int maxEnd)
        {
            if (start >= maxEnd - 3)
            {
                return(null);
            }

            if (markdown == null || markdown.Length < 6)
            {
                return(null);
            }

            // Check the start sequence.
            string startSequence = markdown.Substring(start, 3);

            if (startSequence != "***" && startSequence != "___")
            {
                return(null);
            }

            // Find the end of the span.  The end sequence (either '***' or '___') must be the same
            // as the start sequence.
            var innerStart = start + 3;
            int innerEnd   = Helpers.Common.IndexOf(markdown, startSequence, innerStart, maxEnd);

            if (innerEnd == -1)
            {
                return(null);
            }

            // The span must contain at least one character.
            if (innerStart == innerEnd)
            {
                return(null);
            }

            // The first character inside the span must NOT be a space.
            if (Helpers.Common.IsWhiteSpace(markdown[innerStart]))
            {
                return(null);
            }

            // The last character inside the span must NOT be a space.
            if (Helpers.Common.IsWhiteSpace(markdown[innerEnd - 1]))
            {
                return(null);
            }

            // We found something!
            var bold = new BoldTextInline
            {
                Inlines = new List <MarkdownInline>
                {
                    new ItalicTextInline
                    {
                        Inlines = Helpers.Common.ParseInlineChildren(markdown, innerStart, innerEnd)
                    }
                }
            };

            return(new Helpers.Common.InlineParseResult(bold, start, innerEnd + 3));
        }