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); }
void RefreshComboItems(object sender, EventArgs args) { try { ignoreComboChange = true; ITextSnapshot snapshot = textView.TextBuffer.CurrentSnapshot; sections = new List <MarkdownSection>( MarkdownParser.ParseMarkdownSections(snapshot) .Select(t => new MarkdownSection() { TokenType = t.TokenType, Span = snapshot.CreateTrackingSpan(t.Span, SpanTrackingMode.EdgeExclusive) })); sectionCombo.Items.Clear(); // First, add an item for "Top of the file" sectionCombo.Items.Add(" (Top of file)"); foreach (var section in sections) { var lineText = section.Span.GetStartPoint(snapshot).GetContainingLine().GetText().TrimStart(' ', '\t', '#'); string spaces = new string('-', section.TokenType - MarkdownParser.TokenType.H1); string comboText = string.Format("{0}{1}", spaces, lineText); sectionCombo.Items.Add(comboText); } SetSectionComboToCaretPosition(); } finally { ignoreComboChange = false; } }
IClassificationType GetClassificationTypeForMarkdownToken(MarkdownParser.TokenType tokenType) { string classificationType; if (!_tokenToClassificationType.TryGetValue(tokenType, out classificationType)) throw new ArgumentException("Unable to find classification type for " + tokenType.ToString(), "tokenType"); return _classificationRegistry.GetClassificationType(classificationType); }
static bool IsHeaderToken(MarkdownParser.Token token) { return token.TokenType >= MarkdownParser.TokenType.H1 && token.TokenType <= MarkdownParser.TokenType.H6; }