Beispiel #1
0
        public static ParseResult ParseFrom(
            ParseInput input
            )
        {
            ParseResult result = new ParseResult();

            if (!CanParseFrom(input))
            {
                return(result);
            }
            ArraySegment <string> lines = input.Lines();

            lines[0] = "";
            LinkedList <IHtmlable> innerContent = new LinkedList <IHtmlable>();
            int i = 1;

            while (!regexBacktickSectionClose.Match(lines[i]).Success)
            {
                innerContent.AddLast(
                    new MarkdownText(
                        lines[i]
                        )
                    );
                lines[i] = "";
                i++;
            }
            // Remember to clear final line (closing backticks)
            lines[i] = "";
            MarkdownCodeBlock blockCodeElement = new MarkdownCodeBlock(
                Utils.LinkedListToArray(innerContent)
                );

            result.Success = true;
            result.AddContent(blockCodeElement);
            return(result);
        }
Beispiel #2
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] != ' ')