Esempio n. 1
0
        public void ReparseFile(UDNParsingResults results)
        {
            CreateDocumentSections(results);

            if (TagsChanged != null)
            {
                TagsChanged(
                    this,
                    new SnapshotSpanEventArgs(
                        new SnapshotSpan(results.ParsedSnapshot, 0, results.ParsedSnapshot.Length)));
            }
        }
Esempio n. 2
0
 public void EnforceSpansRefresh(UDNParsingResults results)
 {
     if (ClassificationChanged != null)
     {
         ClassificationChanged(
             this,
             new ClassificationChangedEventArgs(
                 new SnapshotSpan(
                     results.ParsedSnapshot,
                     0,
                     results.ParsedSnapshot.Length)));
     }
 }
        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());
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        private void CreateDocumentSections(UDNParsingResults results)
        {
            var doc = results.Document;

            var elements =
                doc.Data.GetElements <EMElement>().Where(
                    e => !(e is EMContentElement) && e.Document == doc);

            var originalText = doc.Text;

            var bounds = new List <Interval>();

            foreach (var element in elements)
            {
                try
                {
                    var bound = element.GetOriginalTextBounds();

                    if (bound.Start < 0 || bound.End > originalText.Length)
                    {
                        continue;
                    }

                    bounds.Add(bound);
                }
                catch (UnableToDetectOriginalPositionException)
                {
                    // ignore
                }
            }

            foreach (var preprocessedBound in doc.GetPreprocessedTextBounds())
            {
                bounds.Add(preprocessedBound.Bound);
            }

            var newSections = new List <ITrackingSpan>();

            foreach (var bound in bounds)
            {
                var boundedText = originalText.Substring(bound.Start, bound.End - bound.Start + 1);
                var match       = TrimmingPattern.Match(boundedText);

                if (match.Groups["content"].Value.Count(e => e == '\n') > 0) // is multiline element
                {
                    newSections.Add(results.ParsedSnapshot.CreateTrackingSpan(
                                        new Span(bound.Start + match.Groups["content"].Index, match.Groups["content"].Length),
                                        SpanTrackingMode.EdgeExclusive));
                }
            }

            var comboData = UDNDocRunningTableMonitor.CurrentUDNDocView.NavigateToComboData;

            for (var i = 0; i < comboData.Count; ++i)
            {
                newSections.Add(comboData.GetSection(i));
            }

            sectionsLock.EnterWriteLock();
            try
            {
                sections.Clear();
                sections.AddRange(newSections);
            }
            finally
            {
                sectionsLock.ExitWriteLock();
            }
        }