コード例 #1
0
 public void SkipUntil(MarkdownTokenType tokenType)
 {
     while (!EOF && Current.Type != tokenType)
     {
         Next();
     }
 }
コード例 #2
0
ファイル: MdTokenizer.cs プロジェクト: mvacha/RTVS
 protected void AddToken(MarkdownTokenType type, int start, int length)
 {
     Debug.Assert(type != MarkdownTokenType.Code, "Use AddCodeToken instead");
     if (length > 0)
     {
         var token = new MarkdownToken(type, new TextRange(start, length));
         _tokens.Add(token);
     }
 }
コード例 #3
0
        public IEnumerable <MarkdownToken> CaptureUntil(MarkdownTokenType tokenType)
        {
            var start = Position;
            var count = 0;

            while (!EOF && Current.Type != tokenType)
            {
                count++;

                Next();
            }
            return(_Token.GetRange(start, count));
        }
コード例 #4
0
        private static int FirstIndexOfAny(string markdown, IReadOnlyDictionary <string, MarkdownTokenType> values,
                                           int startIndex, out MarkdownTokenType tokenType)
        {
            for (var i = startIndex; i < markdown.Length; ++i)
            {
                foreach (var pair in values)
                {
                    if (StartsWith(markdown, pair.Key, i))
                    {
                        tokenType = pair.Value;
                        return(i);
                    }
                }
            }

            tokenType = MarkdownTokenType.None;
            return(-1);
        }
コード例 #5
0
        protected bool HandleItalic(char boundaryChar, MarkdownTokenType tokenType)
        {
            int start = _cs.Position;

            _cs.MoveToNextChar();

            while (!_cs.IsEndOfStream())
            {
                if (_cs.CurrentChar == '*' && _cs.NextChar == '*')
                {
                    int tokenCount = _tokens.Count;
                    AddToken(tokenType, start, _cs.Position - start);

                    int startOfBold = _cs.Position;
                    if (HandleBold(MarkdownTokenType.BoldItalic))
                    {
                        start = _cs.Position;
                    }
                    else
                    {
                        _tokens.RemoveRange(tokenCount, _tokens.Count - tokenCount);
                        _cs.Position = startOfBold;
                        break;
                    }
                }

                if (_cs.CurrentChar == boundaryChar)
                {
                    _cs.MoveToNextChar();
                    AddToken(tokenType, start, _cs.Position - start);
                    return(true);
                }

                if (_cs.IsAtNewLine())
                {
                    break;
                }

                _cs.MoveToNextChar();
            }

            return(false);
        }
コード例 #6
0
 public MarkdownToken(MarkdownTokenType type, string text = null)
 {
     Type = type;
     Text = text;
 }
コード例 #7
0
 public MarkdownToken(string text)
 {
     Type = MarkdownTokenType.Text;
     Text = text;
 }