Exemplo n.º 1
0
		/// <inheritdoc/>
		public override void BeginSpan(HighlightingColor highlightingColor)
		{
			WriteIndentationAndSpace();
			if (options.ColorNeedsSpanForStyling(highlightingColor)) {
				htmlWriter.Write("<span");
				options.WriteStyleAttributeForColor(htmlWriter, highlightingColor);
				htmlWriter.Write('>');
				endTagStack.Push("</span>");
			} else {
				endTagStack.Push(null);
			}
		}
Exemplo n.º 2
0
        /// <summary>
        /// Produces HTML code for a section of the line, with &lt;span class="colorName"&gt; tags.
        /// </summary>
        public string ToHtml(int startOffset, int endOffset, HtmlOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            int documentLineStartOffset = this.DocumentLine.Offset;
            int documentLineEndOffset   = documentLineStartOffset + this.DocumentLine.Length;

            if (startOffset < documentLineStartOffset || startOffset > documentLineEndOffset)
            {
                throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between " + documentLineStartOffset + " and " + documentLineEndOffset);
            }
            if (endOffset < startOffset || endOffset > documentLineEndOffset)
            {
                throw new ArgumentOutOfRangeException("endOffset", endOffset, "Value must be between startOffset and " + documentLineEndOffset);
            }
            ISegment requestedSegment = new SimpleSegment(startOffset, endOffset - startOffset);

            List <HtmlElement> elements = new List <HtmlElement>();

            for (int i = 0; i < this.Sections.Count; i++)
            {
                HighlightedSection s = this.Sections[i];
                if (s.GetOverlap(requestedSegment).Length > 0)
                {
                    elements.Add(new HtmlElement(s.Offset, i, false, s.Color));
                    elements.Add(new HtmlElement(s.Offset + s.Length, i, true, s.Color));
                }
            }
            elements.Sort();

            TextDocument document   = this.Document;
            StringWriter w          = new StringWriter(CultureInfo.InvariantCulture);
            int          textOffset = startOffset;

            foreach (HtmlElement e in elements)
            {
                int newOffset = Math.Min(e.Offset, endOffset);
                if (newOffset > startOffset)
                {
                    HtmlClipboard.EscapeHtml(w, document.GetText(textOffset, newOffset - textOffset), options);
                }
                textOffset = Math.Max(textOffset, newOffset);
                if (options.ColorNeedsSpanForStyling(e.Color))
                {
                    if (e.IsEnd)
                    {
                        w.Write("</span>");
                    }
                    else
                    {
                        w.Write("<span");
                        options.WriteStyleAttributeForColor(w, e.Color);
                        w.Write('>');
                    }
                }
            }
            HtmlClipboard.EscapeHtml(w, document.GetText(textOffset, endOffset - textOffset), options);
            return(w.ToString());
        }