コード例 #1
0
        // Parse a plain paragraph
        public static ParseResult ParseFrom(
            ParseInput input
            )
        {
            ArraySegment <string>  lines        = input.Lines();
            ParseResult            result       = new ParseResult();
            LinkedList <IHtmlable> innerContent = new LinkedList <IHtmlable>();
            // The paragraph doesn't get parsed past the first blank line
            int endIndex = 0;

            while (
                (endIndex < lines.Count) &&
                (
                    !ContainsOnlyWhitespace(
                        lines[endIndex]
                        )
                )
                )
            {
                endIndex++;
            }
            int i = 0;

            while (i < endIndex)
            {
                lines = input.Lines();
                if (MarkdownCodeBlock.CanParseFrom(input))
                {
                    ParseResult innerResult = MarkdownCodeBlock.ParseFrom(input);
                    foreach (IHtmlable entry in innerResult.GetContent())
                    {
                        innerContent.AddLast(entry);
                    }
                }
                else
                {
                    string line = lines[0];
                    if (endsWithAtLeastTwoSpaces(line))
                    {
                        string shortened = StripTrailingWhitespace(line);
                        foreach (
                            IHtmlable entry
                            in MarkdownParser.ParseInnerText(
                                new ParseInput(
                                    input,
                                    shortened
                                    )
                                )
                            )
                        {
                            innerContent.AddLast(entry);
                        }
                        innerContent.AddLast(
                            new MarkdownLinebreak()
                            );
                    }
                    else
                    {
                        foreach (
                            IHtmlable entry
                            in MarkdownParser.ParseInnerText(
                                new ParseInput(
                                    input,
                                    line
                                    )
                                )
                            )
                        {
                            innerContent.AddLast(entry);
                        }

                        /*
                         * If this is not the last line,
                         * it doesn't end in a manual linebreak
                         * and the user hasn't added a space themselves
                         * we need to add a space at the end
                         */
                        if (
                            (i < (endIndex - 1)) &&
                            (line.Length > 0) &&
                            (line[^ 1] != ' ')