Browse Source

Adjusted unit tests to C# syntax highlighting change.

4.1 4.1-RC
Daniel Grunwald 15 years ago
parent
commit
f24ff58a2b
  1. 5
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Highlighting/HtmlClipboardTests.cs
  2. 14
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs
  3. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HtmlClipboard.cs

5
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Highlighting/HtmlClipboardTests.cs

@ -25,10 +25,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting
{ {
var segment = new TextSegment { StartOffset = 0, Length = document.TextLength }; var segment = new TextSegment { StartOffset = 0, Length = document.TextLength };
string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, new HtmlOptions()); string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, new HtmlOptions());
Assert.AreEqual("<span style=\"color: #008000; font-weight: bold; \">using</span>&nbsp;" + Assert.AreEqual("<span style=\"color: #008000; font-weight: bold; \">using</span>&nbsp;System.Text;<br>" + Environment.NewLine +
"System<span style=\"color: #006400; \">.</span>Text<span style=\"color: #006400; \">;</span><br>" + Environment.NewLine +
"&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #ff0000; \">string</span>&nbsp;" + "&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #ff0000; \">string</span>&nbsp;" +
"text =&nbsp;<span style=\"color: #191970; font-weight: bold; \">SomeMethod</span><span style=\"color: #006400; \">();</span>", html); "text =&nbsp;<span style=\"color: #191970; font-weight: bold; \">SomeMethod</span>();", html);
} }
[Test] [Test]

14
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs

@ -127,12 +127,14 @@ namespace ICSharpCode.AvalonEdit.Highlighting
HtmlClipboard.EscapeHtml(w, document.GetText(textOffset, newOffset - textOffset), options); HtmlClipboard.EscapeHtml(w, document.GetText(textOffset, newOffset - textOffset), options);
} }
textOffset = Math.Max(textOffset, newOffset); textOffset = Math.Max(textOffset, newOffset);
if (e.IsEnd) { if (options.ColorNeedsSpanForStyling(e.Color)) {
w.Write("</span>"); if (e.IsEnd) {
} else { w.Write("</span>");
w.Write("<span"); } else {
options.WriteStyleAttributeForColor(w, e.Color); w.Write("<span");
w.Write('>'); options.WriteStyleAttributeForColor(w, e.Color);
w.Write('>');
}
} }
} }
HtmlClipboard.EscapeHtml(w, document.GetText(textOffset, endOffset - textOffset), options); HtmlClipboard.EscapeHtml(w, document.GetText(textOffset, endOffset - textOffset), options);

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HtmlClipboard.cs

@ -187,5 +187,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting
writer.Write(color.ToCss()); writer.Write(color.ToCss());
writer.Write("\""); writer.Write("\"");
} }
/// <summary>
/// Gets whether the color needs to be written out to HTML.
/// </summary>
public virtual bool ColorNeedsSpanForStyling(HighlightingColor color)
{
if (color == null)
throw new ArgumentNullException("color");
return !string.IsNullOrEmpty(color.ToCss());
}
} }
} }

Loading…
Cancel
Save