public void SkipUntil(MarkdownTokenType tokenType) { while (!EOF && Current.Type != tokenType) { Next(); } }
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); } }
public IEnumerable <MarkdownToken> CaptureUntil(MarkdownTokenType tokenType) { var start = Position; var count = 0; while (!EOF && Current.Type != tokenType) { count++; Next(); } return(_Token.GetRange(start, count)); }
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); }
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); }
public MarkdownToken(MarkdownTokenType type, string text = null) { Type = type; Text = text; }
public MarkdownToken(string text) { Type = MarkdownTokenType.Text; Text = text; }