示例#1
0
        public void MatchPairEmTags()
        {
            var tokens   = new[] { new Token(TokenType.Em, ""), new Token(TokenType.Em, "") };
            var expected = new[] { new Token(TokenType.OpenEm, ""), new Token(TokenType.CloseEm, "") };
            var result   = TokenSplitter.MatchPairTokens(tokens);

            CollectionAssert.AreEqual(expected, result);
        }
示例#2
0
        private static string MarkdownParagraphBySelectTags(string paragraph)
        {
            var matchedTokens   = TokenSplitter.MatchPairTokens(TokenSplitter.SplitOnTokens(paragraph).ToArray());
            var markedParagraph = "";

            var inCode   = false;
            var inStrong = false;
            var inEm     = false;

            foreach (var matchedToken in matchedTokens)
            {
                var oldLength = markedParagraph.Length;

                switch (matchedToken.TokenType)
                {
                case TokenType.OpenCode:
                    inCode           = true;
                    markedParagraph += "<code>";
                    break;

                case TokenType.CloseCode:
                    markedParagraph += "</code>";
                    inCode           = false;
                    break;

                case TokenType.OpenStrong:
                    if (!inCode)
                    {
                        inStrong         = true;
                        markedParagraph += "<strong>";
                    }
                    break;

                case TokenType.CloseStrong:
                    if (inStrong)
                    {
                        markedParagraph += "</strong>";
                        inStrong         = false;
                    }
                    break;

                case TokenType.OpenEm:
                    if (!inCode && !inStrong)
                    {
                        inEm             = true;
                        markedParagraph += "<em>";
                    }
                    break;

                case TokenType.CloseEm:
                    if (inEm)
                    {
                        markedParagraph += "</em>";
                        inEm             = false;
                    }
                    break;
                }

                if (markedParagraph.Length == oldLength)
                {
                    markedParagraph += matchedToken.TextValue;
                }
            }

            return(markedParagraph);
        }