public void TriggerAfterParsingEvent(UDNParsingResults results) { if (AfterParsingEvent != null) { AfterParsingEvent(results); } }
private static void PassResultsToChangedEvent(UDNParsingResults results) { if (CurrentOutputIsChanged != null) { CurrentOutputIsChanged(results); } }
private static IEnumerable <BlockInfo> GetHeaderBlocks(UDNParsingResults results) { var doc = results.Document; if (doc == null) { return(new List <BlockInfo>()); } var headers = doc.Data.GetElements <EMHeader>(); if (headers.Count == 0) { return(new List <BlockInfo>()); } var blocks = new List <BlockInfo>(); var lastHeaderStartAndElement = Tuple.Create <int, EMElement>(0, null); var text = doc.Text; foreach (var header in headers.Where(h => h.Document == doc)) { var bounds = header.GetOriginalTextBounds(); if (lastHeaderStartAndElement.Item2 != null) { var lastNonWhitespace = -1; for (var i = bounds.Start - 1; i >= 0; --i) { if (text[i] != ' ' && text[i] != '\n' && text[i] != '\r' && text[i] != '\t') { lastNonWhitespace = i; break; } } if (lastNonWhitespace != -1 && lastNonWhitespace < bounds.Start) { blocks.Add( new BlockInfo( lastHeaderStartAndElement.Item2, new Span(lastHeaderStartAndElement.Item1, lastNonWhitespace - lastHeaderStartAndElement.Item1 + 1))); } } lastHeaderStartAndElement = Tuple.Create(bounds.Start, header as EMElement); } blocks.Add( new BlockInfo( lastHeaderStartAndElement.Item2, new Span( lastHeaderStartAndElement.Item1, text.Length - lastHeaderStartAndElement.Item1))); return(blocks); }
private UDNParsingResults Parse(ITextSnapshot snapshot) { currentResults = new UDNParsingResults(path, snapshot, package, markdown, folderDetails); SetDirtyFlag(false); return(currentResults); }
public void EnforceSpansRefresh(UDNParsingResults results) { if (ClassificationChanged != null) { ClassificationChanged( this, new ClassificationChangedEventArgs( new SnapshotSpan( results.ParsedSnapshot, 0, results.ParsedSnapshot.Length))); } }
public void RefreshComboItems(UDNParsingResults results) { dataLock.EnterWriteLock(); try { var blockInfos = GetHeaderBlocks(results); sections.Clear(); comboElements.Clear(); // First, add an item for "Top of the file" comboElements.Add(MarkdownSharp.Language.Message("TopOfFile")); foreach (var blockInfo in blockInfos) { var header = blockInfo.BlockElement as EMHeader; if (blockInfo.Span.Start < 0 || blockInfo.Span.Start >= results.ParsedSnapshot.Length || blockInfo.Span.End < 0 || blockInfo.Span.End >= results.ParsedSnapshot.Length) { continue; } var trackingSpan = results.ParsedSnapshot.CreateTrackingSpan(blockInfo.Span, SpanTrackingMode.EdgeExclusive); var comboText = string.Format("{0}{1}", new string('-', header.Level - 1), header.Text); if (trackingSpan == null) { continue; } sections.Add(trackingSpan); comboElements.Add(comboText); } } finally { dataLock.ExitWriteLock(); } SetSectionComboToCaretPosition(); }
private static IEnumerable<BlockInfo> GetHeaderBlocks(UDNParsingResults results) { var doc = results.Document; if (doc == null) { return new List<BlockInfo>(); } var headers = doc.Data.GetElements<EMHeader>(); if (headers.Count == 0) { return new List<BlockInfo>(); } var blocks = new List<BlockInfo>(); var lastHeaderStartAndElement = Tuple.Create<int, EMElement>(0, null); var text = doc.Text; foreach (var header in headers.Where(h => h.Document == doc)) { var bounds = header.GetOriginalTextBounds(); if (lastHeaderStartAndElement.Item2 != null) { var lastNonWhitespace = -1; for (var i = bounds.Start - 1; i >= 0; --i) { if (text[i] != ' ' && text[i] != '\n' && text[i] != '\r' && text[i] != '\t') { lastNonWhitespace = i; break; } } if (lastNonWhitespace != -1 && lastNonWhitespace < bounds.Start) { blocks.Add( new BlockInfo( lastHeaderStartAndElement.Item2, new Span(lastHeaderStartAndElement.Item1, lastNonWhitespace - lastHeaderStartAndElement.Item1 + 1))); } } lastHeaderStartAndElement = Tuple.Create(bounds.Start, header as EMElement); } blocks.Add( new BlockInfo( lastHeaderStartAndElement.Item2, new Span( lastHeaderStartAndElement.Item1, text.Length - lastHeaderStartAndElement.Item1))); return blocks; }
public void Reclassify(UDNParsingResults results) { var boundsWithClassificationStrings = new List<Tuple<Interval, string>>(); foreach (var element in results.Document.Data.GetElements<EMElement>() .Where( e => e.Document == results.Document && !(e is EMContentElement))) { var classificationString = element.GetClassificationString(); if (classificationString == null) { continue; } var bound = element.GetOriginalTextBounds(); if (bound.End > results.ParsedSnapshot.Length) { continue; } boundsWithClassificationStrings.Add(Tuple.Create(bound, classificationString)); } foreach (var preprocessedBound in results.Document.GetPreprocessedTextBounds()) { var classificationString = GetClassificationStringForPreprocessedText(preprocessedBound.Type); if (classificationString == null) { continue; } boundsWithClassificationStrings.Add(Tuple.Create(preprocessedBound.Bound, classificationString)); } spansLock.EnterWriteLock(); try { spans.Clear(); foreach (var boundWithClassificationString in boundsWithClassificationStrings) { var bound = boundWithClassificationString.Item1; var classificationString = boundWithClassificationString.Item2; spans.Add( new ClassificationSpan( new SnapshotSpan( results.ParsedSnapshot, bound.Start, bound.End - bound.Start + 1), _classificationRegistry.GetClassificationType(classificationString))); } } finally { spansLock.ExitWriteLock(); } EnforceSpansRefresh(results); }
private UDNParsingResults Parse(ITextSnapshot snapshot) { currentResults = new UDNParsingResults(path, snapshot, package, markdown, folderDetails); SetDirtyFlag(false); return currentResults; }
void UpdatePreviewWindow(UDNParsingResults results) { ThreadPool.QueueUserWorkItem(state => { var content = GetHTMLText(results); if (string.IsNullOrWhiteSpace(content)) { return; } textView.VisualElement.Dispatcher.Invoke(() => { var previewWindow = GetPreviewWindow(true); if (previewWindow.CurrentSource == this || previewWindow.CurrentSource == null) { previewWindow.SetPreviewContent(this, content, GetDocumentName()); } }, DispatcherPriority.ApplicationIdle); }); }
string GetHTMLText(UDNParsingResults results) { log.ClearLog(); var html = new StringBuilder(); var newHtml = results.Document.ThreadSafeRender(); var anchorPosition = AnchorPosition(newHtml); if (anchorPosition != 0) { newHtml = newHtml.Insert( anchorPosition, "<span name=\"MARKDOWNANCHORNOTUSEDELSEWHERE\"></span>"); } //html.AppendLine(RemoveScript.Replace(newHtml, "")); html.AppendLine(newHtml); LogMarkdownErrors(document.FilePath, results.Errors, log); return html.ToString(); }