コード例 #1
0
        private MdToken MakeToken(string text)
        {
            var token = new MdToken(text, "NONE", "NONE");

            if (text.Length <= 2)
            {
                return(token);
            }
            var shieldingIndexes           = FindShieldedSymbols(text);
            var textWithoutShieldedSymbols = ReplaceShieldingWithSpaces(text, shieldingIndexes);
            var beginningSymbol            = GetBeginningSpecialSymbol(textWithoutShieldedSymbols);
            var endingSymbol = GetEndingSpecialSymbol(textWithoutShieldedSymbols);
            var content      = GetContent(text, beginningSymbol, endingSymbol);

            shieldingIndexes = FindShieldedSymbols(content);
            content          = ClearContentShielding(content, shieldingIndexes);
            token            = new MdToken(content, beginningSymbol, endingSymbol);
            return(token);
        }
コード例 #2
0
 private void UpdatePairedTokens(MdToken token)
 {
     if (pairedSymbols.Count != 0)
     {
         var stackTop = pairedSymbols.Pop();
         while (stackTop.BeginningSpecialSymbol != token.EndingSpecialSymbol && pairedSymbols.Count != 0)
         {
             CorrectPairedTokenBeginning(stackTop);
             stackTop = pairedSymbols.Pop();
         }
         if (stackTop.BeginningSpecialSymbol == token.EndingSpecialSymbol)
         {
             return;
         }
         CorrectPairedTokenBeginning(stackTop);
         CorrectPairedTokenEnding(token);
     }
     else
     {
         CorrectPairedTokenEnding(token);
     }
 }
コード例 #3
0
        private void HandleTokenNesting(MdToken token, string symbolToCheck, string oldBeginSymbol, bool isBeginning)
        {
            if (symbolToCheck == "NONE")
            {
                return;
            }
            if (!config.CanSymbolBeNested(symbolToCheck))
            {
                return;
            }
            if (pairedSymbols.Count == 0)
            {
                return;
            }

            var stackTopBegin = pairedSymbols.Peek().BeginningSpecialSymbol;
            var stackTopEnd   = pairedSymbols.Peek().EndingSpecialSymbol;

            var onlyBeginningIsPresent = stackTopBegin != "NONE" && stackTopEnd == "NONE";
            var isNested            = onlyBeginningIsPresent && stackTopBegin != symbolToCheck && oldBeginSymbol != "NONE";
            var isNestingNotAllowed = config.IsSymbolNestingException(symbolToCheck, stackTopBegin);

            if (!isNested)
            {
                return;
            }
            if (!isNestingNotAllowed)
            {
                return;
            }
            if (isBeginning)
            {
                CorrectPairedTokenBeginning(token);
            }
            else
            {
                CorrectPairedTokenEnding(token);
            }
        }
コード例 #4
0
        private void HandlePairedTokens(MdToken token)
        {
            var beginSymbol = token.BeginningSpecialSymbol;
            var endSymbol   = token.EndingSpecialSymbol;
            var beginningAndEndingAreDifferent = endSymbol != beginSymbol;
            var isNotPairedAndNotEmpty         = !config.IsSymbolPaired(token.BeginningSpecialSymbol) && beginSymbol != "NONE";

            HandleTokenNesting(token, token.BeginningSpecialSymbol, beginSymbol, true);
            if (config.IsSymbolPaired(token.BeginningSpecialSymbol) && beginningAndEndingAreDifferent)
            {
                pairedSymbols.Push(token);
            }
            else if (isNotPairedAndNotEmpty)
            {
                token.EndingSpecialSymbol = token.BeginningSpecialSymbol;
                return;
            }

            HandleTokenNesting(token, token.EndingSpecialSymbol, beginSymbol, false);
            if (beginningAndEndingAreDifferent && config.IsSymbolPaired(token.EndingSpecialSymbol))
            {
                UpdatePairedTokens(token);
            }
        }
コード例 #5
0
 private static void CorrectPairedTokenEnding(MdToken token)
 {
     token.Content            += token.EndingSpecialSymbol;
     token.EndingSpecialSymbol = "NONE";
 }
コード例 #6
0
 private static void CorrectPairedTokenBeginning(MdToken token)
 {
     token.Content = token.BeginningSpecialSymbol + token.Content;
     token.BeginningSpecialSymbol = "NONE";
 }