예제 #1
0
        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            ITextSnapshot snapshot = span.Snapshot;

            SnapshotSpan paragraph = GetEnclosingParagraph(span);

            string paragraphText = snapshot.GetText(paragraph);

            // And now parse the given paragraph and return classification spans for everything

            List <ClassificationSpan> spans = new List <ClassificationSpan>();

            foreach (var token in MarkdownParser.ParseMarkdownParagraph(paragraphText))
            {
                IClassificationType type = GetClassificationTypeForMarkdownToken(token.TokenType);

                spans.Add(new ClassificationSpan(new SnapshotSpan(paragraph.Start + token.Span.Start, token.Span.Length), type));
            }

            return(spans);
        }
        IClassificationType GetClassificationTypeForMarkdownToken(MarkdownParser.TokenType tokenType)
        {
            int index = (int)tokenType;
            if (index < 0 || index >= _tokenToClassificationType.Length || _tokenToClassificationType[index] == null)
                throw new ArgumentException("Unable to find classification type for " + tokenType.ToString(), "tokenType");

            return _tokenToClassificationType[index];
        }