Example #1
0
 public FormattedStringBuilder(
     HtmlMarkupProvider htmlMarkupProvider,
     IClassifier classifier,
     IClassificationType defaultClassificationType,
     IWaitIndicator waitIndicator)
 {
     _htmlMarkupProvider        = htmlMarkupProvider;
     _classifier                = classifier;
     _defaultClassificationType = defaultClassificationType;
     _waitIndicator             = waitIndicator;
 }
Example #2
0
        public string GenerateHtml(NormalizedSnapshotSpanCollection spans, IWpfTextView textView)
        {
            if (spans == null || spans.Count == 0)
            {
                return("");
            }

            // this will trigger loading of the package
            // so we can ensure ToolsOptionsPage gets created and
            // ToolsOptionsPage.Instance gets set
            var dte   = (_DTE)_serviceProvider.GetService(typeof(_DTE));
            var props = dte.Properties[CopyAsHtmlPackage.CategoryName, CopyAsHtmlPackage.PageName];

            IClassificationFormatMap formatMap = _classificationFormatMappingService.GetClassificationFormatMap(textView);
            IClassificationType      defaultClassificationType = _classificationTypeRegistry.GetClassificationType("text");
            HtmlMarkupProvider       htmlMarkupProvider        = new HtmlMarkupProvider(
                formatMap,
                defaultClassificationType,
                textView.Background);
            IClassifier classifier = _classifierAggregatorService.GetClassifier(textView.TextBuffer);

            var formattedStringBuilder = new FormattedStringBuilder(
                htmlMarkupProvider,
                classifier,
                defaultClassificationType,
                this.WaitIndicator);

            string result = formattedStringBuilder.AppendSnapshotSpans(spans);

            var classifierDispose = classifier as System.IDisposable;

            if (classifierDispose != null)
            {
                classifierDispose.Dispose();
            }

            return(result);
        }
Example #3
0
        public string AppendSnapshotSpans(NormalizedSnapshotSpanCollection spans)
        {
            AppendBeginCodeSnippet();

            // if there is a single stream selection span, we can attempt to unindent
            if (ToolsOptionsPage.Instance.UnindentToRemoveExtraLeadingWhitespace && spans.Count == 1)
            {
                var plaintext = spans[0].GetText();
                HtmlMarkupProvider.LongestPrefix = HtmlMarkupProvider.CalculateLongestCommonWhitespacePrefix(plaintext);
            }
            else
            {
                HtmlMarkupProvider.LongestPrefix = null;
            }

            foreach (var span in spans)
            {
                AppendSnapshotSpan(span);
            }

            AppendEndCodeSnippet();
            return(_stringBuilder.ToString());
        }