Beispiel #1
0
        private bool TryFindMarkToken(string text, int index, out int finalIndex, out TokenMd token)
        {
            if (TryFindMark(text, index, out var symbol))
            {
                token = marks[symbol].GetToken(text, index, out finalIndex);
                return(true);
            }
            finalIndex = index;

            token = default;
            return(false);
        }
Beispiel #2
0
        private string GetTokenHtml(TokenMd token)
        {
            var resultToken = token;
            var builder     = new StringBuilder();

            builder.Append(
                resultToken.InnerTokens == null || resultToken.InnerTokens.Count == 0
                ? resultToken.TokenWithoutMark
                : GetInnerTokensHtml(resultToken.InnerTokens));

            return(builder.ToString());
        }
Beispiel #3
0
        private TokenMd GetInnerTokens(TokenMd token)
        {
            var innerTokens = new List <TokenMd>();
            var resultToken = token;
            var index       = 0;

            if (resultToken.InnerTokens == null)
            {
                return(resultToken);
            }

            if (resultToken.InnerTokens.Count == 0)
            {
                while (index < token.TokenWithoutMark.Length)
                {
                    var parsedToken = GetToken(resultToken.TokenWithoutMark, index, out var finalIndex);

                    if (!(token.Mark is EmptyMark) &&
                        !(parsedToken.Mark is EmptyMark) &&
                        token.Mark is ItalicMark &&
                        parsedToken.Mark is StrongMark)
                    {
                        return(new TokenMd(resultToken.Token, new EmptyMark()));
                    }

                    parsedToken.External = token;
                    index = finalIndex;
                    if (parsedToken.Mark is EmptyMark && parsedToken.InnerTokens != null && parsedToken.InnerTokens.Count == 0)
                    {
                        parsedToken.InnerTokens = null;
                    }
                    else
                    {
                        parsedToken = GetInnerTokens(parsedToken);
                    }

                    innerTokens.Add(parsedToken);
                }
                resultToken.InnerTokens = innerTokens;
            }
            else
            {
                resultToken.InnerTokens = GetAllInnerTokens(resultToken.InnerTokens);
            }


            return(resultToken);
        }