Example #1
0
        private void ProcessLine(
            DocumentDefBuilder docBuilder,
            ParsingContext context,
            string lineText)
        {
            Contract.Requires(docBuilder != null);
            Contract.Requires(lineText != null);

            WikiTokenizationSettings tokenizationSettings = new WikiTokenizationSettings();

            tokenizationSettings.IsWholeLine = true;
            IList <WikiTextToken> tokens = tokenizer.TokenizeWikiText(lineText, tokenizationSettings);

            if (tokens.Count == 0)
            {
                throw new NotImplementedException("todo next:");
            }

            TokenBuffer tokenBuffer = new TokenBuffer(tokens);

            WikiTextToken firstToken = tokenBuffer.Token;

            switch (firstToken.Type)
            {
            case WikiTextToken.TokenType.Heading1Start:
            case WikiTextToken.TokenType.Heading2Start:
            case WikiTextToken.TokenType.Heading3Start:
            case WikiTextToken.TokenType.Heading4Start:
            case WikiTextToken.TokenType.Heading5Start:
            case WikiTextToken.TokenType.Heading6Start:
                docBuilder.FinalizeCurrentParagraph();
                HandleHeadingLine(docBuilder, context, tokenBuffer);
                break;

            case WikiTextToken.TokenType.Text:
            case WikiTextToken.TokenType.DoubleApostrophe:
            case WikiTextToken.TokenType.TripleApostrophe:
            case WikiTextToken.TokenType.DoubleSquareBracketsOpen:
            case WikiTextToken.TokenType.SingleSquareBracketsOpen:
            case WikiTextToken.TokenType.BulletList:
            case WikiTextToken.TokenType.NumberedList:
            case WikiTextToken.TokenType.Indent:
                HandleText(docBuilder, context, tokenBuffer);
                break;

            default:
                throw new NotImplementedException("todo next: {0}".Fmt(firstToken.Type));
            }
        }
Example #2
0
        public DocumentDef ParseText(string text, out ParsingContext context)
        {
            DocumentDefBuilder docBuilder = new DocumentDefBuilder();

            context = new ParsingContext(text.SplitIntoLines());

            while (!context.EndOfText)
            {
                if (!ParseLine(docBuilder, context))
                {
                    break;
                }
            }

            docBuilder.FinalizeCurrentParagraph();

            return(docBuilder.Document);
        }
Example #3
0
        private bool ParseLine(DocumentDefBuilder docBuilder, ParsingContext context)
        {
            Contract.Requires(docBuilder != null);

            if (context.EndOfText)
            {
                return(false);
            }

            string lineText = context.CurrentLine;

            // we can ignore lines with nothing but whitespace
            if (lineText.Length == 0 || lineText.Trim().Length == 0)
            {
                docBuilder.FinalizeCurrentParagraph();
            }
            else
            {
                ProcessLine(docBuilder, context, lineText);
            }

            context.IncrementLineCounter();
            return(true);
        }